Lz4FrameEncoderTest Class — netty Architecture
Architecture documentation for the Lz4FrameEncoderTest class in Lz4FrameEncoderTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 16452743_407c_c5f6_ee9f_baa8b84020f0["Lz4FrameEncoderTest"] 092e61b4_366e_ac12_dcb3_469a03923a65["Lz4FrameEncoderTest.java"] 16452743_407c_c5f6_ee9f_baa8b84020f0 -->|defined in| 092e61b4_366e_ac12_dcb3_469a03923a65 476d3f42_0170_0f67_27f0_ef428f2c057e["setup()"] 16452743_407c_c5f6_ee9f_baa8b84020f0 -->|method| 476d3f42_0170_0f67_27f0_ef428f2c057e b40abe87_4a28_e9da_fe39_82d9b1130383["EmbeddedChannel()"] 16452743_407c_c5f6_ee9f_baa8b84020f0 -->|method| b40abe87_4a28_e9da_fe39_82d9b1130383 34882e29_3b67_8b89_1398_3d552d7b42b6["ByteBuf()"] 16452743_407c_c5f6_ee9f_baa8b84020f0 -->|method| 34882e29_3b67_8b89_1398_3d552d7b42b6 5d65cf45_9814_95d1_0f8d_2f37ba79bf9a["testAllocateDirectBuffer()"] 16452743_407c_c5f6_ee9f_baa8b84020f0 -->|method| 5d65cf45_9814_95d1_0f8d_2f37ba79bf9a 3cfcf416_57c5_d367_ed41_452b08c2c77c["testAllocateHeapBuffer()"] 16452743_407c_c5f6_ee9f_baa8b84020f0 -->|method| 3cfcf416_57c5_d367_ed41_452b08c2c77c d53150d4_a5fb_32f4_fc51_9c98d577a401["testAllocateBuffer()"] 16452743_407c_c5f6_ee9f_baa8b84020f0 -->|method| d53150d4_a5fb_32f4_fc51_9c98d577a401 9756b24f_36da_e290_f4c0_d428dc7cacb5["testAllocateDirectBufferExceedMaxEncodeSize()"] 16452743_407c_c5f6_ee9f_baa8b84020f0 -->|method| 9756b24f_36da_e290_f4c0_d428dc7cacb5 6111e409_d85d_a017_6935_7ac7b5d5a337["Lz4FrameEncoder()"] 16452743_407c_c5f6_ee9f_baa8b84020f0 -->|method| 6111e409_d85d_a017_6935_7ac7b5d5a337 d7a1ea84_8c61_5cb6_8338_ce1f96e8ed0c["testAllocateOnHeapBufferOverflowsOutputSize()"] 16452743_407c_c5f6_ee9f_baa8b84020f0 -->|method| d7a1ea84_8c61_5cb6_8338_ce1f96e8ed0c 41d698aa_a735_854e_8f80_b01f96ea35b4["testFlush()"] 16452743_407c_c5f6_ee9f_baa8b84020f0 -->|method| 41d698aa_a735_854e_8f80_b01f96ea35b4 c572c687_c6c6_1cb6_34b9_7036673c2154["testAllocatingAroundBlockSize()"] 16452743_407c_c5f6_ee9f_baa8b84020f0 -->|method| c572c687_c6c6_1cb6_34b9_7036673c2154 1ffe5b69_82b0_1fff_8694_98cfb8688d7e["writingAfterClosedChannelDoesNotNPE()"] 16452743_407c_c5f6_ee9f_baa8b84020f0 -->|method| 1ffe5b69_82b0_1fff_8694_98cfb8688d7e
Relationship Graph
Source Code
codec-compression/src/test/java/io/netty/handler/codec/compression/Lz4FrameEncoderTest.java lines 60–307
public class Lz4FrameEncoderTest extends AbstractEncoderTest {
/**
* For the purposes of this test, if we pass this (very small) size of buffer into
* {@link Lz4FrameEncoder#allocateBuffer(ChannelHandlerContext, ByteBuf, boolean)}, we should get back
* an empty buffer.
*/
private static final int NONALLOCATABLE_SIZE = 1;
@Mock
private ChannelHandlerContext ctx;
/**
* A {@link ByteBuf} for mocking purposes, largely because it's difficult to allocate to huge buffers.
*/
@Mock
private ByteBuf buffer;
@BeforeEach
public void setup() {
MockitoAnnotations.initMocks(this);
when(ctx.alloc()).thenReturn(ByteBufAllocator.DEFAULT);
}
@Override
protected EmbeddedChannel createChannel() {
return new EmbeddedChannel(new Lz4FrameEncoder());
}
@Override
protected ByteBuf decompress(ByteBuf compressed, int originalLength) throws Exception {
byte[] decompressed = new byte[originalLength];
try (LZ4BlockInputStream lz4Is = new LZ4BlockInputStream(new ByteBufInputStream(compressed, true))) {
int remaining = originalLength;
while (remaining > 0) {
int read = lz4Is.read(decompressed, originalLength - remaining, remaining);
if (read > 0) {
remaining -= read;
} else {
break;
}
}
assertEquals(-1, lz4Is.read());
}
return Unpooled.wrappedBuffer(decompressed);
}
@Test
public void testAllocateDirectBuffer() {
final int blockSize = 100;
testAllocateBuffer(blockSize, blockSize - 13, true);
testAllocateBuffer(blockSize, blockSize * 5, true);
testAllocateBuffer(blockSize, NONALLOCATABLE_SIZE, true);
}
@Test
public void testAllocateHeapBuffer() {
final int blockSize = 100;
testAllocateBuffer(blockSize, blockSize - 13, false);
testAllocateBuffer(blockSize, blockSize * 5, false);
testAllocateBuffer(blockSize, NONALLOCATABLE_SIZE, false);
}
private void testAllocateBuffer(int blockSize, int bufSize, boolean preferDirect) {
// allocate the input buffer to an arbitrary size less than the blockSize
ByteBuf in = ByteBufAllocator.DEFAULT.buffer(bufSize, bufSize);
in.writerIndex(in.capacity());
ByteBuf out = null;
try {
Lz4FrameEncoder encoder = newEncoder(blockSize, Lz4FrameEncoder.DEFAULT_MAX_ENCODE_SIZE);
out = encoder.allocateBuffer(ctx, in, preferDirect);
assertNotNull(out);
if (NONALLOCATABLE_SIZE == bufSize) {
assertFalse(out.isWritable());
} else {
assertTrue(out.writableBytes() > 0);
if (!preferDirect) {
// Only check if preferDirect is not true as if a direct buffer is returned or not depends on
// if sun.misc.Unsafe is present.
assertFalse(out.isDirect());
Defined In
Source
Frequently Asked Questions
What is the Lz4FrameEncoderTest class?
Lz4FrameEncoderTest is a class in the netty codebase, defined in codec-compression/src/test/java/io/netty/handler/codec/compression/Lz4FrameEncoderTest.java.
Where is Lz4FrameEncoderTest defined?
Lz4FrameEncoderTest is defined in codec-compression/src/test/java/io/netty/handler/codec/compression/Lz4FrameEncoderTest.java at line 60.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free