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