Search in sources :

Example 1 with Key

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)));
        }
    }
}
Also used : FilterableStreamingHttpConnection(io.servicetalk.http.api.FilterableStreamingHttpConnection) AtomicReference(java.util.concurrent.atomic.AtomicReference) Key.newKey(io.servicetalk.context.api.ContextMap.Key.newKey) Key(io.servicetalk.context.api.ContextMap.Key) AsyncContext(io.servicetalk.concurrent.api.AsyncContext) Arrays.asList(java.util.Arrays.asList) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DelegatingConnectionFactory(io.servicetalk.client.api.DelegatingConnectionFactory) Nullable(javax.annotation.Nullable) MethodSource(org.junit.jupiter.params.provider.MethodSource) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) ConnectionFactory(io.servicetalk.client.api.ConnectionFactory) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ServerContext(io.servicetalk.transport.api.ServerContext) Single(io.servicetalk.concurrent.api.Single) Collection(java.util.Collection) ConnectionFactoryFilter(io.servicetalk.client.api.ConnectionFactoryFilter) HttpResponse(io.servicetalk.http.api.HttpResponse) OK(io.servicetalk.http.api.HttpResponseStatus.OK) InetSocketAddress(java.net.InetSocketAddress) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) ContextMap(io.servicetalk.context.api.ContextMap) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TransportObserver(io.servicetalk.transport.api.TransportObserver) Matchers.is(org.hamcrest.Matchers.is) HostAndPort(io.servicetalk.transport.api.HostAndPort) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) InetSocketAddress(java.net.InetSocketAddress) HttpResponse(io.servicetalk.http.api.HttpResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) HostAndPort(io.servicetalk.transport.api.HostAndPort) ServerContext(io.servicetalk.transport.api.ServerContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ConnectionFactory (io.servicetalk.client.api.ConnectionFactory)1 ConnectionFactoryFilter (io.servicetalk.client.api.ConnectionFactoryFilter)1 DelegatingConnectionFactory (io.servicetalk.client.api.DelegatingConnectionFactory)1 AsyncContext (io.servicetalk.concurrent.api.AsyncContext)1 Single (io.servicetalk.concurrent.api.Single)1 ContextMap (io.servicetalk.context.api.ContextMap)1 Key (io.servicetalk.context.api.ContextMap.Key)1 Key.newKey (io.servicetalk.context.api.ContextMap.Key.newKey)1 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)1 FilterableStreamingHttpConnection (io.servicetalk.http.api.FilterableStreamingHttpConnection)1 HttpResponse (io.servicetalk.http.api.HttpResponse)1 OK (io.servicetalk.http.api.HttpResponseStatus.OK)1 SingleAddressHttpClientBuilder (io.servicetalk.http.api.SingleAddressHttpClientBuilder)1 HostAndPort (io.servicetalk.transport.api.HostAndPort)1 ServerContext (io.servicetalk.transport.api.ServerContext)1 TransportObserver (io.servicetalk.transport.api.TransportObserver)1 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)1 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)1 InetSocketAddress (java.net.InetSocketAddress)1 Arrays.asList (java.util.Arrays.asList)1