private void button6_Click(object sender, EventArgs e) { warmup(); var unsecure = chkUnsecureEcho.Checked; Text = "Working..."; tbNote.Text = "Started..."; var w = Stopwatch.StartNew(); var client = new JokeContractClient(cbo.Text); client.DispatchTimeoutMs = 5 * 1000; client.TimeoutMs = 40 * 1000; if (!unsecure && chkImpersonate.Checked) { client.Headers.Add(new AuthenticationHeader(new IDPasswordCredentials(tbID.Text, tbPwd.Text))); } var totalCalls = tbCallsPerReactor.Text.AsInt(); System.Threading.Tasks.Parallel.For(0, totalCalls, (i) => { client.Async_Notify("aa"); }); var allFinished = w.ElapsedMilliseconds; Text = "Placed {0:n2} One Way calls in {1:n2} ms, @ {2:n2} calls/sec " .Args ( totalCalls, allFinished, totalCalls / (allFinished / 1000d) ); }
private void m_btnCallAsync_Click(object sender, EventArgs e) { try { using (var cl = new JokeContractClient(App.Glue, DEFAULT_TEST_SERVER_ASYNC_NODE)) { cl.Headers.Add(new AuthenticationHeader(DEFAULT_TEST_CREDENTIALS)); var result = cl.Echo("Gello A!"); m_txtLog.AppendText(result); m_txtLog.AppendText(Environment.NewLine); } var glue = App.Glue as Azos.Glue.Implementation.GlueDaemon; var binding = glue.Bindings["async"]; var active = binding.ClientTransports.ToList(); foreach (var ct in active) { ct.Dispose(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button4_Click(object sender, EventArgs ea) { var CNT = edRepeat.Text.AsInt(); var client = new JokeContractClient(cbo.Text); // client.ReserveTransport = true; var w = Stopwatch.StartNew(); int i = 0; try { for (; i < CNT; i++) { client.Notify("Notify!"); } w.Stop(); Text = "Notified " + CNT.ToString() + " in " + w.ElapsedMilliseconds + " ms"; } catch (Exception e) { Text = string.Format("After {0} times: {1}", i, e.ToMessageWithType()); } client.Dispose(); }
public void GlueConfiguredByCodeAndMakeCall_Sync() { //This is an example of how to use Glue without pre-configured app container var app = new TestApplication() { Active = true }; var glue = new NFX.Glue.Implementation.GlueService(app); glue.Start(); try { using (var binding = new SyncBinding(glue, "sync")) { binding.Start(); var cl = new JokeContractClient(glue, TestServerSyncNode); cl.Headers.Add(new AuthenticationHeader(TestCredentials)); var result = cl.Echo("Gello A!"); Assert.IsTrue(result.StartsWith("Server echoed Gello A!")); } } finally { glue.WaitForCompleteStop(); } }
public void Sync_JokeContract_Expected_Security_Exception() { using (var app = JokeHelper.MakeApp()) { var cl = new JokeContractClient(app.Glue, TestServerSyncNode); var result = cl.Echo("Blah");//throws sec exception } }
public void MPX_JokeContract_Expected_Security_Exception() { using (JokeHelper.MakeApp()) { var cl = new JokeContractClient(TestServerMpxNode); var result = cl.Echo("Blah");//throws sec exception } }
private void btnSimple_Click(object sender, EventArgs e) { warmup(); var unsecure = chkUnsecureEcho.Checked; Text = "Working..."; tbNote.Text = "Started..."; var w = Stopwatch.StartNew(); var client = new JokeContractClient(cbo.Text); client.DispatchTimeoutMs = 5 * 1000; client.TimeoutMs = 40 * 1000; if (!unsecure && chkImpersonate.Checked) { client.Headers.Add(new AuthenticationHeader(new IDPasswordCredentials(tbID.Text, tbPwd.Text))); } var totalCalls = tbCallsPerReactor.Text.AsInt(); var totalErrors = 0; System.Threading.Tasks.Parallel.For(0, totalCalls, (i) => { try { if (unsecure) { client.UnsecureEcho("Call number {0} ".Args(i)); } else { client.Echo("Call number {0} ".Args(i)); } } catch (Exception) { Interlocked.Increment(ref totalErrors); } }); var allFinished = w.ElapsedMilliseconds; Text = "Placed {0:n2} calls in {1:n2} ms total time {2:n2} ms @ {3:n2} calls/sec; totalErrors={4:n2} " .Args ( totalCalls, allFinished, allFinished, totalCalls / (allFinished / 1000d), totalErrors ); }
public void Sync_JokeContract_Echo_ByCode() { using (var app = JokeHelper.MakeApp()) { var cl = new JokeContractClient(app.Glue, TestServerSyncNode); cl.Headers.Add(new AuthenticationHeader(TestCredentials)); var result = cl.Echo("Gello A!"); Aver.IsTrue(result.StartsWith("Server echoed Gello A!")); } }
public void MPX_JokeContract_Echo_ByCode() { using (JokeHelper.MakeApp()) { var cl = new JokeContractClient(TestServerMpxNode); cl.Headers.Add(new AuthenticationHeader(TestCredentials)); var result = cl.Echo("Gello A!"); Assert.IsTrue(result.StartsWith("Server echoed Gello A!")); } }
public void Sync_JokeContract_Async_Echo_ByCode() { using (JokeHelper.MakeApp()) { var cl = new JokeContractClient(TestServerSyncNode); cl.Headers.Add(new AuthenticationHeader(TestCredentials)); var call = cl.Async_Echo("Gello B!"); var result = call.GetValue <string>(); Assert.IsTrue(result.StartsWith("Server echoed Gello B!")); } }
public static void EchoThreaded(string node, int count, int parallel) { var tcount = count / parallel; var latch = 0; var threads = new Thread[parallel]; for (var i = 0; i < threads.Length; i++) { threads[i] = new Thread(() => { var client = new JokeContractClient(node); client.ReserveTransport = true; client.UnsecureEcho("aaa"); while (Thread.VolatileRead(ref latch) == 0) { ; //could have used Barrier class } for (var j = 0; j < tcount; j++) { client.UnsecEchoMar("aaa"); } //client.Notify(null); client.Dispose(); }); } foreach (var t in threads) { t.Start(); } Thread.Sleep(2000); var sw = System.Diagnostics.Stopwatch.StartNew(); Thread.VolatileWrite(ref latch, 1); foreach (var t in threads) { t.Join(); } Console.WriteLine("Called Unsecure Echo {0} at {1:n0} ops/sec".Args(count, count / (sw.ElapsedMilliseconds / 1000d))); }
public void GlueConfiguredByCode_MPX() { //This is an example of how to use Glue without pre-configured app container var glue = new NFX.Glue.Implementation.GlueService(); glue.Start(); try { var binding = new MpxBinding(glue, "mpx"); var cl = new JokeContractClient(glue, TestServerMpxNode); } finally { glue.WaitForCompleteStop(); } }
public static void Echo(string node, int count, int parallel) { var client = new JokeContractClient(node); client.UnsecureEcho("aaa"); var sw = System.Diagnostics.Stopwatch.StartNew(); Parallel.For(0, count, new ParallelOptions { MaxDegreeOfParallelism = parallel }, i => { client.UnsecureEcho("aaa"); }); Console.WriteLine("Called Unsecure Echo {0} at {1:n0} ops/sec".Args(count, count / (sw.ElapsedMilliseconds / 1000d))); }
private void btnBadPayload_Click(object sender, EventArgs ea) { var client = new JokeContractClient(cbo.Text); try { var bad = new BadClass(); bad.Click += btnBadMsg_Click; var echoed = client.ObjectWork(bad); Text = echoed.ToString(); } catch (Exception e) { Text = e.ToMessageWithType(); } client.Dispose(); }
private void btnReactor_Click(object sender, EventArgs e) { using (var client1 = new JokeContractClient(cbo.Text)) using (var client2 = new JokeContractClient(cbo.Text)) { var result = ""; var reactor = new CallReactor(false, new Call(client1.Async_Echo("One."), (r, call) => result += call.CallSlot.GetValue <string>()), new Call(client2.Async_Echo("Two."), (r, call) => result += call.CallSlot.GetValue <string>()), new Call(client1.Async_Echo("Three."), (r, call) => result += call.CallSlot.GetValue <string>()) ); reactor.Wait(); MessageBox.Show(result); } }
private void button3_Click(object sender, EventArgs ea) { NOTIFY_COUNT++; var client = new JokeContractClient(cbo.Text); try { client.Notify("Notify!"); Text = "Notified " + NOTIFY_COUNT.ToString() + " times"; } catch (Exception e) { Text = e.ToMessageWithType(); } client.Dispose(); }
public void GlueConfiguredByCode() { //This is an example of how to use Glue without pre-configured app container using (var app = new TestApplication()) { var glue = new Azos.Glue.Implementation.GlueDaemon(app); glue.Start(); try { var binding = new SyncBinding(glue, "sync"); var cl = new JokeContractClient(glue, TestServerSyncNode); } finally { glue.WaitForCompleteStop(); } } }
private void btnReactor2_Click(object sender, EventArgs e) { var client1 = new JokeContractClient(cbo.Text); var client2 = new JokeContractClient(cbo.Text); new CallReactor(false, finishedReactor => { client1.Dispose(); client2.Dispose(); Invoke((Action)(() => MessageBox.Show(finishedReactor.Context.ToString()))); }, string.Empty, new Call(client1.Async_Echo("One."), (reactor, call) => reactor.Context = ((string)reactor.Context) + call.CallSlot.GetValue <string>()), new Call(client2.Async_Echo("Two."), (reactor, call) => reactor.Context = ((string)reactor.Context) + call.CallSlot.GetValue <string>()), new Call(client1.Async_Echo("Three."), (reactor, call) => reactor.Context = ((string)reactor.Context) + call.CallSlot.GetValue <string>()) ); }
private void m_btnRun_Click(object sender, EventArgs e) { try { //using (JokeHelper.MakeApp()) { var cl = new JokeContractClient(App.Glue, DEFAULT_TEST_SERVER_SYNC_NODE); cl.Headers.Add(new AuthenticationHeader(DEFAULT_TEST_CREDENTIALS)); var result = cl.Echo("Gello A!"); m_txtLog.AppendText(result); m_txtLog.AppendText(Environment.NewLine); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button1_Click(object sender, EventArgs ea) { ECHO_COUNT++; var client = new JokeContractClient(cbo.Text); client.Headers.Add(new AuthenticationHeader(new IDPasswordCredentials(tbID.Text, tbPwd.Text))); try { var echoed = chkUnsecureEcho.Checked ? client.UnsecureEcho("Hello!") : client.Echo("Hello!"); Text = echoed + " " + ECHO_COUNT.ToString() + " times"; } catch (Exception e) { Text = e.ToMessageWithType(); } client.Dispose(); }
private string LongRunningMethod(string message) { int errQty = 0; for (int i = 0; i < 10000000; i++) { try { using (var cl = new JokeContractClient(App.Glue, DEFAULT_TEST_SERVER_ASYNC_NODE)) { cl.Headers.Add(new AuthenticationHeader(DEFAULT_TEST_CREDENTIALS)); var result = cl.Echo("Gello A!"); //LogLine(result); if (i % 10 == 0) { LogTotal(i, errQty); } } // close all transports var glue = App.Glue as Azos.Glue.Implementation.GlueDaemon; var binding = glue.Bindings["async"]; var active = binding.ClientTransports.ToList(); foreach (var ct in active) { ct.Dispose(); } } catch (Exception ex) { errQty++; LogLine(ex.Message); //MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } return(message); }
private void button2_Click(object sender, EventArgs ea) { var CNT = edRepeat.Text.AsInt(); var client = new JokeContractClient(cbo.Text); client.Headers.Add(new AuthenticationHeader(new IDPasswordCredentials(tbID.Text, tbPwd.Text))); // client.ReserveTransport = true; var w = Stopwatch.StartNew(); try { if (chkUnsecureEcho.Checked) { for (int i = 0; i < CNT; i++) { client.UnsecureEcho("Hello!"); } } else { for (int i = 0; i < CNT; i++) { client.Echo("Hello!"); } } w.Stop(); Text = "Echoed " + CNT.ToString() + " in " + w.ElapsedMilliseconds + " ms"; } catch (Exception e) { Text = e.ToMessageWithType(); } client.Dispose(); }
private void btnManyDBWorks_Click(object sender, EventArgs e) { warmup(); var rCount = tbRecCount.Text.AsInt(); var waitFrom = tbWaitFrom.Text.AsInt(); var waitTo = tbWaitTo.Text.AsInt(); Text = "Working..."; tbNote.Text = "Started..."; var w = Stopwatch.StartNew(); var client = new JokeContractClient(cbo.Text); client.DispatchTimeoutMs = 5 * 1000; client.TimeoutMs = 40 * 1000; var totalCalls = tbCallsPerReactor.Text.AsInt(); var calls = new ConcurrentQueue <Call>(); var derrors = new ConcurrentQueue <string>(); System.Threading.Tasks.Parallel.For(0, totalCalls, (i) => { try { calls.Enqueue(new Call(client.Async_DBWork(i.ToString(), rCount, waitFrom > 0 ? ExternalRandomGenerator.Instance.NextScaledRandomInteger(waitFrom, waitTo) : 0))); //ExternalRandomGenerator.Instance.NextScaledRandomInteger(1,100), //ExternalRandomGenerator.Instance.NextScaledRandomInteger(0,50))) ); } catch (Exception err) { derrors.Enqueue("{0}: {1}\r\n".Args(1, err.ToMessageWithType())); } }); string estr = null; while (derrors.TryDequeue(out estr)) { tbNote.Text += estr; } var reactor = new CallReactor(calls); var callsPlaced = w.ElapsedMilliseconds; reactor.Wait(); var stats = new ConcurrentDictionary <CallStatus, int>(); foreach (var call in reactor.Calls) { if (call.CallSlot.CallStatus == CallStatus.ResponseError) { var msg = call.CallSlot.ResponseMsg; Text = msg.ExceptionData.Message; } stats.AddOrUpdate(call.CallSlot.CallStatus, 1, (_, k) => k + 1); } var sb = new StringBuilder(); foreach (var k in stats.Keys) { sb.AppendLine("{0} = {1} times".Args(k, stats[k])); } tbNote.Text += sb.ToString(); var allFinished = w.ElapsedMilliseconds; Text = "Placed {0} DB calls in {1} ms, then waited {2} ms for finish, total time {3} ms @ {4} calls/sec " .Args ( totalCalls, callsPlaced, allFinished - callsPlaced, allFinished, (1000 * totalCalls) / allFinished ); if (chkAutoDispatch.Checked) { tmrAuto.Interval = 1000 + ExternalRandomGenerator.Instance.NextScaledRandomInteger(100, 10000); tmrAuto.Enabled = true; } }
[ExpectedException(typeof(ClientCallException))]//because there is no binding registered public void ExpectedExceptionWhenGlueNotConfiguredAndBindingNotRegistered() { var cl = new JokeContractClient(TestServerSyncNode); }
[Aver.Throws(typeof(ClientCallException))]//because there is no binding registered public void ExpectedExceptionWhenGlueNotConfiguredAndBindingNotRegistered() { var app = new TestApplication(); var cl = new JokeContractClient(app.Glue, TestServerSyncNode); }
private void btnManyParallel_Click(object sender, EventArgs e) { Text = "Working..."; var w = Stopwatch.StartNew(); var client = new JokeContractClient(cbo.Text); if (chkImpersonate.Checked) { client.Headers.Add(new AuthenticationHeader(new IDPasswordCredentials(tbID.Text, tbPwd.Text))); } var totalCalls = 0; var reactors = new List <CallReactor>(); for (int rCnt = 0, n = tbReactors.Text.AsInt(); rCnt < n; rCnt++) { var calls = new List <Call>(); for (int cnt = 0, m = tbCallsPerReactor.Text.AsInt(); cnt < m; cnt++) { try { calls.Add(new Call(client.Async_Echo("Call number {0} from {1} reactor ".Args(cnt, rCnt)))); } catch (Exception err) { tbNote.Text += "{0:000}:{1:00000}: {2}".Args(rCnt, cnt, err.Message); } } totalCalls += calls.Count; reactors.Add(new CallReactor(calls)); } var callsPlaced = w.ElapsedMilliseconds; CallReactor.WaitAll(reactors); var stats = new ConcurrentDictionary <CallStatus, int>(); foreach (var rtor in reactors) { foreach (var call in rtor.Calls) { if (call.CallSlot.CallStatus == CallStatus.ResponseError) { var msg = call.CallSlot.ResponseMsg; Text = msg.ExceptionData.Message; } stats.AddOrUpdate(call.CallSlot.CallStatus, 1, (_, k) => k + 1); } } var sb = new StringBuilder(); foreach (var k in stats.Keys) { sb.AppendLine("{0} = {1} times".Args(k, stats[k])); } tbNote.Text = sb.ToString(); var allFinished = w.ElapsedMilliseconds; Text = "Placed {0} calls in {1} ms, then waited {2} ms for finish, total time {3} ms @ {4} calls/sec " .Args ( totalCalls, callsPlaced, allFinished - callsPlaced, allFinished, (1000 * totalCalls) / allFinished ); }
private void btnSimpleWork_Click(object sender, EventArgs e) { warmup(); var marshal = chkArgsMarshalling.Checked; Text = "Working..."; tbNote.Text = "Started..."; var w = Stopwatch.StartNew(); var node = cbo.Text; //var totalCalls = tbCallsPerReactor.Text.AsInt(); var rcount = tbReactors.Text.AsInt(10); var prc = tbCallsPerReactor.Text.AsInt();//totalCalls / rcount; var auth = new AuthenticationHeader(new IDPasswordCredentials(tbID.Text, tbPwd.Text)); var totalCalls = rcount * prc; var calls = new ConcurrentQueue <Call>(); var derrors = new ConcurrentQueue <string>(); var tasks = new List <Task>(); for (var i = 0; i < rcount; i++) { tasks.Add(Task.Factory.StartNew((idx) => { var lcl = new JokeContractClient(node); lcl.DispatchTimeoutMs = 5 * 1000; lcl.TimeoutMs = 40 * 1000; lcl.ReserveTransport = true; for (var j = 0; j < prc; j++) { try { calls.Enqueue(new Call(marshal ? lcl.Async_SimpleWorkMar("Call number {0} ".Args(j), j, i, true, 123.12) : lcl.Async_SimpleWorkAny("Call number {0} ".Args(j), j, i, true, 123.12))); } catch (Exception err) { derrors.Enqueue("{0}: {1}\r\n".Args(j, err.ToMessageWithType())); } } //for lcl.Dispose(); }, i, TaskCreationOptions.LongRunning)); } Task.WaitAll(tasks.ToArray()); string estr = null; while (derrors.TryDequeue(out estr)) { tbNote.Text += estr; } var reactor = new CallReactor(calls); var callsPlaced = w.ElapsedMilliseconds; reactor.Wait(); var stats = new ConcurrentDictionary <CallStatus, int>(); foreach (var call in reactor.Calls) { if (call.CallSlot.CallStatus == CallStatus.ResponseError) { var msg = call.CallSlot.ResponseMsg; Text = msg.ExceptionData.Message; } stats.AddOrUpdate(call.CallSlot.CallStatus, 1, (_, k) => k + 1); } var sb = new StringBuilder(); foreach (var k in stats.Keys) { sb.AppendLine("{0} = {1} times".Args(k, stats[k])); } tbNote.Text += sb.ToString(); var allFinished = w.ElapsedMilliseconds; Text = "Placed {0:n2} calls in {1:n2} ms, then waited {2:n2} ms for finish, total time {3:n2} ms @ {4:n2} calls/sec " .Args ( totalCalls, callsPlaced, allFinished - callsPlaced, allFinished, totalCalls / (allFinished / 1000d) ); }
private void btnParallelDispatch_Click(object sender, EventArgs e) { warmup(); var unsecure = chkUnsecureEcho.Checked; var argsMarshal = chkArgsMarshalling.Checked; Text = "Working..."; tbNote.Text = "Started..."; var w = Stopwatch.StartNew(); var client = new JokeContractClient(cbo.Text); client.DispatchTimeoutMs = 5 * 1000; client.TimeoutMs = 40 * 1000; if (!unsecure && chkImpersonate.Checked) { client.Headers.Add(new AuthenticationHeader(new IDPasswordCredentials(tbID.Text, tbPwd.Text))); } var totalCalls = tbCallsPerReactor.Text.AsInt(); var calls = new ConcurrentQueue <Call>(); var derrors = new ConcurrentQueue <string>(); System.Threading.Tasks.Parallel.For(0, totalCalls, (i) => { try { calls.Enqueue(new Call( argsMarshal ? client.Async_UnsecEchoMar("Call number {0} ".Args(i)) : (unsecure ? client.Async_UnsecureEcho("Call number {0} ".Args(i)) : client.Async_Echo("Call number {0} ".Args(i))))); } catch (Exception err) { derrors.Enqueue("{0}: {1}\r\n".Args(1, err.ToMessageWithType())); } }); string estr = null; while (derrors.TryDequeue(out estr)) { tbNote.Text += estr; } var reactor = new CallReactor(calls); var callsPlaced = w.ElapsedMilliseconds; reactor.Wait(); var stats = new ConcurrentDictionary <CallStatus, int>(); foreach (var call in reactor.Calls) { if (call.CallSlot.CallStatus == CallStatus.ResponseError) { var msg = call.CallSlot.ResponseMsg; Text = msg.ExceptionData.Message; } stats.AddOrUpdate(call.CallSlot.CallStatus, 1, (_, k) => k + 1); } var sb = new StringBuilder(); foreach (var k in stats.Keys) { sb.AppendLine("{0} = {1} times".Args(k, stats[k])); } tbNote.Text += sb.ToString(); var allFinished = w.ElapsedMilliseconds; Text = "Placed {0:n2} calls in {1:n2} ms, then waited {2:n2} ms for finish, total time {3:n2} ms @ {4:n2} calls/sec " .Args ( totalCalls, callsPlaced, allFinished - callsPlaced, allFinished, totalCalls / (allFinished / 1000d) ); }