Skip to content

Commit 45136e6

Browse files
committed
Add unit test
1 parent 54c4c3c commit 45136e6

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,42 @@ public void channelReadShouldRespectAutoRead() {
303303
verifyFramesMultiplexedToCorrectChannel(childChannel, inboundHandler, 2);
304304
}
305305

306+
@Test
307+
public void channelReadShouldRespectAutoReadAndNotProduceNPE() throws Exception {
308+
LastInboundHandler inboundHandler = new LastInboundHandler();
309+
Http2StreamChannel childChannel = newInboundStream(3, false, inboundHandler);
310+
assertTrue(childChannel.config().isAutoRead());
311+
Http2HeadersFrame headersFrame = inboundHandler.readInbound();
312+
assertNotNull(headersFrame);
313+
314+
childChannel.config().setAutoRead(false);
315+
childChannel.pipeline().addFirst(new ChannelInboundHandlerAdapter() {
316+
private int count;
317+
@Override
318+
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
319+
ctx.fireChannelRead(msg);
320+
// Close channel after 2 reads so there is still something in the inboundBuffer when the close happens.
321+
if (++count == 2) {
322+
ctx.close();
323+
}
324+
}
325+
});
326+
frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("hello world"), 0, false);
327+
Http2DataFrame dataFrame0 = inboundHandler.readInbound();
328+
assertNotNull(dataFrame0);
329+
release(dataFrame0);
330+
331+
frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("foo"), 0, false);
332+
frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("bar"), 0, false);
333+
frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("bar"), 0, false);
334+
335+
assertNull(inboundHandler.readInbound());
336+
337+
childChannel.config().setAutoRead(true);
338+
verifyFramesMultiplexedToCorrectChannel(childChannel, inboundHandler, 3);
339+
inboundHandler.checkException();
340+
}
341+
306342
@Test
307343
public void readInChannelReadWithoutAutoRead() {
308344
useReadWithoutAutoRead(false);

0 commit comments

Comments
 (0)