Search in sources :

Example 1 with ReservedBlockingStreamingHttpConnection

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

the class ExecutionStrategyInContextTest method testBlockingStreaming.

@ParameterizedTest(name = "customStrategy={0}")
@ValueSource(booleans = { false, true })
void testBlockingStreaming(boolean customStrategy) throws Exception {
    BlockingStreamingHttpClient client = initClientAndServer(builder -> {
        if (customStrategy) {
            // Ensure we don't deadlock by not offloading receive meta
            expectedServerStrategy = customStrategyBuilder().offloadReceiveMetadata().build();
            builder.executionStrategy(expectedServerStrategy);
        }
        return builder.listenBlockingStreaming((ctx, request, response) -> {
            serviceStrategyRef.set(ctx.executionContext().executionStrategy());
            response.sendMetaData().close();
        });
    }, customStrategy).buildBlockingStreaming();
    clientAsCloseable = client;
    if (!customStrategy) {
        assert expectedClientStrategy == null;
        expectedClientStrategy = customStrategyBuilder().offloadSend().offloadEvent().build();
        assert expectedServerStrategy == null;
        expectedServerStrategy = customStrategyBuilder().offloadReceiveMetadata().build();
    }
    HttpExecutionStrategy clientStrat = client.executionContext().executionStrategy();
    assertThat("Unexpected client strategy.", clientStrat, equalStrategies(expectedClientStrategy));
    client.request(client.get("/"));
    assertThat("Unexpected service strategy", serviceStrategyRef.get(), equalStrategies(expectedServerStrategy));
    ReservedBlockingStreamingHttpConnection conn = client.reserveConnection(client.get("/"));
    assertThat("Unexpected connection strategy (from execution context).", conn.executionContext().executionStrategy(), equalStrategies(expectedClientStrategy));
    assertThat("Unexpected connection strategy (from execution context).", conn.connectionContext().executionContext().executionStrategy(), equalStrategies(expectedClientStrategy));
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) HttpExecutionStrategies.defaultStrategy(io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) HttpExecutionStrategies(io.servicetalk.http.api.HttpExecutionStrategies) HttpServerContext(io.servicetalk.http.api.HttpServerContext) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) HttpClient(io.servicetalk.http.api.HttpClient) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ReservedHttpConnection(io.servicetalk.http.api.ReservedHttpConnection) HttpServerBuilder(io.servicetalk.http.api.HttpServerBuilder) Nullable(javax.annotation.Nullable) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) ReservedBlockingStreamingHttpConnection(io.servicetalk.http.api.ReservedBlockingStreamingHttpConnection) ValueSource(org.junit.jupiter.params.provider.ValueSource) Description(org.hamcrest.Description) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ServerContext(io.servicetalk.transport.api.ServerContext) Single(io.servicetalk.concurrent.api.Single) HttpClients.forSingleAddress(io.servicetalk.http.netty.HttpClients.forSingleAddress) ReservedBlockingHttpConnection(io.servicetalk.http.api.ReservedBlockingHttpConnection) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) InetSocketAddress(java.net.InetSocketAddress) BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) Objects(java.util.Objects) HttpExecutionStrategies.customStrategyBuilder(io.servicetalk.http.api.HttpExecutionStrategies.customStrategyBuilder) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Matcher(org.hamcrest.Matcher) ReservedStreamingHttpConnection(io.servicetalk.http.api.ReservedStreamingHttpConnection) HostAndPort(io.servicetalk.transport.api.HostAndPort) BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) ReservedBlockingStreamingHttpConnection(io.servicetalk.http.api.ReservedBlockingStreamingHttpConnection) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Single (io.servicetalk.concurrent.api.Single)1 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)1 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)1 BlockingStreamingHttpClient (io.servicetalk.http.api.BlockingStreamingHttpClient)1 HttpClient (io.servicetalk.http.api.HttpClient)1 HttpExecutionStrategies (io.servicetalk.http.api.HttpExecutionStrategies)1 HttpExecutionStrategies.customStrategyBuilder (io.servicetalk.http.api.HttpExecutionStrategies.customStrategyBuilder)1 HttpExecutionStrategies.defaultStrategy (io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy)1 HttpExecutionStrategy (io.servicetalk.http.api.HttpExecutionStrategy)1 HttpServerBuilder (io.servicetalk.http.api.HttpServerBuilder)1 HttpServerContext (io.servicetalk.http.api.HttpServerContext)1 ReservedBlockingHttpConnection (io.servicetalk.http.api.ReservedBlockingHttpConnection)1 ReservedBlockingStreamingHttpConnection (io.servicetalk.http.api.ReservedBlockingStreamingHttpConnection)1 ReservedHttpConnection (io.servicetalk.http.api.ReservedHttpConnection)1 ReservedStreamingHttpConnection (io.servicetalk.http.api.ReservedStreamingHttpConnection)1 SingleAddressHttpClientBuilder (io.servicetalk.http.api.SingleAddressHttpClientBuilder)1 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)1 HttpClients.forSingleAddress (io.servicetalk.http.netty.HttpClients.forSingleAddress)1 HostAndPort (io.servicetalk.transport.api.HostAndPort)1 ServerContext (io.servicetalk.transport.api.ServerContext)1