Esempio n. 1
0
        public void TestBasicRequestResponse()
        {
            var request = "Hello, Request-Response";

            _serverConsumer.CurrentExpectedRequestLength  = request.Length;
            _clientConsumer.CurrentExpectedResponseLength = _serverConsumer.CurrentExpectedRequestLength;

            var serverConsumeCount = 0;
            var clientConsumeCount = 0;
            var accessSafely       = AccessSafely.AfterCompleting(1)
                                     .WritingWith <int>("serverConsume", (value) => serverConsumeCount += value)
                                     .ReadingWith("serverConsume", () => serverConsumeCount)
                                     .WritingWith <int>("clientConsume", (value) => clientConsumeCount += value)
                                     .ReadingWith("clientConsume", () => clientConsumeCount);

            _serverConsumer.UntilConsume = accessSafely;
            _clientConsumer.UntilConsume = accessSafely;

            Request(request);

            while (_serverConsumer.UntilConsume.ReadFrom <int>("serverConsume") < 1)
            {
                Thread.Sleep(1);
            }
            _serverConsumer.UntilConsume.ReadFromExpecting("serverConsume", 1);

            while (_clientConsumer.UntilConsume.ReadFrom <int>("clientConsume") < 1)
            {
                _client.ProbeChannel();
            }
            _clientConsumer.UntilConsume.ReadFromExpecting("clientConsume", 1);

            Assert.False(_serverConsumer.Requests.Count == 0);
        }
Esempio n. 2
0
        public void TestBasicRequestResponse()
        {
            _output.WriteLine("Starting TestBasicRequestResponse");
            var request = "Hello, Request-Response";

            _serverConsumer.CurrentExpectedRequestLength  = request.Length;
            _clientConsumer.CurrentExpectedResponseLength = _serverConsumer.CurrentExpectedRequestLength;
            _serverConsumer.CurrentState = new TestRequestChannelConsumer.State(1);
            _clientConsumer.CurrentState = new TestResponseChannelConsumer.State(1);

            Request(request);

            var remaining = _clientConsumer.CurrentState.Access.ReadFromNow <int>("remaining");

            while (remaining != 0)
            {
                _client.ProbeChannel();
                remaining = _clientConsumer.CurrentState.Access.ReadFromNow <int>("remaining");
            }

            Assert.True(_serverConsumer.Requests.Any());
            Assert.Equal(1, _serverConsumer.CurrentState.Access.ReadFrom <int>("consumeCount"));
            Assert.Equal(_serverConsumer.CurrentState.Access.ReadFrom <int>("consumeCount"), _serverConsumer.Requests.Count);

            Assert.True(_clientConsumer.Responses.Any());
            Assert.Equal(1, _clientConsumer.CurrentState.Access.ReadFrom <int>("consumeCount"));
            Assert.Equal(_clientConsumer.CurrentState.Access.ReadFrom <int>("consumeCount"), _clientConsumer.Responses.Count);

            Assert.Equal(_clientConsumer.Responses[0], _serverConsumer.Requests[0]);
        }
Esempio n. 3
0
        public void TestThatSecureClientRequestResponse()
        {
            var address = Address.From(Host.Of("www.google.com"), 443, AddressType.None);

            _client = new SecureClientRequestResponseChannel(address, _clientConsumer, _poolSize, 65536, _world.DefaultLogger);

            _clientConsumer.CurrentExpectedResponseLength = 500;
            var access = _clientConsumer.AfterCompleting(1);

            var get    = "GET / HTTP/1.1\nHost: www.google.com\nConnection: close\n\n";
            var buffer = BasicConsumerByteBuffer.Allocate(1, 1000);

            buffer.Put(Encoding.UTF8.GetBytes(get));
            buffer.Flip();
            _client.RequestWith(buffer.ToArray());

            for (int count = 0; count < 100; ++count)
            {
                if (access.TotalWrites > 0)
                {
                    break;
                }
                _client.ProbeChannel();
                Thread.Sleep(100);
            }

            Assert.True(_clientConsumer.GetConsumeCount() > 0);
            Assert.Contains("google.com", _clientConsumer.GetResponses().First());
        }
Esempio n. 4
0
        public void TestThatServerHandlesThrowables()
        {
            var request = GetExceptionRequest("1");

            _client.RequestWith(ToStream(request).ToArray());

            var consumeCalls = _progress.ExpectConsumeTimes(1);

            while (consumeCalls.TotalWrites < 1)
            {
                _client.ProbeChannel();
            }
            consumeCalls.ReadFrom <int>("completed");

            _progress.Responses.TryDequeue(out var createdResponse);

            Assert.Equal(1, _progress.ConsumeCount.Get());
            Assert.Equal(Response.ResponseStatus.InternalServerError, createdResponse.Status);
        }
Esempio n. 5
0
        public void TestThatServesRootStaticFile()
        {
            var resource = "/index.html";
            var content  = ReadTextFile(_contentRoot + resource);
            var request  = GetRequest(resource);

            _client.RequestWith(ToByteBuffer(request));

            var consumeCalls = _progress.ExpectConsumeTimes(1);

            while (consumeCalls.TotalWrites < 1)
            {
                _client.ProbeChannel();
            }

            consumeCalls.ReadFrom <int>("completed");

            _progress.Responses.TryDequeue(out var contentResponse);

            Assert.Equal(1, _progress.ConsumeCount.Get());
            Assert.Equal(Response.ResponseStatus.Ok, contentResponse.Status);
            Assert.Equal(content, contentResponse.Entity.Content);
        }
    public void TestThatFeedResourceFeeds()
    {
        var request = RequestFor($"{FeedURI}/100");

        var consumeCalls = _progress.ExpectConsumeTimes(1);

        _client.RequestWith(ToMemoryStream(request).ToArray());

        while (consumeCalls.TotalWrites < 1)
        {
            _client.ProbeChannel();
        }
        consumeCalls.ReadFrom <int>("completed");

        _progress.Responses.TryDequeue(out var contentResponse);

        Assert.Equal(1, _progress.ConsumeCount.Get());
        Assert.Equal(ResponseStatus.Ok, contentResponse.Status);
        Assert.Equal("events:100:1\n2\n3\n4\n5\n", contentResponse.Entity.Content);
    }
Esempio n. 7
0
 public void IntervalSignal(IScheduled <object> scheduled, object data)
 => _channel.ProbeChannel();