Home / Class/ ZstdEncoderTest Class — netty Architecture

ZstdEncoderTest Class — netty Architecture

Architecture documentation for the ZstdEncoderTest class in ZstdEncoderTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  c729df56_e52a_35d9_ae50_4104aa9af83d["ZstdEncoderTest"]
  80b4e77c_8891_65a8_2699_ab9085c166b4["ZstdEncoderTest.java"]
  c729df56_e52a_35d9_ae50_4104aa9af83d -->|defined in| 80b4e77c_8891_65a8_2699_ab9085c166b4
  83ce515f_3fb7_fcc9_04b2_b734e353e0a2["setup()"]
  c729df56_e52a_35d9_ae50_4104aa9af83d -->|method| 83ce515f_3fb7_fcc9_04b2_b734e353e0a2
  078b8d9c_d979_d4c4_b6a4_12a7272114e2["hugeData()"]
  c729df56_e52a_35d9_ae50_4104aa9af83d -->|method| 078b8d9c_d979_d4c4_b6a4_12a7272114e2
  53a64223_d224_ec28_5c91_4d894e4d605b["EmbeddedChannel()"]
  c729df56_e52a_35d9_ae50_4104aa9af83d -->|method| 53a64223_d224_ec28_5c91_4d894e4d605b
  17681beb_5178_7d26_d32d_adaa60a66fad["testCompressionOfLargeBatchedFlow()"]
  c729df56_e52a_35d9_ae50_4104aa9af83d -->|method| 17681beb_5178_7d26_d32d_adaa60a66fad
  de878df2_aa0c_d891_15d9_15df57372eaf["testCompressionOfHugeBatchedFlow()"]
  c729df56_e52a_35d9_ae50_4104aa9af83d -->|method| de878df2_aa0c_d891_15d9_15df57372eaf
  29ca51d5_6387_64d2_dd4b_ad49a6d7e88d["testCompressionOfLargeDataBatchedFlow()"]
  c729df56_e52a_35d9_ae50_4104aa9af83d -->|method| 29ca51d5_6387_64d2_dd4b_ad49a6d7e88d
  f03d028d_0eb2_3ee1_328d_13f7316f75cb["testCompressionOfSmallBatchedFlow()"]
  c729df56_e52a_35d9_ae50_4104aa9af83d -->|method| f03d028d_0eb2_3ee1_328d_13f7316f75cb
  c6a9f844_60f4_73fd_72a0_b4cba082b69c["testCompressionOfTinyData()"]
  c729df56_e52a_35d9_ae50_4104aa9af83d -->|method| c6a9f844_60f4_73fd_72a0_b4cba082b69c
  b315a9b8_b458_0caf_cc38_65804a77ebf4["ByteBuf()"]
  c729df56_e52a_35d9_ae50_4104aa9af83d -->|method| b315a9b8_b458_0caf_cc38_65804a77ebf4

Relationship Graph

Source Code

codec-compression/src/test/java/io/netty/handler/codec/compression/ZstdEncoderTest.java lines 39–131

public class ZstdEncoderTest extends AbstractEncoderTest {

    @Mock
    private ChannelHandlerContext ctx;

    @BeforeEach
    public void setup() {
        MockitoAnnotations.initMocks(this);
        when(ctx.alloc()).thenReturn(ByteBufAllocator.DEFAULT);
    }

    public static ByteBuf[] hugeData() {
        final byte[] bytesHuge = new byte[36 * 1024 * 1024];
        ByteBuf heap = Unpooled.wrappedBuffer(bytesHuge);
        ByteBuf direct = Unpooled.directBuffer(bytesHuge.length);
        direct.writeBytes(bytesHuge);
        return new ByteBuf[] {heap, direct};
    }

    @Override
    public EmbeddedChannel createChannel() {
        return new EmbeddedChannel(new ZstdEncoder());
    }

    @ParameterizedTest
    @MethodSource("largeData")
    public void testCompressionOfLargeBatchedFlow(final ByteBuf data) throws Exception {
        testCompressionOfLargeDataBatchedFlow(data);
    }

    @ParameterizedTest
    @MethodSource("hugeData")
    public void testCompressionOfHugeBatchedFlow(final ByteBuf data) throws Exception {
        testCompressionOfLargeDataBatchedFlow(data);
    }

    private void testCompressionOfLargeDataBatchedFlow(final ByteBuf data) throws Exception {
        final int dataLength = data.readableBytes();
        int written = 0;

        ByteBuf in = data.retainedSlice(written, 65535);
        assertTrue(channel.writeOutbound(in));

        ByteBuf in2 = data.retainedSlice(65535, dataLength - 65535);
        assertTrue(channel.writeOutbound(in2));

        assertTrue(channel.finish());

        ByteBuf decompressed = readDecompressed(dataLength);
        assertEquals(data, decompressed);

        decompressed.release();
        data.release();
    }

    @ParameterizedTest
    @MethodSource("smallData")
    public void testCompressionOfSmallBatchedFlow(final ByteBuf data) throws Exception {
        testCompressionOfBatchedFlow(data);
    }

    @Test
    public void testCompressionOfTinyData() throws Exception {
        ByteBuf data = Unpooled.copiedBuffer("Hello, World", CharsetUtil.UTF_8);
        assertTrue(channel.writeOutbound(data));
        assertTrue(channel.finish());

        ByteBuf out = channel.readOutbound();
        assertThat(out.readableBytes()).isPositive();
        out.release();
        assertNull(channel.readOutbound());
    }

    @Override
    protected ByteBuf decompress(ByteBuf compressed, int originalLength) throws Exception {
        byte[] decompressed = new byte[originalLength];
        try (ZstdInputStream zstdIs = new ZstdInputStream(new ByteBufInputStream(compressed, true))) {

            int remaining = originalLength;
            while (remaining > 0) {
                int read = zstdIs.read(decompressed, originalLength - remaining, remaining);

Frequently Asked Questions

What is the ZstdEncoderTest class?
ZstdEncoderTest is a class in the netty codebase, defined in codec-compression/src/test/java/io/netty/handler/codec/compression/ZstdEncoderTest.java.
Where is ZstdEncoderTest defined?
ZstdEncoderTest is defined in codec-compression/src/test/java/io/netty/handler/codec/compression/ZstdEncoderTest.java at line 39.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free