use of io.servicetalk.http.api.DefaultHttpExecutionContext in project servicetalk by apple.
the class TimeoutHttpRequesterFilterTest method applyFilter.
private static Single<StreamingHttpResponse> applyFilter(TimeoutHttpRequesterFilter filterFactory, final HttpExecutionStrategy strategy, final Single<StreamingHttpResponse> responseSingle) {
HttpExecutionContext executionContext = new DefaultHttpExecutionContext(DEFAULT_ALLOCATOR, IO_EXECUTOR, EXECUTOR, strategy);
HttpConnectionContext connectionContext = mock(HttpConnectionContext.class);
when(connectionContext.executionContext()).thenReturn(executionContext);
FilterableStreamingHttpConnection connection = mock(FilterableStreamingHttpConnection.class);
when(connection.executionContext()).thenReturn(executionContext);
when(connection.request(any())).thenReturn(responseSingle);
StreamingHttpRequester requester = filterFactory.create(connection);
return requester.request(mock(StreamingHttpRequest.class));
}
use of io.servicetalk.http.api.DefaultHttpExecutionContext in project servicetalk by apple.
the class FlushStrategyOnServerTest method setUp.
private void setUp(final Param param) {
this.interceptor = new OutboundWriteEventsInterceptor();
this.headersFactory = DefaultHttpHeadersFactory.INSTANCE;
final StreamingHttpService service = (ctx, request, responseFactory) -> {
StreamingHttpResponse resp = responseFactory.ok();
if (request.headers().get(USE_EMPTY_RESP_BODY) == null) {
resp.payloadBody(from("Hello", "World"), appSerializerUtf8FixLen());
}
if (request.headers().get(USE_AGGREGATED_RESP) != null) {
return resp.toResponse().map(HttpResponse::toStreamingResponse);
}
return succeeded(resp);
};
final DefaultHttpExecutionContext httpExecutionContext = new DefaultHttpExecutionContext(DEFAULT_ALLOCATOR, globalExecutionContext().ioExecutor(), EXECUTOR_RULE.executor(), param.executionStrategy);
final ReadOnlyHttpServerConfig config = new HttpServerConfig().asReadOnly();
final ReadOnlyTcpServerConfig tcpReadOnly = new TcpServerConfig().asReadOnly();
try {
serverContext = TcpServerBinder.bind(localAddress(0), tcpReadOnly, true, httpExecutionContext, null, (channel, observer) -> {
final ConnectionObserver connectionObserver = config.tcpConfig().transportObserver().onNewConnection(channel.localAddress(), channel.remoteAddress());
return initChannel(channel, httpExecutionContext, config, new TcpServerChannelInitializer(tcpReadOnly, connectionObserver).andThen(channel1 -> channel1.pipeline().addLast(interceptor)), service, true, connectionObserver);
}, connection -> connection.process(true)).map(delegate -> new NettyHttpServerContext(delegate, service, httpExecutionContext)).toFuture().get();
} catch (Exception e) {
fail(e);
}
client = HttpClients.forSingleAddress(serverHostAndPort(serverContext)).protocols(h1Default()).buildBlocking();
}
use of io.servicetalk.http.api.DefaultHttpExecutionContext in project servicetalk by apple.
the class TimeoutHttpServiceFilterTest method applyFilter.
private static Single<StreamingHttpResponse> applyFilter(TimeoutHttpServiceFilter filterFactory, final HttpExecutionStrategy strategy, final Single<StreamingHttpResponse> responseSingle) {
HttpExecutionContext executionContext = new DefaultHttpExecutionContext(DEFAULT_ALLOCATOR, IO_EXECUTOR, EXECUTOR, strategy);
HttpServiceContext serviceContext = mock(HttpServiceContext.class);
when(serviceContext.executionContext()).thenReturn(executionContext);
StreamingHttpService service = mock(StreamingHttpService.class);
when(service.handle(any(), any(), any())).thenReturn(responseSingle);
StreamingHttpServiceFilter filter = filterFactory.create(service);
return filter.handle(serviceContext, mock(StreamingHttpRequest.class), mock(StreamingHttpResponseFactory.class));
}
Aggregations