Search in sources :

Example 1 with HttpConnection

use of io.servicetalk.http.api.HttpConnection in project servicetalk by apple.

the class ExpectContinueTest method expectationFailedAggregated.

@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void expectationFailedAggregated(HttpProtocol protocol, boolean withCL) throws Exception {
    try (HttpServerContext serverContext = startServer(protocol);
        StreamingHttpClient client = createClient(serverContext, protocol);
        HttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get().asConnection()) {
        BufferAllocator allocator = connection.executionContext().bufferAllocator();
        Future<HttpResponse> responseFuture = connection.request(newRequest(connection, withCL, true, PAYLOAD + PAYLOAD, allocator)).toFuture();
        requestReceived.await();
        sendContinue.countDown();
        returnResponse.countDown();
        HttpResponse response = responseFuture.get();
        assertThat(response.status(), is(EXPECTATION_FAILED));
        assertThat(response.payloadBody().toString(US_ASCII), equalTo(""));
        sendFollowUpRequest(connection.asStreamingConnection(), withCL, allocator, OK);
    }
}
Also used : StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) HttpConnection(io.servicetalk.http.api.HttpConnection) StreamingHttpConnection(io.servicetalk.http.api.StreamingHttpConnection) HttpServerContext(io.servicetalk.http.api.HttpServerContext) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with HttpConnection

use of io.servicetalk.http.api.HttpConnection in project servicetalk by apple.

the class ExpectContinueTest method serverRespondsWithSuccessAggregated.

@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void serverRespondsWithSuccessAggregated(HttpProtocol protocol, boolean withCL) throws Exception {
    try (HttpServerContext serverContext = startServer(protocol, (ctx, request, response) -> {
        requestReceived.countDown();
        returnResponse.await();
        response.status(ACCEPTED);
        try (HttpPayloadWriter<Buffer> writer = response.sendMetaData()) {
            for (Buffer chunk : request.payloadBody()) {
                writer.write(chunk);
            }
        }
    });
        StreamingHttpClient client = createClient(serverContext, protocol);
        HttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get().asConnection()) {
        BufferAllocator allocator = connection.executionContext().bufferAllocator();
        returnResponse.countDown();
        HttpResponse response = connection.request(newRequest(connection, withCL, false, PAYLOAD + PAYLOAD, allocator)).toFuture().get();
        assertThat(response.status(), is(ACCEPTED));
        assertThat(response.payloadBody().toString(US_ASCII), equalTo(PAYLOAD + PAYLOAD));
        sendFollowUpRequest(connection.asStreamingConnection(), withCL, allocator, ACCEPTED);
    }
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) HttpConnection(io.servicetalk.http.api.HttpConnection) StreamingHttpConnection(io.servicetalk.http.api.StreamingHttpConnection) HttpServerContext(io.servicetalk.http.api.HttpServerContext) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with HttpConnection

use of io.servicetalk.http.api.HttpConnection in project servicetalk by apple.

the class ExpectContinueTest method expectContinueAggregated.

@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void expectContinueAggregated(HttpProtocol protocol, boolean withCL) throws Exception {
    try (HttpServerContext serverContext = startServer(protocol);
        StreamingHttpClient client = createClient(serverContext, protocol);
        HttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get().asConnection()) {
        BufferAllocator allocator = connection.executionContext().bufferAllocator();
        Future<HttpResponse> responseFuture = connection.request(newRequest(connection, withCL, false, PAYLOAD + PAYLOAD, allocator)).toFuture();
        requestReceived.await();
        sendContinue.countDown();
        returnResponse.countDown();
        HttpResponse response = responseFuture.get();
        assertThat(response.status(), is(OK));
        assertThat(response.payloadBody().toString(US_ASCII), equalTo(PAYLOAD + PAYLOAD));
        sendFollowUpRequest(connection.asStreamingConnection(), withCL, allocator, OK);
    }
}
Also used : StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) HttpConnection(io.servicetalk.http.api.HttpConnection) StreamingHttpConnection(io.servicetalk.http.api.StreamingHttpConnection) HttpServerContext(io.servicetalk.http.api.HttpServerContext) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with HttpConnection

use of io.servicetalk.http.api.HttpConnection in project servicetalk by apple.

the class StreamObserverTest method maxActiveStreamsViolationError.

@Disabled("https://github.com/apple/servicetalk/issues/1264")
@Test
void maxActiveStreamsViolationError() throws Exception {
    CountDownLatch maxConcurrentStreamsValueSetToOne = new CountDownLatch(1);
    try (HttpConnection connection = client.reserveConnection(client.get("/")).map(conn -> {
        conn.transportEventStream(MAX_CONCURRENCY).forEach(event -> {
            if (event.event() == 1) {
                maxConcurrentStreamsValueSetToOne.countDown();
            }
        });
        return conn;
    }).toFuture().get()) {
        verify(clientTransportObserver).onNewConnection(any(), any());
        verify(clientConnectionObserver).multiplexedConnectionEstablished(any(ConnectionInfo.class));
        connection.request(connection.get("/first")).subscribe(__ -> {
        /* no response expected */
        });
        requestReceived.await();
        maxConcurrentStreamsValueSetToOne.await();
        ExecutionException e = assertThrows(ExecutionException.class, () -> connection.request(connection.get("/second")).toFuture().get());
        assertThat(e.getCause(), instanceOf(Http2Exception.class));
        assertThat(e.getCause(), instanceOf(RetryableException.class));
        assertThat(e.getCause().getCause(), instanceOf(StreamException.class));
        verify(clientMultiplexedObserver, times(2)).onNewStream();
        verify(clientStreamObserver, times(2)).streamEstablished();
        verify(clientDataObserver, times(2)).onNewRead();
        verify(clientDataObserver, times(2)).onNewWrite();
        verify(clientReadObserver).readFailed(any(ClosedChannelException.class));
        verify(clientWriteObserver).writeFailed(e.getCause());
        verify(clientStreamObserver, await()).streamClosed(e.getCause());
    }
    verify(clientStreamObserver, await()).streamClosed();
    verify(clientConnectionObserver).connectionClosed();
    verifyNoMoreInteractions(clientTransportObserver, clientMultiplexedObserver, clientStreamObserver, clientDataObserver);
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) Http2Exception(io.servicetalk.http.api.Http2Exception) RetryableException(io.servicetalk.transport.api.RetryableException) HttpConnection(io.servicetalk.http.api.HttpConnection) FilterableStreamingHttpConnection(io.servicetalk.http.api.FilterableStreamingHttpConnection) ConnectionInfo(io.servicetalk.transport.api.ConnectionInfo) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 5 with HttpConnection

use of io.servicetalk.http.api.HttpConnection in project servicetalk by apple.

the class ExpectContinueTest method serverErrorAggregated.

@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void serverErrorAggregated(HttpProtocol protocol, boolean withCL) throws Exception {
    try (HttpServerContext serverContext = startServer(protocol, (ctx, request, response) -> {
        requestReceived.countDown();
        returnResponse.await();
        if (request.headers().contains(EXPECT, CONTINUE)) {
            response.status(INTERNAL_SERVER_ERROR);
        }
        response.sendMetaData().close();
    });
        StreamingHttpClient client = createClient(serverContext, protocol);
        HttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get().asConnection()) {
        BufferAllocator allocator = connection.executionContext().bufferAllocator();
        Future<HttpResponse> responseFuture = connection.request(newRequest(connection, withCL, false, PAYLOAD + PAYLOAD, allocator)).toFuture();
        requestReceived.await();
        returnResponse.countDown();
        HttpResponse response = responseFuture.get();
        assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
        assertThat(response.payloadBody().toString(US_ASCII), equalTo(""));
        // send a follow-up request on the same connection:
        response = connection.request(connection.get("/")).toFuture().get();
        assertThat(response.status(), is(OK));
        assertThat(response.payloadBody().toString(US_ASCII), equalTo(""));
    }
}
Also used : StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) HttpConnection(io.servicetalk.http.api.HttpConnection) StreamingHttpConnection(io.servicetalk.http.api.StreamingHttpConnection) HttpServerContext(io.servicetalk.http.api.HttpServerContext) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

HttpConnection (io.servicetalk.http.api.HttpConnection)5 BufferAllocator (io.servicetalk.buffer.api.BufferAllocator)4 HttpResponse (io.servicetalk.http.api.HttpResponse)4 HttpServerContext (io.servicetalk.http.api.HttpServerContext)4 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)4 StreamingHttpConnection (io.servicetalk.http.api.StreamingHttpConnection)4 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 StreamException (io.netty.handler.codec.http2.Http2Exception.StreamException)1 Buffer (io.servicetalk.buffer.api.Buffer)1 FilterableStreamingHttpConnection (io.servicetalk.http.api.FilterableStreamingHttpConnection)1 Http2Exception (io.servicetalk.http.api.Http2Exception)1 ConnectionInfo (io.servicetalk.transport.api.ConnectionInfo)1 RetryableException (io.servicetalk.transport.api.RetryableException)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 Disabled (org.junit.jupiter.api.Disabled)1 Test (org.junit.jupiter.api.Test)1