This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch iotdb in repository https://gitbox.apache.org/repos/asf/tsfile.git
commit eb74c0a9b24e58ac8a685ea2a8a267f7881eafc9 Author: Potato <[email protected]> AuthorDate: Fri Jul 5 18:53:12 2024 +0800 enhance test for direct buffer (#146) 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..761699bc 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 @@ -20,6 +20,7 @@ package org.apache.tsfile.compress; 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; @@ -27,6 +28,7 @@ import org.junit.Before; import org.junit.Test; import java.io.IOException; +import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.concurrent.ThreadLocalRandom; @@ -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 803de712..dd0e6c17 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);
