Search in sources :

Example 6 with CompressionCodec

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);
}
Also used : CompressionCodec(org.apache.pulsar.common.compression.CompressionCodec) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Aggregations

CompressionCodec (org.apache.pulsar.common.compression.CompressionCodec)6 ByteBuf (io.netty.buffer.ByteBuf)5 Test (org.testng.annotations.Test)4 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)1 ExecutionException (java.util.concurrent.ExecutionException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 Entry (org.apache.bookkeeper.mledger.Entry)1 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)1 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)1 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)1 NotAllowedException (org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException)1 SubscriptionBusyException (org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)1 TopicBusyException (org.apache.pulsar.broker.service.BrokerServiceException.TopicBusyException)1 PersistentReplicator (org.apache.pulsar.broker.service.persistent.PersistentReplicator)1 PersistentSubscription (org.apache.pulsar.broker.service.persistent.PersistentSubscription)1 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)1 RestException (org.apache.pulsar.broker.web.RestException)1