Search in sources :

Example 1 with StreamingHttpConnectionFilterFactory

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

the class ConditionalFilterFactory method append.

public FilterFactory append(FilterFactory append) {
    StreamingHttpClientFilterFactory clientFactory = appendClientFilterFactory(this, append);
    StreamingHttpConnectionFilterFactory connectionFactory = appendConnectionFilterFactory(this, append);
    return new FilterFactory() {

        @Override
        public StreamingHttpClientFilter create(final FilterableStreamingHttpClient client) {
            return clientFactory.create(client);
        }

        @Override
        public StreamingHttpConnectionFilter create(final FilterableStreamingHttpConnection connection) {
            return connectionFactory.create(connection);
        }
    };
}
Also used : StreamingHttpClientFilterFactory(io.servicetalk.http.api.StreamingHttpClientFilterFactory) FilterableStreamingHttpClient(io.servicetalk.http.api.FilterableStreamingHttpClient) FilterableStreamingHttpConnection(io.servicetalk.http.api.FilterableStreamingHttpConnection) StreamingHttpConnectionFilterFactory(io.servicetalk.http.api.StreamingHttpConnectionFilterFactory) StreamingHttpClientFilterFactory(io.servicetalk.http.api.StreamingHttpClientFilterFactory) StreamingHttpConnectionFilterFactory(io.servicetalk.http.api.StreamingHttpConnectionFilterFactory)

Example 2 with StreamingHttpConnectionFilterFactory

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

the class ClientEffectiveStrategyTest method clientStrategy.

@ParameterizedTest(name = "API={0} builder={1} filter={2} LB={3} CF={4}")
@MethodSource("casesSupplier")
void clientStrategy(ClientType clientType, @Nullable final HttpExecutionStrategy builderStrategy, @Nullable final HttpExecutionStrategy filterStrategy, @Nullable final HttpExecutionStrategy lbStrategy, @Nullable final HttpExecutionStrategy cfStrategy) throws Exception {
    HttpExecutionStrategy effectiveStrategy = computeClientExecutionStrategy(builderStrategy, filterStrategy, lbStrategy, cfStrategy);
    SingleAddressHttpClientBuilder<HostAndPort, InetSocketAddress> clientBuilder = HttpClients.forSingleAddress(serverHostAndPort(context));
    if (builderStrategy != null) {
        clientBuilder.executionStrategy(builderStrategy);
    }
    ClientInvokingThreadRecorder invokingThreadsRecorder = new ClientInvokingThreadRecorder(clientType, effectiveStrategy);
    clientBuilder.appendClientFilter(invokingThreadsRecorder);
    if (null != filterStrategy) {
        clientBuilder.appendClientFilter(new StreamingHttpClientFilterFactory() {

            @Override
            public StreamingHttpClientFilter create(final FilterableStreamingHttpClient client) {
                return new StreamingHttpClientFilter(client) {
                };
            }

            @Override
            public HttpExecutionStrategy requiredOffloads() {
                return filterStrategy;
            }
        });
    }
    if (null != lbStrategy) {
        HttpLoadBalancerFactory<InetSocketAddress> lfFactory = DefaultHttpLoadBalancerFactory.Builder.from(new LoadBalancerFactoryImpl() {

            @Override
            public ExecutionStrategy requiredOffloads() {
                return lbStrategy;
            }
        }).build();
        clientBuilder.loadBalancerFactory(lfFactory);
    }
    if (null != cfStrategy) {
        clientBuilder.appendConnectionFilter(new StreamingHttpConnectionFilterFactory() {

            @Override
            public StreamingHttpConnectionFilter create(final FilterableStreamingHttpConnection connection) {
                return new StreamingHttpConnectionFilter(connection) {
                };
            }

            @Override
            public HttpExecutionStrategy requiredOffloads() {
                return cfStrategy;
            }
        });
    }
    // Exercise the client
    try (StreamingHttpClient client = clientBuilder.buildStreaming()) {
        String responseBody = getResponse(clientType, client);
        assertThat(responseBody, is(GREETING));
        invokingThreadsRecorder.verifyOffloads();
    }
}
Also used : FilterableStreamingHttpClient(io.servicetalk.http.api.FilterableStreamingHttpClient) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) InetSocketAddress(java.net.InetSocketAddress) FilterableStreamingHttpConnection(io.servicetalk.http.api.FilterableStreamingHttpConnection) StreamingHttpConnectionFilterFactory(io.servicetalk.http.api.StreamingHttpConnectionFilterFactory) StreamingHttpClientFilterFactory(io.servicetalk.http.api.StreamingHttpClientFilterFactory) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) HostAndPort(io.servicetalk.transport.api.HostAndPort) StreamingHttpClientFilter(io.servicetalk.http.api.StreamingHttpClientFilter) StreamingHttpConnectionFilter(io.servicetalk.http.api.StreamingHttpConnectionFilter) FilterableStreamingHttpClient(io.servicetalk.http.api.FilterableStreamingHttpClient) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

FilterableStreamingHttpClient (io.servicetalk.http.api.FilterableStreamingHttpClient)2 FilterableStreamingHttpConnection (io.servicetalk.http.api.FilterableStreamingHttpConnection)2 StreamingHttpClientFilterFactory (io.servicetalk.http.api.StreamingHttpClientFilterFactory)2 StreamingHttpConnectionFilterFactory (io.servicetalk.http.api.StreamingHttpConnectionFilterFactory)2 BlockingStreamingHttpClient (io.servicetalk.http.api.BlockingStreamingHttpClient)1 HttpExecutionStrategy (io.servicetalk.http.api.HttpExecutionStrategy)1 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)1 StreamingHttpClientFilter (io.servicetalk.http.api.StreamingHttpClientFilter)1 StreamingHttpConnectionFilter (io.servicetalk.http.api.StreamingHttpConnectionFilter)1 HostAndPort (io.servicetalk.transport.api.HostAndPort)1 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)1 InetSocketAddress (java.net.InetSocketAddress)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1