private void verifyAndCloseDecoder( TransportFrameDecoder decoder, ChannelHandlerContext ctx, ByteBuf data) throws Exception { try { decoder.channelInactive(ctx); assertTrue("There shouldn't be dangling references to the data.", data.release()); } finally { release(data); } }
private void verifyAndCloseDecoder( TransportFrameDecoder decoder, ChannelHandlerContext ctx, ByteBuf data) throws Exception { try { decoder.channelInactive(ctx); assertTrue("There shouldn't be dangling references to the data.", data.release()); } finally { release(data); } }
@Test public void testSplitLengthField() throws Exception { byte[] frame = new byte[1024 * (RND.nextInt(31) + 1)]; ByteBuf buf = Unpooled.buffer(frame.length + 8); buf.writeLong(frame.length + 8); buf.writeBytes(frame); TransportFrameDecoder decoder = new TransportFrameDecoder(); ChannelHandlerContext ctx = mockChannelHandlerContext(); try { decoder.channelRead(ctx, buf.readSlice(RND.nextInt(7)).retain()); verify(ctx, never()).fireChannelRead(any(ByteBuf.class)); decoder.channelRead(ctx, buf); verify(ctx).fireChannelRead(any(ByteBuf.class)); assertEquals(0, buf.refCnt()); } finally { decoder.channelInactive(ctx); release(buf); } }
@Test public void testSplitLengthField() throws Exception { byte[] frame = new byte[1024 * (RND.nextInt(31) + 1)]; ByteBuf buf = Unpooled.buffer(frame.length + 8); buf.writeLong(frame.length + 8); buf.writeBytes(frame); TransportFrameDecoder decoder = new TransportFrameDecoder(); ChannelHandlerContext ctx = mockChannelHandlerContext(); try { decoder.channelRead(ctx, buf.readSlice(RND.nextInt(7)).retain()); verify(ctx, never()).fireChannelRead(any(ByteBuf.class)); decoder.channelRead(ctx, buf); verify(ctx).fireChannelRead(any(ByteBuf.class)); assertEquals(0, buf.refCnt()); } finally { decoder.channelInactive(ctx); release(buf); } }