use of org.apache.pulsar.common.compression.CompressionCodec in project incubator-pulsar by apache.
the class CompressorCodecTest method testCompressDecompress.
@Test(dataProvider = "codec")
void testCompressDecompress(CompressionType type) throws IOException {
CompressionCodec codec = CompressionCodecProvider.getCompressionCodec(type);
byte[] data = text.getBytes();
ByteBuf raw = PooledByteBufAllocator.DEFAULT.buffer();
raw.writeBytes(data);
ByteBuf compressed = codec.encode(raw);
assertEquals(raw.readableBytes(), data.length);
int compressedSize = compressed.readableBytes();
ByteBuf uncompressed = codec.decode(compressed, data.length);
assertEquals(compressed.readableBytes(), compressedSize);
assertEquals(uncompressed.readableBytes(), data.length);
assertEquals(uncompressed, raw);
raw.release();
compressed.release();
uncompressed.release();
// Verify compression codecs have the same behavior with buffers ref counting
assertEquals(raw.refCnt(), 0);
assertEquals(compressed.refCnt(), 0);
assertEquals(compressed.refCnt(), 0);
}
Aggregations