Search in sources :

Example 16 with StreamingHttpConnection

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

the class ExpectContinueTest method expectationFailed.

@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void expectationFailed(HttpProtocol protocol, boolean withCL) throws Exception {
    try (HttpServerContext serverContext = startServer(protocol);
        StreamingHttpClient client = createClient(serverContext, protocol);
        StreamingHttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get()) {
        TestPublisher<Buffer> payload = new TestPublisher.Builder<Buffer>().singleSubscriber().build();
        connection.request(newRequest(connection, withCL, true, payload)).subscribe(responses::add);
        requestReceived.await();
        assertThat("Unexpected subscribe to payload body before 100 (Continue)", payload.isSubscribed(), is(false));
        returnResponse.countDown();
        assertResponse(EXPECTATION_FAILED, "");
        assertThat("Unexpected subscribe to payload body on expectation failed", payload.isSubscribed(), is(false));
        sendContinue.countDown();
        sendFollowUpRequest(connection, withCL, connection.executionContext().bufferAllocator(), OK);
    }
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) RedirectConfigBuilder(io.servicetalk.http.api.RedirectConfigBuilder) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) HttpServerContext(io.servicetalk.http.api.HttpServerContext) StreamingHttpConnection(io.servicetalk.http.api.StreamingHttpConnection) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with StreamingHttpConnection

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

the class ExpectContinueTest method expectContinue.

@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void expectContinue(HttpProtocol protocol, boolean withCL) throws Exception {
    try (HttpServerContext serverContext = startServer(protocol);
        StreamingHttpClient client = createClient(serverContext, protocol);
        StreamingHttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get()) {
        BufferAllocator allocator = connection.executionContext().bufferAllocator();
        TestPublisher<Buffer> payload = new TestPublisher.Builder<Buffer>().singleSubscriber().build();
        connection.request(newRequest(connection, withCL, false, payload)).subscribe(responses::add);
        requestReceived.await();
        assertThat("Unexpected subscribe to payload body before 100 (Continue)", payload.isSubscribed(), is(false));
        sendContinue.countDown();
        sendRequestPayload(payload, allocator);
        returnResponse.countDown();
        assertResponse(OK, PAYLOAD + PAYLOAD);
        sendFollowUpRequest(connection, withCL, allocator, OK);
    }
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) RedirectConfigBuilder(io.servicetalk.http.api.RedirectConfigBuilder) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) HttpServerContext(io.servicetalk.http.api.HttpServerContext) StreamingHttpConnection(io.servicetalk.http.api.StreamingHttpConnection) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 18 with StreamingHttpConnection

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

the class ExpectContinueTest method expectContinueConnectionClose.

@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void expectContinueConnectionClose(HttpProtocol protocol, boolean withCL) throws Exception {
    assumeTrue(protocol == HTTP_1);
    try (HttpServerContext serverContext = startServer(protocol);
        StreamingHttpClient client = createClient(serverContext, protocol);
        StreamingHttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get()) {
        TestPublisher<Buffer> payload = new TestPublisher.Builder<Buffer>().singleSubscriber().build();
        connection.request(newRequest(connection, withCL, false, payload).setHeader(CONNECTION, CLOSE)).subscribe(responses::add);
        requestReceived.await();
        assertThat("Unexpected subscribe to payload body before 100 (Continue)", payload.isSubscribed(), is(false));
        sendContinue.countDown();
        sendRequestPayload(payload, connection.executionContext().bufferAllocator());
        returnResponse.countDown();
        assertResponse(OK, PAYLOAD + PAYLOAD);
        connection.onClose().toFuture().get();
    }
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) RedirectConfigBuilder(io.servicetalk.http.api.RedirectConfigBuilder) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) HttpServerContext(io.servicetalk.http.api.HttpServerContext) StreamingHttpConnection(io.servicetalk.http.api.StreamingHttpConnection) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 19 with StreamingHttpConnection

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

the class FlushStrategyForClientApiTest method streamingApiShouldFlushOnEach.

@Test
void streamingApiShouldFlushOnEach() throws Exception {
    final StreamingHttpConnection connection = streamingHttpConnection();
    final SingleSource.Processor<Buffer, Buffer> payloadItemProcessor = Processors.newSingleProcessor();
    final Publisher<Buffer> payload = fromSource(payloadItemProcessor).toPublisher();
    final Single<StreamingHttpResponse> responseSingle = connection.request(connection.newRequest(POST, "/").payloadBody(payload));
    // Subscribe, to initiate the request, but we don't care about the response.
    responseSingle.toFuture();
    // Wait for the server to receive the response, meaning the client wrote and flushed.
    requestLatch.await();
    MatcherAssert.assertThat(payloadBuffersReceived.size(), is(0));
    final Buffer payloadItem = BufferAllocators.DEFAULT_ALLOCATOR.fromAscii("Hello");
    payloadItemProcessor.onSuccess(payloadItem);
    // Wait for the server to receive the payload
    Buffer receivedBuffer = payloadBuffersReceived.take();
    MatcherAssert.assertThat(receivedBuffer, is(payloadItem));
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) SingleSource(io.servicetalk.concurrent.SingleSource) StreamingHttpConnection(io.servicetalk.http.api.StreamingHttpConnection) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) Test(org.junit.jupiter.api.Test)

Example 20 with StreamingHttpConnection

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

the class FlushStrategyForClientApiTest method aggregatedApiShouldNotOverrideExplicit.

@Test
void aggregatedApiShouldNotOverrideExplicit() throws Exception {
    final StreamingHttpConnection connection = streamingHttpConnection();
    ((NettyConnectionContext) connection.connectionContext()).updateFlushStrategy((prev, isOriginal) -> FlushStrategies.flushOnEach());
    final Single<StreamingHttpResponse> responseSingle = connection.request(connection.asConnection().newRequest(POST, "/").addHeader(TRANSFER_ENCODING, CHUNKED).toStreamingRequest().payloadBody(Publisher.never()));
    // Subscribe, to initiate the request, but we don't care about the response.
    responseSingle.toFuture();
    // Wait for the server to receive the response, meaning the client wrote and flushed.
    requestLatch.await();
}
Also used : NettyConnectionContext(io.servicetalk.transport.netty.internal.NettyConnectionContext) StreamingHttpConnection(io.servicetalk.http.api.StreamingHttpConnection) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

StreamingHttpConnection (io.servicetalk.http.api.StreamingHttpConnection)29 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)13 Buffer (io.servicetalk.buffer.api.Buffer)12 Test (org.junit.jupiter.api.Test)12 SingleAddressHttpClientBuilder (io.servicetalk.http.api.SingleAddressHttpClientBuilder)10 HttpServerContext (io.servicetalk.http.api.HttpServerContext)9 RedirectConfigBuilder (io.servicetalk.http.api.RedirectConfigBuilder)9 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 ExecutionException (java.util.concurrent.ExecutionException)6 BufferAllocator (io.servicetalk.buffer.api.BufferAllocator)5 EnumSource (org.junit.jupiter.params.provider.EnumSource)5 ServerContext (io.servicetalk.transport.api.ServerContext)4 Single (io.servicetalk.concurrent.api.Single)3 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 CharSequences.newAsciiString (io.servicetalk.buffer.api.CharSequences.newAsciiString)2 Publisher.fromInputStream (io.servicetalk.concurrent.api.Publisher.fromInputStream)2 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)2