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();
}
Aggregations