Search in sources :

Example 1 with MulticastTransportEventsStreamingHttpConnectionFilter

use of io.servicetalk.http.netty.StreamObserverTest.MulticastTransportEventsStreamingHttpConnectionFilter in project servicetalk by apple.

the class H2ConcurrencyControllerTest method setUp.

@BeforeEach
void setUp() throws Exception {
    serverEventLoopGroup = createIoExecutor(1, "server-io").eventLoopGroup();
    for (int i = 0; i < N_ITERATIONS; i++) {
        latches[i] = new CountDownLatch(1);
    }
    AtomicBoolean secondAndMore = new AtomicBoolean();
    serverAcceptorChannel = bindH2Server(serverEventLoopGroup, new ChannelInitializer<Http2StreamChannel>() {

        @Override
        protected void initChannel(Http2StreamChannel ch) {
            // Respond only for the first request which is used to propagate MAX_CONCURRENT_STREAMS_VALUE
            if (secondAndMore.compareAndSet(false, true)) {
                ch.pipeline().addLast(new EchoHttp2Handler());
            } else {
                // Do not respond to any subsequent requests, only release the associated latch to notify the client
                // that server received the request.
                ch.pipeline().addLast(new SimpleChannelInboundHandler<Http2HeadersFrame>() {

                    @Override
                    protected void channelRead0(final ChannelHandlerContext ctx, final Http2HeadersFrame msg) {
                        String path = msg.headers().path().toString();
                        int i = parseInt(path.substring(1));
                        latches[i].countDown();
                    }
                });
            }
        }
    }, parentPipeline -> {
    }, h2Builder -> {
        h2Builder.initialSettings().maxConcurrentStreams(MAX_CONCURRENT_STREAMS_VALUE);
        return h2Builder;
    });
    final HostAndPort serverAddress = of((InetSocketAddress) serverAcceptorChannel.localAddress());
    client = forResolvedAddress(serverAddress).ioExecutor(CTX.ioExecutor()).executor(CTX.executor()).executionStrategy(defaultStrategy()).appendClientFilter(// All exceptions should be propagated
    disableAutoRetries()).appendConnectionFilter(MulticastTransportEventsStreamingHttpConnectionFilter::new).appendConnectionFilter(connection -> new StreamingHttpConnectionFilter(connection) {

        @Override
        public Single<StreamingHttpResponse> request(StreamingHttpRequest request) {
            return delegate().request(request).liftSync(subscriber -> new SingleSource.Subscriber<StreamingHttpResponse>() {

                @Override
                public void onSubscribe(final Cancellable cancellable) {
                    // Defer the cancel() signal to let the test thread start a new request
                    subscriber.onSubscribe(() -> CTX.executor().schedule(cancellable::cancel, ofMillis(100)));
                }

                @Override
                public void onSuccess(@Nullable final StreamingHttpResponse result) {
                    subscriber.onSuccess(result);
                }

                @Override
                public void onError(final Throwable t) {
                    subscriber.onError(t);
                }
            });
        }
    }).protocols(h2().enableFrameLogging("servicetalk-tests-h2-frame-logger", TRACE, () -> true).build()).build();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) StreamObserverTest.safeSync(io.servicetalk.http.netty.StreamObserverTest.safeSync) TRACE(io.servicetalk.logging.api.LogLevel.TRACE) SingleSource(io.servicetalk.concurrent.SingleSource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Cancellable(io.servicetalk.concurrent.Cancellable) MulticastTransportEventsStreamingHttpConnectionFilter(io.servicetalk.http.netty.StreamObserverTest.MulticastTransportEventsStreamingHttpConnectionFilter) MAX_CONCURRENCY(io.servicetalk.http.api.HttpEventKey.MAX_CONCURRENCY) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpExecutionStrategies.defaultStrategy(io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy) HostAndPort.of(io.servicetalk.transport.api.HostAndPort.of) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) EchoHttp2Handler(io.servicetalk.http.netty.H2PriorKnowledgeFeatureParityTest.EchoHttp2Handler) HttpClient(io.servicetalk.http.api.HttpClient) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ReservedHttpConnection(io.servicetalk.http.api.ReservedHttpConnection) Nullable(javax.annotation.Nullable) HttpProtocolConfigs.h2(io.servicetalk.http.netty.HttpProtocolConfigs.h2) Matchers.empty(org.hamcrest.Matchers.empty) EventLoopGroup(io.netty.channel.EventLoopGroup) ChannelInitializer(io.netty.channel.ChannelInitializer) NettyIoExecutors.createIoExecutor(io.servicetalk.transport.netty.internal.NettyIoExecutors.createIoExecutor) Single(io.servicetalk.concurrent.api.Single) HttpResponse(io.servicetalk.http.api.HttpResponse) ExecutionContextExtension(io.servicetalk.transport.netty.internal.ExecutionContextExtension) BlockingQueue(java.util.concurrent.BlockingQueue) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) StreamingHttpConnectionFilter(io.servicetalk.http.api.StreamingHttpConnectionFilter) OK(io.servicetalk.http.api.HttpResponseStatus.OK) H2PriorKnowledgeFeatureParityTest.bindH2Server(io.servicetalk.http.netty.H2PriorKnowledgeFeatureParityTest.bindH2Server) InetSocketAddress(java.net.InetSocketAddress) Integer.parseInt(java.lang.Integer.parseInt) Http2HeadersFrame(io.netty.handler.codec.http2.Http2HeadersFrame) HttpClients.forResolvedAddress(io.servicetalk.http.netty.HttpClients.forResolvedAddress) Channel(io.netty.channel.Channel) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) AfterEach(org.junit.jupiter.api.AfterEach) HttpsProxyTest.safeClose(io.servicetalk.http.netty.HttpsProxyTest.safeClose) RetryingHttpRequesterFilter.disableAutoRetries(io.servicetalk.http.netty.RetryingHttpRequesterFilter.disableAutoRetries) SimpleChannelInboundHandler(io.netty.channel.SimpleChannelInboundHandler) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) Matchers.is(org.hamcrest.Matchers.is) Http2StreamChannel(io.netty.handler.codec.http2.Http2StreamChannel) Duration.ofMillis(java.time.Duration.ofMillis) HostAndPort(io.servicetalk.transport.api.HostAndPort) Http2HeadersFrame(io.netty.handler.codec.http2.Http2HeadersFrame) SingleSource(io.servicetalk.concurrent.SingleSource) Cancellable(io.servicetalk.concurrent.Cancellable) EchoHttp2Handler(io.servicetalk.http.netty.H2PriorKnowledgeFeatureParityTest.EchoHttp2Handler) MulticastTransportEventsStreamingHttpConnectionFilter(io.servicetalk.http.netty.StreamObserverTest.MulticastTransportEventsStreamingHttpConnectionFilter) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HostAndPort(io.servicetalk.transport.api.HostAndPort) MulticastTransportEventsStreamingHttpConnectionFilter(io.servicetalk.http.netty.StreamObserverTest.MulticastTransportEventsStreamingHttpConnectionFilter) StreamingHttpConnectionFilter(io.servicetalk.http.api.StreamingHttpConnectionFilter) ChannelInitializer(io.netty.channel.ChannelInitializer) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) Http2StreamChannel(io.netty.handler.codec.http2.Http2StreamChannel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Channel (io.netty.channel.Channel)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 SimpleChannelInboundHandler (io.netty.channel.SimpleChannelInboundHandler)1 Http2HeadersFrame (io.netty.handler.codec.http2.Http2HeadersFrame)1 Http2StreamChannel (io.netty.handler.codec.http2.Http2StreamChannel)1 Cancellable (io.servicetalk.concurrent.Cancellable)1 SingleSource (io.servicetalk.concurrent.SingleSource)1 Single (io.servicetalk.concurrent.api.Single)1 HttpClient (io.servicetalk.http.api.HttpClient)1 MAX_CONCURRENCY (io.servicetalk.http.api.HttpEventKey.MAX_CONCURRENCY)1 HttpExecutionStrategies.defaultStrategy (io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy)1 HttpResponse (io.servicetalk.http.api.HttpResponse)1 OK (io.servicetalk.http.api.HttpResponseStatus.OK)1 ReservedHttpConnection (io.servicetalk.http.api.ReservedHttpConnection)1 StreamingHttpConnectionFilter (io.servicetalk.http.api.StreamingHttpConnectionFilter)1 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)1 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)1 EchoHttp2Handler (io.servicetalk.http.netty.H2PriorKnowledgeFeatureParityTest.EchoHttp2Handler)1