public async void TestSendAndReceiveWithPoller() { var resolver = new DependencyResolver(); using (var broker = new ZmqPollBroker(this.zmqContext, ClientInboundAddress, ServerInboundAddress)) { broker.Listen(); using (var server = new ZmqPollServer(this.zmqContext, ServerInboundAddress, new ServiceFactory(resolver))) { server.Listen(); using (var client = new ZmqPollClient(this.zmqContext, ClientInboundAddress)) { var clientFactory = new ServiceClientFactory(client); var serviceClient = clientFactory.CreateServiceClient<ITestService2>(); Assert.That(serviceClient.GetPerson(1), Is.Not.Null); var persons = await serviceClient.ListPersonsAsync(5); Assert.That(persons, Is.Not.Null); Assert.AreEqual(5, persons.Count()); var nullCollection = await serviceClient.ListPersonsAsync(-1); Assert.IsNull(nullCollection); var nullObject = serviceClient.GetPerson(-1); Assert.IsNull(nullObject); } } } }
public async void TestSendAndReceive() { var resolver = new DependencyResolver(); using (var server = new RedisServer(new RedisConnection(RedisHost, RedisPort, RedisPassword), ServerQueue, new ServiceFactory(resolver))) { server.Listen(); using (var client = new RedisClient(new RedisConnection(RedisHost, RedisPort, RedisPassword), ClientQueue, ServerQueue)) { var clientFactory = new ServiceProxy.ServiceClientFactory(client); var serviceClient = clientFactory.CreateServiceClient<ITestService2>(); Assert.That(serviceClient.GetPerson(1), Is.Not.Null); var persons = await serviceClient.ListPersonsAsync(5); Assert.That(persons, Is.Not.Null); Assert.AreEqual(5, persons.Count()); var nullCollection = await serviceClient.ListPersonsAsync(-1); Assert.IsNull(nullCollection); var nullObject = serviceClient.GetPerson(-1); Assert.IsNull(nullObject); } } }
public async void TestSendAndReceiveExceptions() { var resolver = new DependencyResolver(); using (var broker = new ZmqBroker(this.zmqContext, ClientInboundAddress, ClientOutboundAddress, ServerInboundAddress, ServerOutboundAddress)) { broker.Listen(); using (var server = new ZmqServer(this.zmqContext, ServerInboundAddress, ServerOutboundAddress, new ServiceFactory(resolver))) { server.Listen(); using (var client = new ZmqClient(this.zmqContext, ClientInboundAddress, ClientOutboundAddress)) { var clientFactory = new ServiceClientFactory(client); var serviceClient = clientFactory.CreateServiceClient<ITestService>(); //Synchronous var err = Assert.Catch(async () => await serviceClient.FailAsync()); Assert.IsNotNull(err); Assert.IsNotInstanceOf<AggregateException>(err); //Asynchronous task based err = Assert.Catch(() => serviceClient.Fail()); Assert.IsNotNull(err); Assert.IsNotInstanceOf<AggregateException>(err); //Asynchronous IAsyncResult based , awaiting with Task err = Assert.Catch(async () => await Task.Factory.FromAsync(serviceClient.BeginFail, serviceClient.EndFail, null)); Assert.IsNotNull(err); Assert.IsNotInstanceOf<AggregateException>(err); //Timeout exceptions var factoryWithTimeout = new ServiceClientFactory(client); var serviceClientWithTimeout = factoryWithTimeout.CreateServiceClient<ITestService>(50); //50ms Assert.Throws<TimeoutException>(async () => await serviceClientWithTimeout.ReplyAfter(1000)); } } } }
public async void TestSendAndReceiveExceptions() { var resolver = new DependencyResolver(); using (var server = new RedisServer(new RedisConnection(RedisHost, RedisPort, RedisPassword), ServerQueue, new ServiceFactory(resolver))) { server.Listen(); using (var client = new RedisClient(new RedisConnection(RedisHost, RedisPort, RedisPassword), ClientQueue, ServerQueue)) { var clientFactory = new ServiceClientFactory(client); var serviceClient = clientFactory.CreateServiceClient<ITestService>(); //Synchronous var err = Assert.Catch(async () => await serviceClient.FailAsync()); Assert.IsNotNull(err); Assert.IsNotInstanceOf<AggregateException>(err); //Asynchronous task based err = Assert.Catch(() => serviceClient.Fail()); Assert.IsNotNull(err); Assert.IsNotInstanceOf<AggregateException>(err); //Asynchronous IAsyncResult based , awaiting with Task err = Assert.Catch(async () => await Task.Factory.FromAsync(serviceClient.BeginFail, serviceClient.EndFail, null)); Assert.IsNotNull(err); Assert.IsNotInstanceOf<AggregateException>(err); //Timeout exceptions var factoryWithTimeout = new ServiceClientFactory(client); var serviceClientWithTimeout = factoryWithTimeout.CreateServiceClient<ITestService>(50); //50ms Assert.Throws<TimeoutException>(async () => await serviceClientWithTimeout.ReplyAfter(1000)); } } }
//[TestCase(5, 1000000)] public async void TestLoadBalancingWithPoll(int nServers, int nMsgs) { var resolver = new DependencyResolver(); using (var broker = new ZmqPollBroker(this.zmqContext, ClientInboundAddress, ServerInboundAddress)) { broker.Listen(); var servers = Enumerable.Range(0, nServers) .Select(i => new ZmqPollServer(this.zmqContext, ServerInboundAddress, new ServiceFactory(resolver))) .ToArray(); try { foreach (var server in servers) server.Listen(); using (var client = new ZmqPollClient(this.zmqContext, ClientInboundAddress)) { var clientFactory = new ServiceClientFactory(client); var serviceClient = clientFactory.CreateServiceClient<ITestService2>(); var tasks = Enumerable.Range(0, nMsgs) //.Select(i => serviceClient.SumAsync(5, 15)) .Select(i => serviceClient.ListPersonsAsync(7)) .ToArray(); await Task.WhenAll(tasks); Assert.True(tasks.All(t => t.Result.Count() == 7)); } } finally { foreach (var server in servers) server.Dispose(); } } }
//[TestCase(5, 1000000)] public async void TestLoadBalancing(int nServers, int nMsgs) { var resolver = new DependencyResolver(); var servers = Enumerable.Range(0, nServers) .Select(i => new RedisServer(new RedisConnection(RedisHost, RedisPort, RedisPassword), ServerQueue, new ServiceFactory(resolver))) .ToArray(); try { foreach (var server in servers) server.Listen(); using (var client = new RedisClient(new RedisConnection(RedisHost, RedisPort, RedisPassword), ClientQueue, ServerQueue)) { var clientFactory = new ServiceClientFactory(client); var serviceClient = clientFactory.CreateServiceClient<ITestService2>(); var tasks = Enumerable.Range(0, nMsgs) //.Select(i => serviceClient.SumAsync(5, 15)) .Select(i => serviceClient.ListPersonsAsync(7)) .ToArray(); await Task.WhenAll(tasks); Assert.True(tasks.All(t => t.Result.Count() == 7)); } } finally { foreach (var server in servers) server.Dispose(); } }