Beispiel #1
0
        public void TestThatLoadBalancingClientDelivers()
        {
            var safely  = new TestResponseConsumer(_output);
            var access  = safely.AfterCompleting(100);
            var unknown = new UnknownResponseConsumer(access, _output);
            var known   = new KnownResponseConsumer(access);

            //var config = Client.Configuration.DefaultedExceptFor(World.Stage, unknown);
            var config = Client.Configuration.Has(World.Stage, Address.From(Host.Of("localhost"), NextPort.Get(), AddressType.None), unknown,
                                                  false,
                                                  30,
                                                  10240,
                                                  10,
                                                  10240);

            config.TestInfo(true);
            config.TestInfo(true);

            _client =
                Client.Using(
                    config,
                    Client.ClientConsumerType.LoadBalancing,
                    5);

            for (var count = 0; count < 100; ++count)
            {
                var user = count % 2 == 0 ? UniqueJohnDoe() : UniqueJaneDoe();
                _client.RequestWith(
                    Request
                    .Has(Method.Post)
                    .And("/users".ToMatchableUri())
                    .And(RequestHeader.WithHost("localhost"))
                    .And(RequestHeader.WithContentLength(user))
                    .And(Body.From(user)))
                .AndThenConsume(response => known.Consume(response));
            }

            var responseCount        = access.ReadFromExpecting("responseCount", 100, 10000);
            var total                = access.ReadFrom <int>("totalAllResponseCount");
            var unknownResponseCount = access.ReadFrom <int>("unknownResponseCount");
            var clientCounts         = access.ReadFrom <Dictionary <string, int> >("responseClientCounts");

            Assert.Equal(100, total);
            Assert.Equal(100, responseCount);
            Assert.Equal(0, unknownResponseCount);

            var totalClientCounts = 0;

            foreach (var id in clientCounts.Keys)
            {
                var clientCount = clientCounts[id];
                totalClientCounts += clientCount;
            }

            Assert.Equal(100, totalClientCounts);
        }
Beispiel #2
0
        public void TestThatCorrelatingClientDelivers()
        {
            var user = JohnDoeUserSerialized;

            var safely  = new TestResponseConsumer(_output);
            var access  = safely.AfterCompleting(1);
            var unknown = new UnknownResponseConsumer(access, _output);
            var known   = new KnownResponseConsumer(access);

            var config = Client.Configuration.Has(World.Stage, Address.From(Host.Of("localhost"), NextPort.Get(), AddressType.None), unknown,
                                                  false,
                                                  10,
                                                  10240,
                                                  10,
                                                  10240);

            _client = Client.Using(config);

            _client.RequestWith(
                Request
                .Has(Method.Post)
                .And("/users".ToMatchableUri())
                .And(RequestHeader.WithHost("localhost"))
                .And(RequestHeader.WithContentLength(user))
                .And(Body.From(user)))
            .AndThenConsume(TimeSpan.FromMilliseconds(5000), Response.Of(Response.ResponseStatus.RequestTimeout), response => _expectedResponse = response)
            .AndThenConsume(response => _expectedHeaderCount = response.Headers.Count)
            .AndThenConsume(response => _location            = response.Headers.HeaderOf(ResponseHeader.Location))
            .AndThenConsume(known.Consume);

            var responseCount        = access.ReadFrom <int>("responseCount");
            var unknownResponseCount = access.ReadFrom <int>("unknownResponseCount");

            Assert.Equal(1, responseCount);
            Assert.NotNull(_expectedResponse);
            Assert.Equal(Response.ResponseStatus.Created, _expectedResponse.Status);
            Assert.Equal(3, _expectedHeaderCount);
            Assert.NotNull(_location);
            Assert.Equal(0, unknownResponseCount);
        }