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,
            Address.From(Host.Of("localhost"), NextPort.Get(), AddressType.None), unknown);

        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(RequestHeader.WithKeepAlive())
                .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 TestThatSecureClientReceivesResponse()
    {
        var responseConsumer = new TestResponseConsumer(_output);
        var access           = responseConsumer.AfterCompleting(1);
        var unknown          = new UnknownResponseConsumer(access, _output);

        var config =
            Client.Configuration.Secure(
                _world.Stage,
                Address.From(Host.Of("google.com"), 443, AddressType.None),
                unknown,
                false,
                10,
                65535,
                10,
                65535);

        config.TestInfo(true);

        var client =
            Client.Using(
                config,
                Client.ClientConsumerType.RoundRobin,
                5);

        var request =
            Request
            .Has(Method.Get)
            .And(new Uri("/search?q=vlingo", UriKind.Relative))
            .And(RequestHeader.WithHost("google.com"))
            .And(RequestHeader.WithConnection("close"))
            .And(RequestHeader.WithContentType("text/html"));

        var response = client.RequestWith(request);

        response.AndThenConsume(res => {
            _responseContent = res.Entity.Content;
            access.WriteUsing("response", res);
        });


        Assert.Equal(1, access.ReadFrom <int>("responseCount"));

        var accessResponse = access.ReadFrom <Response>("response");

        Assert.Equal(_responseContent, accessResponse.Entity.Content);
    }
Beispiel #3
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.DefaultedExceptFor(
            World.Stage,
            Address.From(Host.Of("localhost"), NextPort.Get(), AddressType.None), unknown);

        _client = Client.Using(config);

        _client.RequestWith(
            Request
            .Has(Method.Post)
            .And("/users".ToMatchableUri())
            .And(RequestHeader.WithHost("localhost"))
            .And(RequestHeader.WithContentLength(user))
            .And(RequestHeader.WithKeepAlive())
            .And(Body.From(user)))
        .AndThenConsume(TimeSpan.FromMilliseconds(5000), Response.Of(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(ResponseStatus.Created, _expectedResponse.Status);
        Assert.Equal(3, _expectedHeaderCount);
        Assert.NotNull(_location);
        Assert.Equal(0, unknownResponseCount);
    }
Beispiel #4
0
    public void TestBasicFailure()
    {
        var consumer = new TestResponseConsumer(_output);
        var access   = consumer.AfterCompleting(1);
        var unknown  = new UnknownResponseConsumer(access, _output);

        var config =
            Client.Configuration.DefaultedExceptFor(_world.Stage, Address.From(Host.Of("localhost"), _port, AddressType.None), unknown);

        _client = Client.Using(config, Client.ClientConsumerType.RoundRobin, 1);

        var request = Request.From(ToConsumerByteBuffer("GET /fail HTTP/1.1\nHost: vlingo.io\n\n"));

        _count = 0;

        _client.RequestWith(request).AndThenConsume(response => {
            ++_count;
            _response = response;
        }).Await();

        Assert.Equal(1, _count);

        Assert.NotNull(_response);
    }