Search in sources :

Example 26 with BlockingHttpClient

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

the class MalformedDataAfterHttpMessageTest method afterRequest.

@Test
void afterRequest() throws Exception {
    try (ServerContext server = stServer();
        BlockingHttpClient client = stClient(server.listenAddress())) {
        Buffer malformedBody = client.executionContext().bufferAllocator().fromAscii(CONTENT).writeShort(// malformed data at the end of the request msg
        0);
        HttpRequest request = client.post("/").setHeader(CONTENT_LENGTH, valueOf(CONTENT.length())).setHeader(CONTENT_TYPE, TEXT_PLAIN).payloadBody(malformedBody);
        ReservedBlockingHttpConnection connection = client.reserveConnection(request);
        CountDownLatch connectionClosedLatch = new CountDownLatch(1);
        connection.connectionContext().onClose().whenFinally(connectionClosedLatch::countDown).subscribe();
        assertThrows(IOException.class, () -> connection.request(request));
        // Server should close the connection:
        connectionClosedLatch.await();
    }
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) HttpRequest(io.servicetalk.http.api.HttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) CountDownLatch(java.util.concurrent.CountDownLatch) ReservedBlockingHttpConnection(io.servicetalk.http.api.ReservedBlockingHttpConnection) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with BlockingHttpClient

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

the class ServerEffectiveStrategyTest method asyncStreaming.

@ParameterizedTest
@EnumSource(ServerStrategyCase.class)
void asyncStreaming(final ServerStrategyCase strategyCase) throws Exception {
    try (Params params = strategyCase.apply(ServiceType.AsyncStreaming)) {
        assertThat("Null params supplied", params, notNullValue());
        BlockingHttpClient client = params.startAsyncStreaming();
        client.request(client.get("/").payloadBody(client.executionContext().bufferAllocator().fromAscii("Hello")));
        params.verifyOffloads();
    }
}
Also used : BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with BlockingHttpClient

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

the class NettyHttpServerConnectionDrainTest method requestIsAutoDrainedWhenUserFailsToConsume.

@Disabled("https://github.com/apple/servicetalk/issues/981")
@Test
void requestIsAutoDrainedWhenUserFailsToConsume() throws Exception {
    BlockingHttpClient client = null;
    try (ServerContext serverContext = server(true, respondOkWithoutReadingRequest())) {
        client = HttpClients.forSingleAddress(serverHostAndPort(serverContext)).buildBlocking();
        postLargePayloadAndAssertResponseOk(client);
    } finally {
        closeClient(client);
    }
}
Also used : ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 29 with BlockingHttpClient

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

the class BasicAuthStrategyInfluencerTest method defaultOffloads.

@Test
void defaultOffloads() throws Exception {
    BlockingHttpClient client = setup(false);
    assert service != null;
    HttpResponse response = makeRequest(client);
    assertThat("Unexpected response.", response.status().code(), is(200));
    service.assertHandleOffload(not(startsWith(IO_EXECUTOR_NAME_PREFIX)));
    service.assertRequestOffload(not(startsWith(IO_EXECUTOR_NAME_PREFIX)));
    service.assertResponseOffload(not(startsWith(IO_EXECUTOR_NAME_PREFIX)));
}
Also used : BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) HttpResponse(io.servicetalk.http.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 30 with BlockingHttpClient

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

the class PredicateRouterOffloadingTest method predicateOffloadedAndNotRoute.

@ParameterizedTest
@EnumSource(RouteServiceType.class)
void predicateOffloadedAndNotRoute(RouteServiceType routeServiceType) throws Exception {
    this.routeServiceType = routeServiceType;
    assumeSafeToDisableOffloading(routeServiceType);
    final HttpPredicateRouterBuilder routerBuilder = newRouterBuilder();
    serverBuilder.executor(executionContextRule.executor());
    routeServiceType.addThreadRecorderService(routerBuilder.when(this::recordRouterThread).executionStrategy(offloadNever()), this::recordThread);
    final BlockingHttpClient client = buildServerAndClient(routerBuilder.buildStreaming());
    client.request(client.get("/"));
    verifyAllOffloadPointsRecorded();
    // Server is still offloaded, noOffloadsStrategy at route level isn't enough to disable offloading
    assertRouteAndPredicateOffloaded();
}
Also used : BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)86 HttpResponse (io.servicetalk.http.api.HttpResponse)57 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)45 ServerContext (io.servicetalk.transport.api.ServerContext)43 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)27 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)26 InetSocketAddress (java.net.InetSocketAddress)26 MethodSource (org.junit.jupiter.params.provider.MethodSource)25 Test (org.junit.jupiter.api.Test)24 HttpRequest (io.servicetalk.http.api.HttpRequest)20 HttpSerializers.textSerializerUtf8 (io.servicetalk.http.api.HttpSerializers.textSerializerUtf8)20 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)20 Single (io.servicetalk.concurrent.api.Single)19 OK (io.servicetalk.http.api.HttpResponseStatus.OK)17 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 Matchers.is (org.hamcrest.Matchers.is)16 HostAndPort (io.servicetalk.transport.api.HostAndPort)15 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)14 HttpExecutionStrategy (io.servicetalk.http.api.HttpExecutionStrategy)13 ReservedBlockingHttpConnection (io.servicetalk.http.api.ReservedBlockingHttpConnection)13