Lz4FrameEncoder extends MessageToByteEncoder<ByteBuf> { @Override protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) { return allocateBuffer(ctx, msg, preferDirect, true); } Lz4FrameEncoder();  Lz4FrameEncoder(boolean highCompressor);  Lz4FrameEncoder(LZ4Factory factory, boolean highCompressor, int blockSize, Checksum checksum);  Lz4FrameEncoder(LZ4Factory factory, boolean highCompressor, int blockSize,
                           Checksum checksum, int maxEncodeSize); @Override void flush(final ChannelHandlerContext ctx); boolean isClosed(); ChannelFuture close(); ChannelFuture close(final ChannelPromise promise); @Override void close(final ChannelHandlerContext ctx, final ChannelPromise promise); @Override void handlerAdded(ChannelHandlerContext ctx); @Override void handlerRemoved(ChannelHandlerContext ctx);  }
@Test (expected = EncoderException.class) public void testAllocateDirectBufferExceedMaxEncodeSize() { final int maxEncodeSize = 1024; Lz4FrameEncoder encoder = newEncoder(Lz4Constants.DEFAULT_BLOCK_SIZE, maxEncodeSize); int inputBufferSize = maxEncodeSize * 10; ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(inputBufferSize, inputBufferSize); try { buf.writerIndex(inputBufferSize); encoder.allocateBuffer(ctx, buf, false); } finally { buf.release(); } }
@Test (expected = EncoderException.class) public void testAllocateOnHeapBufferOverflowsOutputSize() { final int maxEncodeSize = Integer.MAX_VALUE; Lz4FrameEncoder encoder = newEncoder(Lz4Constants.DEFAULT_BLOCK_SIZE, maxEncodeSize); when(buffer.readableBytes()).thenReturn(maxEncodeSize); buffer.writerIndex(maxEncodeSize); encoder.allocateBuffer(ctx, buffer, false); }