Repository: netty/netty
File: codec-compression/src/test/java/io/netty/handler/codec/compression/ZstdEncoderTest.java (Java)

Code before:
    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);
    }

    public 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);
    }

    @Override

Review comment (performance):
```suggestion
    private void testCompressionOfLargeDataBatchedFlow(final ByteBuf data) throws Exception {
```

Code after:
    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);
    }

    @Override