use of io.netty.handler.codec.http2.Http2StreamChannel in project netty by netty.
the class Http2MultiplexTest method failedOutboundStreamCreationThrowsAndClosesChannel.
// Test failing the promise of the first headers frame of an outbound stream. In practice this error case would most
// likely happen due to the max concurrent streams limit being hit or the channel running out of stream identifiers.
//
@Test
public void failedOutboundStreamCreationThrowsAndClosesChannel() throws Exception {
LastInboundHandler handler = new LastInboundHandler();
Http2StreamChannel childChannel = newOutboundStream(handler);
assertTrue(childChannel.isActive());
Http2Headers headers = new DefaultHttp2Headers();
when(frameWriter.writeHeaders(eqCodecCtx(), anyInt(), eq(headers), anyInt(), anyBoolean(), any(ChannelPromise.class))).thenAnswer(new Answer<ChannelFuture>() {
@Override
public ChannelFuture answer(InvocationOnMock invocationOnMock) {
return ((ChannelPromise) invocationOnMock.getArgument(5)).setFailure(new Http2NoMoreStreamIdsException());
}
});
final ChannelFuture future = childChannel.writeAndFlush(new DefaultHttp2HeadersFrame(headers));
parentChannel.flush();
assertFalse(childChannel.isActive());
assertFalse(childChannel.isOpen());
handler.checkException();
assertThrows(Http2NoMoreStreamIdsException.class, new Executable() {
@Override
public void execute() {
future.syncUninterruptibly();
}
});
}
use of io.netty.handler.codec.http2.Http2StreamChannel in project netty by netty.
the class Http2MultiplexTest method callUnsafeCloseMultipleTimes.
@Test
public void callUnsafeCloseMultipleTimes() {
LastInboundHandler inboundHandler = new LastInboundHandler();
Http2StreamChannel childChannel = newInboundStream(3, false, inboundHandler);
childChannel.unsafe().close(childChannel.voidPromise());
ChannelPromise promise = childChannel.newPromise();
childChannel.unsafe().close(promise);
promise.syncUninterruptibly();
childChannel.closeFuture().syncUninterruptibly();
}
use of io.netty.handler.codec.http2.Http2StreamChannel in project netty by netty.
the class Http2MultiplexTest method channelClosedWhenInactiveFired.
@Test
public void channelClosedWhenInactiveFired() {
LastInboundHandler inboundHandler = new LastInboundHandler();
Http2StreamChannel childChannel = newInboundStream(3, false, inboundHandler);
final AtomicBoolean channelOpen = new AtomicBoolean(false);
final AtomicBoolean channelActive = new AtomicBoolean(false);
assertTrue(childChannel.isOpen());
assertTrue(childChannel.isActive());
childChannel.pipeline().addLast(new ChannelInboundHandlerAdapter() {
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
channelOpen.set(ctx.channel().isOpen());
channelActive.set(ctx.channel().isActive());
super.channelInactive(ctx);
}
});
childChannel.close().syncUninterruptibly();
assertFalse(channelOpen.get());
assertFalse(channelActive.get());
}
use of io.netty.handler.codec.http2.Http2StreamChannel in project netty by netty.
the class Http2MultiplexTest method channelReadShouldRespectAutoReadAndNotProduceNPE.
@Test
public void channelReadShouldRespectAutoReadAndNotProduceNPE() throws Exception {
LastInboundHandler inboundHandler = new LastInboundHandler();
Http2StreamChannel childChannel = newInboundStream(3, false, inboundHandler);
assertTrue(childChannel.config().isAutoRead());
Http2HeadersFrame headersFrame = inboundHandler.readInbound();
assertNotNull(headersFrame);
childChannel.config().setAutoRead(false);
childChannel.pipeline().addFirst(new ChannelInboundHandlerAdapter() {
private int count;
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
ctx.fireChannelRead(msg);
// Close channel after 2 reads so there is still something in the inboundBuffer when the close happens.
if (++count == 2) {
ctx.close();
}
}
});
frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("hello world"), 0, false);
Http2DataFrame dataFrame0 = inboundHandler.readInbound();
assertNotNull(dataFrame0);
release(dataFrame0);
frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("foo"), 0, false);
frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("bar"), 0, false);
frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("bar"), 0, false);
assertNull(inboundHandler.readInbound());
childChannel.config().setAutoRead(true);
verifyFramesMultiplexedToCorrectChannel(childChannel, inboundHandler, 3);
inboundHandler.checkException();
}
use of io.netty.handler.codec.http2.Http2StreamChannel in project rest.li by linkedin.
the class Http2ChannelLifecycle method doBootstrapStreamChannel.
/**
* Bootstraps the stream channel from the given parent channel. Returns the stream channel
* through the success callback if bootstrap succeeds; Return the cause if an exception occurs.
* @param channel Parent channel to bootstrap the stream channel from.
* @param callback Callback of the stream channel bootstrap.
*/
private void doBootstrapStreamChannel(Channel channel, Callback<Channel> callback) {
final Http2StreamChannelBootstrap bootstrap = new Http2StreamChannelBootstrap(channel).handler(new Http2StreamChannelInitializer(_ssl, _maxContentLength));
bootstrap.open().addListener(future -> {
if (future.isSuccess()) {
synchronized (_lock) {
_childChannelCount++;
}
callback.onSuccess((Http2StreamChannel) future.get());
} else {
channel.close();
callback.onError(future.cause());
}
});
}
Aggregations