use of io.servicetalk.http.api.StreamingHttpClientFilterFactory in project servicetalk by apple.
the class ErrorHandlingTest method setUp.
private void setUp(TestMode testMode, GrpcExecutionStrategy serverStrategy, GrpcExecutionStrategy clientStrategy) throws Exception {
this.testMode = testMode;
cannedResponse = TestResponse.newBuilder().setMessage("foo").build();
ServiceFactory serviceFactory;
StreamingHttpServiceFilterFactory serviceFilterFactory = IDENTITY_FILTER;
StreamingHttpClientFilterFactory clientFilterFactory = IDENTITY_CLIENT_FILTER;
Publisher<TestRequest> requestPublisher = from(TestRequest.newBuilder().build());
switch(testMode) {
case HttpClientFilterThrows:
clientFilterFactory = new ErrorProducingClientFilter(true, DELIBERATE_EXCEPTION);
serviceFactory = setupForSuccess();
break;
case HttpClientFilterThrowsGrpcException:
clientFilterFactory = new ErrorProducingClientFilter(true, cannedException);
serviceFactory = setupForSuccess();
break;
case HttpClientFilterEmitsError:
clientFilterFactory = new ErrorProducingClientFilter(false, DELIBERATE_EXCEPTION);
serviceFactory = setupForSuccess();
break;
case HttpClientFilterEmitsGrpcException:
clientFilterFactory = new ErrorProducingClientFilter(false, cannedException);
serviceFactory = setupForSuccess();
break;
case HttpFilterThrows:
serviceFilterFactory = new ErrorProducingSvcFilter(true, DELIBERATE_EXCEPTION);
serviceFactory = setupForSuccess();
break;
case HttpFilterThrowsGrpcException:
serviceFilterFactory = new ErrorProducingSvcFilter(true, cannedException);
serviceFactory = setupForSuccess();
break;
case HttpFilterEmitsError:
serviceFilterFactory = new ErrorProducingSvcFilter(false, DELIBERATE_EXCEPTION);
serviceFactory = setupForSuccess();
break;
case HttpFilterEmitsGrpcException:
serviceFilterFactory = new ErrorProducingSvcFilter(false, cannedException);
serviceFactory = setupForSuccess();
break;
case ServiceThrows:
serviceFactory = setupForServiceThrows(DELIBERATE_EXCEPTION);
break;
case ServiceThrowsGrpcException:
serviceFactory = setupForServiceThrows(cannedException);
break;
case ServiceOperatorThrows:
serviceFactory = setupForServiceOperatorThrows(DELIBERATE_EXCEPTION);
break;
case ServiceOperatorThrowsGrpcException:
serviceFactory = setupForServiceOperatorThrows(cannedException);
break;
case ServiceSecondOperatorThrowsGrpcException:
serviceFactory = setupForServiceSecondOperatorThrows(cannedException);
requestPublisher = from(TestRequest.newBuilder().build(), TestRequest.newBuilder().setName(REQ_THROW_NAME).build());
break;
case ServiceEmitsError:
serviceFactory = setupForServiceEmitsError(DELIBERATE_EXCEPTION);
break;
case ServiceEmitsGrpcException:
serviceFactory = setupForServiceEmitsError(cannedException);
break;
case ServiceEmitsDataThenError:
serviceFactory = setupForServiceEmitsDataThenError(DELIBERATE_EXCEPTION);
break;
case ServiceEmitsDataThenGrpcException:
serviceFactory = setupForServiceEmitsDataThenError(cannedException);
break;
case BlockingServiceThrows:
serviceFactory = setupForBlockingServiceThrows(DELIBERATE_EXCEPTION);
break;
case BlockingServiceThrowsGrpcException:
serviceFactory = setupForBlockingServiceThrows(cannedException);
break;
case BlockingServiceWritesThenThrows:
serviceFactory = setupForBlockingServiceWritesThenThrows(DELIBERATE_EXCEPTION);
break;
case BlockingServiceWritesThenThrowsGrpcException:
serviceFactory = setupForBlockingServiceWritesThenThrows(cannedException);
break;
default:
throw new IllegalArgumentException("Unknown mode: " + testMode);
}
this.requestPublisher = requestPublisher;
final StreamingHttpServiceFilterFactory filterFactory = serviceFilterFactory;
serverContext = GrpcServers.forAddress(localAddress(0)).initializeHttp(builder -> builder.appendServiceFilter(filterFactory).executionStrategy(serverStrategy)).listenAndAwait(serviceFactory);
final StreamingHttpClientFilterFactory pickedClientFilterFactory = clientFilterFactory;
GrpcClientBuilder<HostAndPort, InetSocketAddress> clientBuilder = GrpcClients.forAddress(serverHostAndPort(serverContext)).initializeHttp(builder -> builder.appendClientFilter(pickedClientFilterFactory).executionStrategy(clientStrategy));
client = clientBuilder.build(new ClientFactory());
blockingClient = clientBuilder.buildBlocking(new ClientFactory());
}
use of io.servicetalk.http.api.StreamingHttpClientFilterFactory in project servicetalk by apple.
the class RedirectingHttpRequesterFilterTest method newClient.
private StreamingHttpClient newClient(RedirectConfig config, StreamingHttpClientFilterFactory... other) {
StreamingHttpClientFilterFactory result = new RedirectingHttpRequesterFilter(config);
for (StreamingHttpClientFilterFactory next : other) {
result = appendClientFilterFactory(result, next);
}
StreamingHttpClientFilterFactory mockResponse = client -> new StreamingHttpClientFilter(client) {
@Override
protected Single<StreamingHttpResponse> request(final StreamingHttpRequester delegate, final StreamingHttpRequest request) {
return httpClient.request(request);
}
};
return from(reqRespFactory, mock(HttpExecutionContext.class), appendClientFilterFactory(result, mockResponse));
}
use of io.servicetalk.http.api.StreamingHttpClientFilterFactory 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.StreamingHttpClientFilterFactory 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