Skip to content

Commit

Permalink
enhance test for direct buffer (#146)
Browse files Browse the repository at this point in the history
Signed-off-by: OneSizeFitQuorum <[email protected]>
  • Loading branch information
OneSizeFitsQuorum authored Jul 5, 2024
1 parent 0930795 commit fbd65b7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions java/tsfile/src/test/java/org/apache/tsfile/compress/LZ4Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

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;
import org.junit.Test;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ThreadLocalRandom;

Expand Down Expand Up @@ -101,4 +103,29 @@ public void testBytes3() throws IOException {
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void testBytes2() throws IOException {
}

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void setUp() {}
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);
Expand Down

0 comments on commit fbd65b7

Please sign in to comment.