summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/test/java/com/yahoo/compress/ZstdCompressorTest.java15
-rw-r--r--vespajlib/src/test/java/com/yahoo/compress/ZstdOuputStreamTest.java18
2 files changed, 33 insertions, 0 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/compress/ZstdCompressorTest.java b/vespajlib/src/test/java/com/yahoo/compress/ZstdCompressorTest.java
index 146199dc860..f38ce4ad953 100644
--- a/vespajlib/src/test/java/com/yahoo/compress/ZstdCompressorTest.java
+++ b/vespajlib/src/test/java/com/yahoo/compress/ZstdCompressorTest.java
@@ -4,6 +4,7 @@ package com.yahoo.compress;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author bjorncs
@@ -19,4 +20,18 @@ class ZstdCompressorTest {
assertArrayEquals(inputData, decompressedData);
}
+ @Test
+ void compressed_size_is_less_than_uncompressed() {
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < 100; i++) {
+ builder.append("The quick brown fox jumps over the lazy dog").append('\n');
+ }
+ byte[] inputData = builder.toString().getBytes();
+ ZstdCompressor compressor = new ZstdCompressor();
+ byte[] compressedData = compressor.compress(inputData, 0, inputData.length);
+ assertTrue(
+ compressedData.length < inputData.length,
+ () -> "Compressed size is " + compressedData.length + " while uncompressed size is " + inputData.length);
+ }
+
}
diff --git a/vespajlib/src/test/java/com/yahoo/compress/ZstdOuputStreamTest.java b/vespajlib/src/test/java/com/yahoo/compress/ZstdOuputStreamTest.java
index 99e3130f3a3..5d35eb10215 100644
--- a/vespajlib/src/test/java/com/yahoo/compress/ZstdOuputStreamTest.java
+++ b/vespajlib/src/test/java/com/yahoo/compress/ZstdOuputStreamTest.java
@@ -7,6 +7,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author bjorncs
@@ -27,4 +28,21 @@ class ZstdOuputStreamTest {
compressor.decompress(compressedData, 0, compressedData.length, decompressedData, 0, decompressedData.length);
assertArrayEquals(inputData, decompressedData);
}
+
+ @Test
+ void compressed_size_is_less_than_uncompressed() throws IOException {
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < 100; i++) {
+ builder.append("The quick brown fox jumps over the lazy dog").append('\n');
+ }
+ byte[] inputData = builder.toString().getBytes();
+ ByteArrayOutputStream arrayOut = new ByteArrayOutputStream();
+ try (ZstdOuputStream zstdOut = new ZstdOuputStream(arrayOut)) {
+ zstdOut.write(inputData);
+ }
+ int compressedSize = arrayOut.toByteArray().length;
+ assertTrue(
+ compressedSize < inputData.length,
+ () -> "Compressed size is " + compressedSize + " while uncompressed size is " + inputData.length);
+ }
}