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()));
}
}
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));
}
Aggregations