public void One_Responder_1_Requester() { var echoWorker = new ResponderWorker(); var workerFactory = new ResponderWorkerFactory(request => echoWorker); using (var responder = new Responder(workerFactory)) using (var requester = new Requester()) { var endpoint = GetEndpoint(); responder.Bind(endpoint); requester.Connect(endpoint); Thread.Sleep(100); var sw = Stopwatch.StartNew(); var messageSent = new TestMessage(); for (var i = 0; i < NumberOfRequests; i++) { requester.Request(messageSent); } sw.Stop(); Assert.Inconclusive("{0} elapsed sending/receiving {1} messages ({2:N0} per second)", sw.Elapsed, NumberOfRequests, NumberOfRequests / sw.Elapsed.TotalSeconds); } }
public void GetResponse_typed_constructor_passed_TestMessage_IMessage_function_is_called() { Func<TestMessage, IMessage> func = m => new TestMessage("response"); var responderWorker = new ResponderWorker<TestMessage>(func); var response = (TestMessage)responderWorker.GetResponse(new TestMessage(), null); Assert.AreEqual("response", response.Text); }
public void GetResponse_typed_constructor_passed_nothing_Echo_function_is_called() { var responderWorker = new ResponderWorker<TestMessage>(); var requestMessage = new TestMessage(); var response = (TestMessage)responderWorker.GetResponse(requestMessage, null); Assert.AreEqual(requestMessage, response); }
public void GetWorkerFor_constructor_passed_function_is_called() { var responderWorker = new ResponderWorker(); Func<IMessage, IResponderWorker> func = m => responderWorker; var factory = new ResponderWorkerFactory(func); Assert.AreSame(responderWorker, factory.GetWorkerFor(new TestMessage())); }
public void GetResponse_typed_constructor_passed_TestMessage_IMessage_function_is_called() { Func <TestMessage, IMessage> func = m => new TestMessage("response"); var responderWorker = new ResponderWorker <TestMessage>(func); var response = (TestMessage)responderWorker.GetResponse(new TestMessage(), null); Assert.AreEqual("response", response.Text); }
public void GetResponse_typed_constructor_passed_nothing_Echo_function_is_called() { var responderWorker = new ResponderWorker <TestMessage>(); var requestMessage = new TestMessage(); var response = (TestMessage)responderWorker.GetResponse(requestMessage, null); Assert.AreEqual(requestMessage, response); }
public void GetWorkerFor_constructor_passed_function_is_called() { var responderWorker = new ResponderWorker(); Func <IMessage, IResponderWorker> func = m => responderWorker; var factory = new ResponderWorkerFactory(func); Assert.AreSame(responderWorker, factory.GetWorkerFor(new TestMessage())); }
private void One_Responder_N_Requesters(int n) { var echoWorker = new ResponderWorker(); var workerFactory = new ResponderWorkerFactory(request => echoWorker); using (var responder = new Responder(workerFactory)) { var endpoint = GetEndpoint(); responder.Bind(endpoint); var requesters = Enumerable.Range(0, n).Select(x => new Requester()).ToList(); foreach (var requester in requesters) { requester.Connect(endpoint); } Thread.Sleep(100); var threadsStartedSignal = new CounterSignal(n, 0); var startSignal = new ManualResetEventSlim(); var tasks = new List <Task>(); foreach (var requester in requesters) { var req = requester; var task = Task.Factory.StartNew(() => { threadsStartedSignal.Increment(); startSignal.Wait(); var message = new TestMessage(); for (var i = 0; i < NumberOfRequests / n; i++) { req.Request(message); } }, TaskCreationOptions.LongRunning); tasks.Add(task); } Assert.IsTrue(threadsStartedSignal.Wait(TimeSpan.FromSeconds(1))); var sw = Stopwatch.StartNew(); startSignal.Set(); Assert.IsTrue(Task.WhenAll(tasks).Wait(TimeSpan.FromMinutes(1))); sw.Stop(); foreach (var requester in requesters) { requester.Disconnect(); } Assert.Inconclusive("{0} elapsed sending/receiving {1} messages ({2:N0} per second)", sw.Elapsed, NumberOfRequests, NumberOfRequests / sw.Elapsed.TotalSeconds); } }
private void One_Responder_N_Requesters(int n) { var echoWorker = new ResponderWorker(); var workerFactory = new ResponderWorkerFactory(request => echoWorker); using (var responder = new Responder(workerFactory)) { var endpoint = GetEndpoint(); responder.Bind(endpoint); var requesters = Enumerable.Range(0, n).Select(x => new Requester()).ToList(); foreach (var requester in requesters) { requester.Connect(endpoint); } Thread.Sleep(100); var threadsStartedSignal = new CounterSignal(n, 0); var startSignal = new ManualResetEventSlim(); var tasks = new List<Task>(); foreach (var requester in requesters) { var req = requester; var task = Task.Factory.StartNew(() => { threadsStartedSignal.Increment(); startSignal.Wait(); var message = new TestMessage(); for (var i = 0; i < NumberOfRequests / n; i++) { req.Request(message); } }, TaskCreationOptions.LongRunning); tasks.Add(task); } Assert.IsTrue(threadsStartedSignal.Wait(TimeSpan.FromSeconds(1))); var sw = Stopwatch.StartNew(); startSignal.Set(); Assert.IsTrue(Task.WhenAll(tasks).Wait(TimeSpan.FromMinutes(1))); sw.Stop(); foreach (var requester in requesters) { requester.Disconnect(); } Assert.Inconclusive("{0} elapsed sending/receiving {1} messages ({2:N0} per second)", sw.Elapsed, NumberOfRequests, NumberOfRequests / sw.Elapsed.TotalSeconds); } }