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

Code before:
 */
package io.netty.handler.codec.compression;

import com.github.luben.zstd.ZstdInputStream;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedChannel;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

public class ZstdEncoderTest extends AbstractEncoderTest {

    @Mock
    private ChannelHandlerContext ctx;

    protected static final byte[] BYTES_HUGE = new byte[256 * 1024 * 1024];

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

    public static ByteBuf[] hugeData() {
        ByteBuf heap = Unpooled.wrappedBuffer(BYTES_HUGE);
        ByteBuf direct = Unpooled.directBuffer(BYTES_HUGE.length);
        direct.writeBytes(BYTES_HUGE);
        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);
    }


Review comment (suggestion):
I think it would be better to just allocate this in `hugeData` so it can be GC'ed once the test completes. 

Code after:
 */
package io.netty.handler.codec.compression;

import com.github.luben.zstd.ZstdInputStream;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedChannel;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

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