use of io.servicetalk.context.api.ContextMap.Key in project servicetalk by apple.
the class MixedFiltersTest method testSingleClient.
@ParameterizedTest(name = "{displayName} [{index}] filters={0}")
@MethodSource("arguments")
void testSingleClient(List<AbstractFactoryFilter> filters) throws Exception {
String expected = filters.stream().map(AbstractFactoryFilter::toString).reduce((first, second) -> first + ',' + second).get();
try (ServerContext serverContext = HttpServers.forAddress(localAddress(0)).listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok())) {
SingleAddressHttpClientBuilder<HostAndPort, InetSocketAddress> builder = HttpClients.forSingleAddress(serverHostAndPort(serverContext));
filters.forEach(builder::appendConnectionFactoryFilter);
try (BlockingHttpClient client = builder.buildBlocking()) {
AtomicReference<StringBuilder> ref = new AtomicReference<>(new StringBuilder());
AsyncContext.put(KEY, ref);
HttpResponse response = client.request(client.get("/"));
assertThat(response.status(), is(OK));
assertThat(ref.toString(), is(equalTo(expected)));
}
}
}
Aggregations