コード例 #1
0
        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);
                    }
                }
            }
        }
コード例 #2
0
        //[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();
                    }
                }
            }
        }