Search in sources :

Example 1 with ReservedHttpConnection

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

the class H2ConcurrencyControllerTest method noMaxActiveStreamsViolatedError.

@Test
void noMaxActiveStreamsViolatedError() throws Exception {
    CountDownLatch maxConcurrencyUpdated = new CountDownLatch(1);
    try (ReservedHttpConnection connection = client.reserveConnection(client.get("/")).map(conn -> {
        conn.transportEventStream(MAX_CONCURRENCY).forEach(event -> {
            if (event.event() == MAX_CONCURRENT_STREAMS_VALUE) {
                maxConcurrencyUpdated.countDown();
            }
        });
        return conn;
    }).toFuture().get()) {
        awaitMaxConcurrentStreamsSettingsUpdate(connection, maxConcurrencyUpdated);
        BlockingQueue<Throwable> exceptions = new LinkedBlockingDeque<>();
        for (int i = 0; i < N_ITERATIONS; i++) {
            final int idx = i;
            Cancellable cancellable = client.request(client.get("/" + i)).whenOnError(exceptions::add).afterFinally(() -> latches[idx].countDown()).subscribe(__ -> {
            /* response is not expected */
            });
            latches[i].await();
            cancellable.cancel();
        }
        assertThat(exceptions, is(empty()));
    }
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) Cancellable(io.servicetalk.concurrent.Cancellable) CountDownLatch(java.util.concurrent.CountDownLatch) ReservedHttpConnection(io.servicetalk.http.api.ReservedHttpConnection) Test(org.junit.jupiter.api.Test)

Example 2 with ReservedHttpConnection

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

the class ExecutionStrategyInContextTest method testAsync.

@ParameterizedTest(name = "customStrategy={0}")
@ValueSource(booleans = { false, true })
void testAsync(boolean customStrategy) throws Exception {
    HttpClient client = initClientAndServer(builder -> builder.listen((ctx, request, responseFactory) -> {
        serviceStrategyRef.set(ctx.executionContext().executionStrategy());
        return succeeded(responseFactory.ok());
    }), customStrategy).build();
    clientAsCloseable = client;
    if (!customStrategy) {
        assert expectedClientStrategy == null;
        expectedClientStrategy = customStrategyBuilder().offloadReceiveData().offloadEvent().build();
        assert expectedServerStrategy == null;
        expectedServerStrategy = customStrategyBuilder().offloadReceiveData().offloadSend().build();
    }
    HttpExecutionStrategy clientStrat = client.executionContext().executionStrategy();
    assertThat("Unexpected client strategy.", clientStrat, equalStrategies(expectedClientStrategy));
    client.request(client.get("/")).toFuture().get();
    assertThat("Unexpected service strategy", serviceStrategyRef.get(), equalStrategies(expectedServerStrategy));
    ReservedHttpConnection conn = client.reserveConnection(client.get("/")).toFuture().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) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) HttpClient(io.servicetalk.http.api.HttpClient) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) ReservedHttpConnection(io.servicetalk.http.api.ReservedHttpConnection) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ReservedHttpConnection (io.servicetalk.http.api.ReservedHttpConnection)2 Cancellable (io.servicetalk.concurrent.Cancellable)1 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 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