public void RabbitMQBinding_NonTransactionalDuplexWithPredefinedCallbackQueueDelivery() { IDuplexService channel = _channelFactory.CreateChannel(); Data data = new Data { Id = 1, Name = "Rabbit" }; A.CallTo(_errorProcessorFake).DoesNothing(); A.CallTo(() => _callbackFake.Say(A <Data> .Ignored)).Invokes(() => _ev.Set()); channel.Say(data); bool wait = _ev.Wait(TimeSpan.FromSeconds(10)); Assert.IsTrue(wait, "Callback were not being invoked"); A.CallTo(() => _processorFake.Say(A <Data> ._)).WhenArgumentsMatch(collection => { data.ShouldBeEquivalentTo(collection[0]); return(true); }).MustHaveHappened(Repeated.Like(i => i == 1)); A.CallTo(() => _callbackFake.Say(A <Data> ._)).WhenArgumentsMatch(collection => { _replyData.ShouldBeEquivalentTo(collection[0]); return(true); }).MustHaveHappened(Repeated.Like(i => i == 1)); }
public void Say(Data data) { _process.Say(data); IDuplexService callbackChannel = OperationContext.Current.GetCallbackChannel <IDuplexService>(); callbackChannel.Say(_replyData); }
public override int UseChannelImpl(IDuplexService channel) { int callbacks = _params.CallbacksToExpect; int result = channel.GetAsyncCallbackData(1, callbacks); // we can't guarantee the correctness of the result in case of relaxed exception policy if (!RelaxedExceptionPolicy) { int expected = (1 + callbacks) * callbacks / 2; if (result != expected) { TestUtils.ReportFailure("Unexpected result. Expected: " + expected + " result: " + result); } } return(callbacks + 1); }
public override async Task <int> UseAsyncChannelImpl(IDuplexService channel) { int callbacks = _params.CallbacksToExpect; int result = await channel.GetAsyncCallbackDataAsync(1, callbacks); // we can't guarantee the correctness of the result in case of relaxed exception policy if (!RelaxedExceptionPolicy) { int expected = (1 + callbacks) * callbacks / 2; if (result != expected) { TestUtils.ReportFailure("Unexpected result. Expected: " + expected + "result: " + result); } } // count our call to GetAsyncCallbackDataAsync and each callback call as a separate request return(callbacks + 1); }
static void Main(string[] args) { Console.WriteLine("Client Started"); // Test DuplexChannelFactory using netHttpBinding DuplexChannelFactory <IDuplexService> webSocketFactory = new DuplexChannelFactory <IDuplexService>( new InstanceContext(new Callback()), new NetHttpBinding { Name = "netHttpBindingDuplexService", MessageEncoding = NetHttpMessageEncoding.Text }, new EndpointAddress("ws://localhost:3123/DuplexService") ); IDuplexService webSocketDuplexChannel = webSocketFactory.CreateChannel(); webSocketDuplexChannel.HelloWorld(CreateMessage("Web Socket Duplex is running!")); // Stop Client from exiting Console.ReadLine(); }
private ActionResult Perftest(IDuplexService svc) { var sw = new Stopwatch(); sw.Start(); var content = RunPerftest(svc); sw.Stop(); content += "\r\n\r\n" + sw.ElapsedMilliseconds + "ms TOTAL"; return Content(content, "text/plain"); }
private static string RunPerftest(IDuplexService svc) { var sw = new Stopwatch(); sw.Start(); var results = new List<double>(); var errors = new List<Exception>(); for (int j = 0; j < _iterations; j++) { var isw = new Stopwatch(); isw.Start(); for (int l = 0; l < _batches; l++) { var tasks = new List<Task>(); for (int i = 0; i < _numberThreads; i++) { tasks.Add(Task.Factory.StartNew(() => { try { svc.GetDate(new GetDateRequest { RequestTime = DateTime.Now }); } catch (Exception ex) { lock(errors) { errors.Add(ex); } } })); } Task.WaitAll(tasks.ToArray()); } isw.Stop(); results.Add(isw.ElapsedMilliseconds); } sw.Stop(); var content = svc.GetType().FullName + "\r\n" + string.Join("\r\n", results) + "\r\n\r\nTotal:\t\t" + sw.ElapsedMilliseconds + "\r\n\r\nAverage:\t" + results.Average() + "\r\n\r\nErrors:\t" + errors.Count() + "\r\n\r\n"; return content; }
public DuplexService(IDuplexService process, Data replyData) { _process = process; _replyData = replyData; }