This is an automated email from the ASF dual-hosted git repository. tanxinyu pushed a commit to branch add_compression_wal_test in repository https://gitbox.apache.org/repos/asf/tsfile.git
commit eaae57bfce4d44fa21d711e24b720368d33886a6 Author: OneSizeFitQuorum <[email protected]> AuthorDate: Mon Jul 1 11:02:45 2024 +0800 enhance test for direct buffer Signed-off-by: OneSizeFitQuorum <[email protected]> --- .../java/org/apache/tsfile/compress/LZ4Test.java | 27 ++++++++++++++++++++++ .../java/org/apache/tsfile/compress/LZMA2Test.java | 2 +- .../java/org/apache/tsfile/compress/ZstdTest.java | 2 +- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/java/tsfile/src/test/java/org/apache/tsfile/compress/LZ4Test.java b/java/tsfile/src/test/java/org/apache/tsfile/compress/LZ4Test.java index 299c70f7..e57cf4af 100644 --- a/java/tsfile/src/test/java/org/apache/tsfile/compress/LZ4Test.java +++ b/java/tsfile/src/test/java/org/apache/tsfile/compress/LZ4Test.java @@ -18,9 +18,11 @@ */ package org.apache.tsfile.compress; +import java.nio.ByteBuffer; import org.apache.tsfile.compress.ICompressor.LZ4Compressor; import org.apache.tsfile.compress.IUnCompressor.LZ4UnCompressor; +import org.apache.tsfile.utils.ReadWriteIOUtils; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -101,4 +103,29 @@ public class LZ4Test { unCompressor.uncompress(compressed, offset, compressedLength, uncompressed, 0); Assert.assertArrayEquals(origin, uncompressed); } + + @Test + public void testByteBuffer() throws IOException { + for (int i = 1; i < 500000; i += 100000) { + String input = randomString(i); + ByteBuffer source = ByteBuffer.allocateDirect(input.getBytes().length); + source.put(input.getBytes()); + source.flip(); + + ICompressor.LZ4Compressor compressor = new ICompressor.LZ4Compressor(); + ByteBuffer compressed = + ByteBuffer.allocateDirect(Math.max(source.remaining() * 3 + 1, 28 + source.remaining())); + compressor.compress(source, compressed); + + IUnCompressor.LZ4UnCompressor unCompressor = new IUnCompressor.LZ4UnCompressor(); + ByteBuffer uncompressedByteBuffer = + ByteBuffer.allocateDirect(compressed.remaining() + 28 * 2); + compressed.flip(); + unCompressor.uncompress(compressed, uncompressedByteBuffer); + + uncompressedByteBuffer.flip(); + String afterDecode = ReadWriteIOUtils.readStringFromDirectByteBuffer(uncompressedByteBuffer); + assert input.equals(afterDecode); + } + } } diff --git a/java/tsfile/src/test/java/org/apache/tsfile/compress/LZMA2Test.java b/java/tsfile/src/test/java/org/apache/tsfile/compress/LZMA2Test.java index 36aaf367..ff7188ef 100644 --- a/java/tsfile/src/test/java/org/apache/tsfile/compress/LZMA2Test.java +++ b/java/tsfile/src/test/java/org/apache/tsfile/compress/LZMA2Test.java @@ -80,7 +80,7 @@ public class LZMA2Test { } @Test - public void testBytes3() throws IOException { + public void testByteBuffer() throws IOException { for (int i = 0; i < 500; i += 1) { String input = randomString(i); ByteBuffer source = ByteBuffer.allocateDirect(input.getBytes().length); diff --git a/java/tsfile/src/test/java/org/apache/tsfile/compress/ZstdTest.java b/java/tsfile/src/test/java/org/apache/tsfile/compress/ZstdTest.java index 5c5c7050..be62620b 100644 --- a/java/tsfile/src/test/java/org/apache/tsfile/compress/ZstdTest.java +++ b/java/tsfile/src/test/java/org/apache/tsfile/compress/ZstdTest.java @@ -48,7 +48,7 @@ public class ZstdTest { public void tearDown() {} @Test - public void testBytes1() throws IOException { + public void testBytebuffer() throws IOException { for (int i = 1; i < 500000; i += 100000) { String input = randomString(i); ByteBuffer source = ByteBuffer.allocateDirect(input.getBytes().length);
