Search in sources :

Example 1 with DefaultHttpExecutionContext

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));
}
Also used : StreamingHttpRequester(io.servicetalk.http.api.StreamingHttpRequester) HttpConnectionContext(io.servicetalk.http.api.HttpConnectionContext) DefaultHttpExecutionContext(io.servicetalk.http.api.DefaultHttpExecutionContext) HttpExecutionContext(io.servicetalk.http.api.HttpExecutionContext) FilterableStreamingHttpConnection(io.servicetalk.http.api.FilterableStreamingHttpConnection) DefaultHttpExecutionContext(io.servicetalk.http.api.DefaultHttpExecutionContext) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest)

Example 2 with DefaultHttpExecutionContext

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();
}
Also used : DefaultHttpExecutionContext(io.servicetalk.http.api.DefaultHttpExecutionContext) TcpServerChannelInitializer(io.servicetalk.tcp.netty.internal.TcpServerChannelInitializer) TcpServerConfig(io.servicetalk.tcp.netty.internal.TcpServerConfig) ReadOnlyTcpServerConfig(io.servicetalk.tcp.netty.internal.ReadOnlyTcpServerConfig) ChannelPromise(io.netty.channel.ChannelPromise) HttpExecutionStrategies.defaultStrategy(io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy) Executor(io.servicetalk.concurrent.api.Executor) GlobalExecutionContext.globalExecutionContext(io.servicetalk.transport.netty.internal.GlobalExecutionContext.globalExecutionContext) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) ExecutorExtension(io.servicetalk.concurrent.api.ExecutorExtension) HttpResponse(io.servicetalk.http.api.HttpResponse) TRANSFER_ENCODING(io.servicetalk.http.api.HttpHeaderNames.TRANSFER_ENCODING) BlockingQueue(java.util.concurrent.BlockingQueue) DefaultHttpHeadersFactory(io.servicetalk.http.api.DefaultHttpHeadersFactory) HttpExecutionStrategies.customStrategyBuilder(io.servicetalk.http.api.HttpExecutionStrategies.customStrategyBuilder) StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Assertions.fail(org.junit.jupiter.api.Assertions.fail) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) DEFAULT_ALLOCATOR(io.servicetalk.buffer.netty.BufferAllocators.DEFAULT_ALLOCATOR) StreamingHttpRequests.newTransportRequest(io.servicetalk.http.api.StreamingHttpRequests.newTransportRequest) HttpHeaders(io.servicetalk.http.api.HttpHeaders) EnumSource(org.junit.jupiter.params.provider.EnumSource) NettyHttpServer.initChannel(io.servicetalk.http.netty.NettyHttpServer.initChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ConnectionObserver(io.servicetalk.transport.api.ConnectionObserver) HttpProtocolConfigs.h1Default(io.servicetalk.http.netty.HttpProtocolConfigs.h1Default) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) HttpSerializers.appSerializerUtf8FixLen(io.servicetalk.http.api.HttpSerializers.appSerializerUtf8FixLen) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Publisher.from(io.servicetalk.concurrent.api.Publisher.from) CHUNKED(io.servicetalk.http.api.HttpHeaderValues.CHUNKED) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ServerContext(io.servicetalk.transport.api.ServerContext) GET(io.servicetalk.http.api.HttpRequestMethod.GET) TcpServerBinder(io.servicetalk.tcp.netty.internal.TcpServerBinder) NettyHttpServerContext(io.servicetalk.http.netty.NettyHttpServer.NettyHttpServerContext) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) HttpHeadersFactory(io.servicetalk.http.api.HttpHeadersFactory) HTTP_1_1(io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_1) HttpExecutionStrategies.offloadNever(io.servicetalk.http.api.HttpExecutionStrategies.offloadNever) NettyHttpServerContext(io.servicetalk.http.netty.NettyHttpServer.NettyHttpServerContext) TcpServerChannelInitializer(io.servicetalk.tcp.netty.internal.TcpServerChannelInitializer) DefaultHttpExecutionContext(io.servicetalk.http.api.DefaultHttpExecutionContext) TcpServerConfig(io.servicetalk.tcp.netty.internal.TcpServerConfig) ReadOnlyTcpServerConfig(io.servicetalk.tcp.netty.internal.ReadOnlyTcpServerConfig) ConnectionObserver(io.servicetalk.transport.api.ConnectionObserver) StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) ReadOnlyTcpServerConfig(io.servicetalk.tcp.netty.internal.ReadOnlyTcpServerConfig) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse)

Example 3 with DefaultHttpExecutionContext

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));
}
Also used : StreamingHttpServiceFilter(io.servicetalk.http.api.StreamingHttpServiceFilter) DefaultHttpExecutionContext(io.servicetalk.http.api.DefaultHttpExecutionContext) HttpExecutionContext(io.servicetalk.http.api.HttpExecutionContext) HttpServiceContext(io.servicetalk.http.api.HttpServiceContext) StreamingHttpResponseFactory(io.servicetalk.http.api.StreamingHttpResponseFactory) StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) DefaultHttpExecutionContext(io.servicetalk.http.api.DefaultHttpExecutionContext) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest)

Aggregations

DefaultHttpExecutionContext (io.servicetalk.http.api.DefaultHttpExecutionContext)3 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)3 HttpExecutionContext (io.servicetalk.http.api.HttpExecutionContext)2 StreamingHttpService (io.servicetalk.http.api.StreamingHttpService)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)1 ChannelPromise (io.netty.channel.ChannelPromise)1 DEFAULT_ALLOCATOR (io.servicetalk.buffer.netty.BufferAllocators.DEFAULT_ALLOCATOR)1 Executor (io.servicetalk.concurrent.api.Executor)1 ExecutorExtension (io.servicetalk.concurrent.api.ExecutorExtension)1 Publisher.from (io.servicetalk.concurrent.api.Publisher.from)1 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)1 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)1 DefaultHttpHeadersFactory (io.servicetalk.http.api.DefaultHttpHeadersFactory)1 FilterableStreamingHttpConnection (io.servicetalk.http.api.FilterableStreamingHttpConnection)1 HttpConnectionContext (io.servicetalk.http.api.HttpConnectionContext)1 HttpExecutionStrategies.customStrategyBuilder (io.servicetalk.http.api.HttpExecutionStrategies.customStrategyBuilder)1 HttpExecutionStrategies.defaultStrategy (io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy)1 HttpExecutionStrategies.offloadNever (io.servicetalk.http.api.HttpExecutionStrategies.offloadNever)1 HttpExecutionStrategy (io.servicetalk.http.api.HttpExecutionStrategy)1