From 7119f103c67a7c17e2847a9c66a646e5c497b3c2 Mon Sep 17 00:00:00 2001 From: Matteo Merli Date: Wed, 12 Feb 2020 11:09:12 -0800 Subject: [PATCH] Ensure direct bytebuf for both compression and decompression test --- .../CompressorCodecBackwardCompatTest.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pulsar-common/src/test/java/org/apache/pulsar/common/compression/CompressorCodecBackwardCompatTest.java b/pulsar-common/src/test/java/org/apache/pulsar/common/compression/CompressorCodecBackwardCompatTest.java index ffc38900b2296..77ed8e9bfa091 100644 --- a/pulsar-common/src/test/java/org/apache/pulsar/common/compression/CompressorCodecBackwardCompatTest.java +++ b/pulsar-common/src/test/java/org/apache/pulsar/common/compression/CompressorCodecBackwardCompatTest.java @@ -25,6 +25,7 @@ import java.io.IOException; +import org.apache.pulsar.common.allocator.PulsarByteBufAllocator; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -50,7 +51,7 @@ public Object[][] codecProvider() { @Test(dataProvider = "codecs") void testCompressDecompress(CompressionCodec c1, CompressionCodec c2) throws IOException { byte[] data = text.getBytes(); - ByteBuf raw = Unpooled.directBuffer(); + ByteBuf raw = PulsarByteBufAllocator.DEFAULT.directBuffer(); raw.writeBytes(data); ByteBuf compressed = c1.encode(raw); @@ -58,9 +59,13 @@ void testCompressDecompress(CompressionCodec c1, CompressionCodec c2) throws IOE int compressedSize = compressed.readableBytes(); - ByteBuf uncompressed = c2.decode(compressed, data.length); + // Copy into a direct byte buf + ByteBuf compressedDirect = PulsarByteBufAllocator.DEFAULT.directBuffer(); + compressedDirect.writeBytes(compressed); - assertEquals(compressed.readableBytes(), compressedSize); + ByteBuf uncompressed = c2.decode(compressedDirect, data.length); + + assertEquals(compressedDirect.readableBytes(), compressedSize); assertEquals(uncompressed.readableBytes(), data.length); assertEquals(uncompressed, raw); @@ -68,10 +73,11 @@ void testCompressDecompress(CompressionCodec c1, CompressionCodec c2) throws IOE raw.release(); compressed.release(); uncompressed.release(); + compressedDirect.release(); // Verify compression codecs have the same behavior with buffers ref counting assertEquals(raw.refCnt(), 0); - assertEquals(compressed.refCnt(), 0); - assertEquals(compressed.refCnt(), 0); + assertEquals(compressedDirect.refCnt(), 0); + assertEquals(compressedDirect.refCnt(), 0); } }