Beispiel #1
0
 private void Request(string request)
 {
     _buffer.Clear();
     _buffer.Write(Converters.TextToBytes(request));
     _buffer.Flip();
     _client.RequestWith(_buffer.ToArray());
 }
Beispiel #2
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());
        }
Beispiel #3
0
        public void SendRequest(Request request)
        {
            _buffer.Clear();
            var array = Converters.TextToBytes(request.ToString());

            _buffer.Write(array, 0, array.Length);
            _buffer.Flip();
            _channel.RequestWith(_buffer.ToArray());
        }
Beispiel #4
0
        public void SendRequest(Request request)
        {
            _buffer.Clear();
            _buffer.Seek(0, SeekOrigin.Begin);
            var array = Converters.TextToBytes(request.ToString());

            _buffer.Write(array, 0, array.Length);
            _buffer.Flip();
            _channel.RequestWith(_buffer.GetBuffer());
        }
        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);
        }
Beispiel #6
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);
    }