public static void compressAndDecompressNativeTest(BaseCompression compression, String testMessage,
      int bufferLeftPadSize, int bufferRightPadSize) throws CompressionException {
    // Apply compression to testMessage.
    // compressedBuffer consists of bytes[bufferLeftPadSize] + bytes[actualCompressedSize]
    // + bytes[compressUnusedSpace] + bytes[bufferRightPadSize]
    ByteBuffer sourceBuffer = ByteBuffer.wrap(testMessage.getBytes(StandardCharsets.UTF_8));
    int sourceBufferSize = sourceBuffer.remaining();

    int compressedBufferSize = compression.estimateMaxCompressedDataSize(sourceBufferSize);
    ByteBuffer compressedBuffer = ByteBuffer.wrap(new byte[bufferLeftPadSize + compressedBufferSize + bufferRightPadSize]);
    int actualCompressedSize = compression.compressNative(sourceBuffer, 0, sourceBufferSize,
        compressedBuffer, bufferLeftPadSize, compressedBufferSize);
    Assert.assertTrue(actualCompressedSize > 0);

    // Apply decompression.
    // compressedBuffer has bytes[bufferLeftPadSize] + bytes[actualCompressedSize] + bytes[bufferRightPadSize]
    // decompressedBuffer contains bytes[bufferLeftPadSize] + bytes[sourceBufferSize] + bytes[bufferRightPadSize]
    ByteBuffer decompressedBuffer = ByteBuffer.wrap(new byte[bufferLeftPadSize + sourceBufferSize + bufferRightPadSize]);
    compression.decompressNative(compressedBuffer, bufferLeftPadSize, actualCompressedSize,
        decompressedBuffer, bufferLeftPadSize, sourceBufferSize);

    String decompressedMessage = new String(decompressedBuffer.array(), bufferLeftPadSize, sourceBufferSize,
        StandardCharsets.UTF_8);
    Assert.assertEquals(testMessage, decompressedMessage);
  }
Test compression using compressNative() and decompressNative() APIs.
It does not use the structural formatting introduced by compress().
ambry-commons/src/test/java/com/github/ambry/compression/LZ4CompressionTest.java