-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#255 implement decompression from direct buffer to heap buffer
- Loading branch information
1 parent
820038c
commit 5adaab4
Showing
7 changed files
with
162 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-9.29 KB
(97%)
src/main/resources/org/xerial/snappy/native/Linux/x86_64/libsnappyjava.so
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.xerial.snappy; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
|
||
@RunWith(Parameterized.class) | ||
public class SnappyGenerativeTest { | ||
|
||
@Parameterized.Parameters | ||
public static Iterable<Object[]> data() { | ||
List<Object[]> testCases = new ArrayList<>(100); | ||
for (int i = 0 ; i < 100; ++i) { | ||
testCases.add(randomData()); | ||
} | ||
return testCases; | ||
} | ||
|
||
|
||
private final byte[] input; | ||
|
||
public SnappyGenerativeTest(byte[] input) { | ||
this.input = input; | ||
} | ||
|
||
@Test | ||
public void roundTripDirectToDirect() throws IOException { | ||
ByteBuffer in = ByteBuffer.allocateDirect(input.length); | ||
in.put(input); | ||
ByteBuffer compressed = ByteBuffer.allocateDirect(input.length * 2); | ||
Snappy.compress(in, compressed); | ||
Snappy.uncompress(compressed, in); | ||
byte[] result = new byte[input.length]; | ||
in.flip(); | ||
in.get(result); | ||
assertArrayEquals(input, result); | ||
} | ||
|
||
@Test | ||
public void roundTripDirectToHeap() throws IOException { | ||
ByteBuffer in = ByteBuffer.allocateDirect(input.length); | ||
in.put(input); | ||
in.flip(); | ||
ByteBuffer compressed = ByteBuffer.allocateDirect(input.length * 2); | ||
Snappy.compress(in, compressed); | ||
ByteBuffer out = ByteBuffer.allocate(input.length); | ||
Snappy.uncompress(compressed, out); | ||
out.flip(); | ||
assertArrayEquals(input, out.array()); | ||
} | ||
|
||
private static Object[] randomData() { | ||
int length = Math.abs(ThreadLocalRandom.current().nextInt(10,10_000)); | ||
byte[] data = new byte[length]; | ||
ThreadLocalRandom.current().nextBytes(data); | ||
return new Object[] {data}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters