use of io.servicetalk.http.api.FilterableStreamingHttpClient in project servicetalk by apple.
the class EnforceSequentialModeRequesterFilterTest method responseCompletesAfterRequestPayloadBodyCompletes.
@Test
void responseCompletesAfterRequestPayloadBodyCompletes() {
TestPublisher<Buffer> payloadBody = new TestPublisher<>();
StreamingHttpRequest request = REQ_RES_FACTORY.post("/").payloadBody(payloadBody);
FilterableStreamingHttpClient client = EnforceSequentialModeRequesterFilter.INSTANCE.create(this.client);
StepVerifiers.create(client.request(request)).expectCancellable().then(payloadBody::onComplete).expectSuccess().verify();
}
use of io.servicetalk.http.api.FilterableStreamingHttpClient in project servicetalk by apple.
the class DefaultMultiAddressUrlHttpClientBuilder method buildStreaming.
@Override
public StreamingHttpClient buildStreaming() {
final CompositeCloseable closeables = newCompositeCloseable();
try {
final HttpClientBuildContext<HostAndPort, InetSocketAddress> buildContext = builderTemplate.copyBuildCtx();
final ClientFactory clientFactory = new ClientFactory(buildContext.builder, singleAddressInitializer);
HttpExecutionContext executionContext = buildContext.builder.executionContextBuilder.build();
final CachingKeyFactory keyFactory = closeables.prepend(new CachingKeyFactory());
FilterableStreamingHttpClient urlClient = closeables.prepend(new StreamingUrlHttpClient(executionContext, clientFactory, keyFactory, defaultReqRespFactory(buildContext.httpConfig().asReadOnly(), executionContext.bufferAllocator())));
// Need to wrap the top level client (group) in order for non-relative redirects to work
urlClient = redirectConfig == null ? urlClient : new RedirectingHttpRequesterFilter(redirectConfig).create(urlClient);
HttpExecutionStrategy computedStrategy = buildContext.builder.computeChainStrategy(executionContext.executionStrategy());
LOGGER.debug("Client created with base strategy {} → computed strategy {}", executionContext.executionStrategy(), computedStrategy);
return new FilterableClientToClient(urlClient, computedStrategy);
} catch (final Throwable t) {
closeables.closeAsync().subscribe();
throw t;
}
}
use of io.servicetalk.http.api.FilterableStreamingHttpClient in project servicetalk by apple.
the class RetryingHttpRequesterFilterAutoRetryStrategiesTest method newFilter.
private ContextAwareRetryingHttpClientFilter newFilter(final RetryingHttpRequesterFilter filter) {
final FilterableStreamingHttpClient client = mock(FilterableStreamingHttpClient.class);
final HttpExecutionContext executionContext = mock(HttpExecutionContext.class);
when(executionContext.executor()).then((Answer<Executor>) invocation -> immediate());
when(client.executionContext()).then(__ -> executionContext);
final ContextAwareRetryingHttpClientFilter f = (ContextAwareRetryingHttpClientFilter) filter.create(client);
f.inject(lbEvents, sdStatus);
return f;
}
use of io.servicetalk.http.api.FilterableStreamingHttpClient 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);
}
};
}
use of io.servicetalk.http.api.FilterableStreamingHttpClient 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();
}
}
Aggregations