diff options
author | Arne Juul <arnej@yahooinc.com> | 2023-01-05 08:37:01 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahooinc.com> | 2023-01-05 08:37:01 +0000 |
commit | 02b035d1812729d16b7126614b03d0025e81f452 (patch) | |
tree | f1193f0f6d74a32425b3bb9d747682b85c18dc01 /airlift-zstd | |
parent | f3054672426ebe077e56c750f1a55bb02e91db5f (diff) |
avoid testng
Diffstat (limited to 'airlift-zstd')
8 files changed, 94 insertions, 135 deletions
diff --git a/airlift-zstd/pom.xml b/airlift-zstd/pom.xml index f1f98abc72b..ded66d0fc6d 100644 --- a/airlift-zstd/pom.xml +++ b/airlift-zstd/pom.xml @@ -21,37 +21,8 @@ <dependencies> <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <version>7.7.1</version> - <scope>test</scope> - </dependency> - - <dependency> - <!-- Bind to slf4j's SimpleLogger --> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - <version>${slf4j.version}</version> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.openjdk.jmh</groupId> - <artifactId>jmh-core</artifactId> - <version>1.36</version> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.openjdk.jmh</groupId> - <artifactId>jmh-generator-annprocess</artifactId> - <version>1.36</version> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> <scope>test</scope> </dependency> @@ -149,7 +120,6 @@ <artifactId>maven-surefire-plugin</artifactId> <configuration> <redirectTestOutputToFile>false</redirectTestOutputToFile> - <forkCount>4</forkCount> <includes> <include>**/TestZstd.java</include> <include>**/TestZstdInputStream.java</include> diff --git a/airlift-zstd/src/test/java/ai/vespa/airlift/compress/AbstractTestCompression.java b/airlift-zstd/src/test/java/ai/vespa/airlift/compress/AbstractTestCompression.java index c8d530bc238..851efdb3580 100644 --- a/airlift-zstd/src/test/java/ai/vespa/airlift/compress/AbstractTestCompression.java +++ b/airlift-zstd/src/test/java/ai/vespa/airlift/compress/AbstractTestCompression.java @@ -15,10 +15,10 @@ package ai.vespa.airlift.compress; import com.google.common.primitives.Bytes; import ai.vespa.airlift.compress.benchmark.DataSet; -import org.testng.SkipException; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import javax.inject.Inject; @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random; +import java.util.stream.Stream; import java.util.concurrent.ThreadLocalRandom; import static com.google.common.base.Preconditions.checkPositionIndexes; @@ -38,13 +39,14 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.catchThrowable; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assumptions.assumeTrue; -@Guice(modules = TestingModule.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public abstract class AbstractTestCompression { - private List<DataSet> testCases; + private List<DataSet> testCases = setup(); protected abstract Compressor getCompressor(); @@ -59,10 +61,8 @@ public abstract class AbstractTestCompression return true; } - @Inject - public void setup(List<DataSet> dataSets) - { - testCases = new ArrayList<>(); + private static List<DataSet> setup() { + List<DataSet> testCases = new ArrayList<>(); testCases.add(new DataSet("nothing", new byte[0])); testCases.add(new DataSet("short literal", "hello world!".getBytes(UTF_8))); @@ -75,10 +75,12 @@ public abstract class AbstractTestCompression } testCases.add(new DataSet("long literal", data)); - testCases.addAll(dataSets); + testCases.addAll(TestingModule.dataSets()); + return testCases; } - @Test(dataProvider = "data") + @ParameterizedTest + @MethodSource("getAllDataSets") public void testDecompress(DataSet dataSet) throws Exception { @@ -100,7 +102,8 @@ public abstract class AbstractTestCompression } // Tests that decompression works correctly when the decompressed data does not span the entire output buffer - @Test(dataProvider = "data") + @ParameterizedTest + @MethodSource("getAllDataSets") public void testDecompressWithOutputPadding(DataSet dataSet) { int padding = 1021; @@ -122,7 +125,8 @@ public abstract class AbstractTestCompression assertByteArraysEqual(uncompressed, padding, uncompressedSize, uncompressedOriginal, 0, uncompressedOriginal.length); } - @Test(dataProvider = "data") + @ParameterizedTest + @MethodSource("getAllDataSets") public void testDecompressionBufferOverrun(DataSet dataSet) { byte[] uncompressedOriginal = dataSet.getUncompressed(); @@ -232,13 +236,12 @@ public abstract class AbstractTestCompression } } - @Test(dataProvider = "data") + @ParameterizedTest + @MethodSource("getAllDataSets") public void testDecompressByteBufferHeapToHeap(DataSet dataSet) throws Exception { - if (!isByteBufferSupported()) { - throw new SkipException("ByteBuffer not supported"); - } + assumeTrue(isByteBufferSupported()); byte[] uncompressedOriginal = dataSet.getUncompressed(); @@ -251,13 +254,12 @@ public abstract class AbstractTestCompression assertByteBufferEqual(ByteBuffer.wrap(uncompressedOriginal), uncompressed); } - @Test(dataProvider = "data") + @ParameterizedTest + @MethodSource("getAllDataSets") public void testDecompressByteBufferHeapToDirect(DataSet dataSet) throws Exception { - if (!isByteBufferSupported()) { - throw new SkipException("ByteBuffer not supported"); - } + assumeTrue(isByteBufferSupported()); byte[] uncompressedOriginal = dataSet.getUncompressed(); @@ -270,13 +272,12 @@ public abstract class AbstractTestCompression assertByteBufferEqual(ByteBuffer.wrap(uncompressedOriginal), uncompressed); } - @Test(dataProvider = "data") + @ParameterizedTest + @MethodSource("getAllDataSets") public void testDecompressByteBufferDirectToHeap(DataSet dataSet) throws Exception { - if (!isByteBufferSupported()) { - throw new SkipException("ByteBuffer not supported"); - } + assumeTrue(isByteBufferSupported()); byte[] uncompressedOriginal = dataSet.getUncompressed(); @@ -289,13 +290,12 @@ public abstract class AbstractTestCompression assertByteBufferEqual(ByteBuffer.wrap(uncompressedOriginal), uncompressed); } - @Test(dataProvider = "data") + @ParameterizedTest + @MethodSource("getAllDataSets") public void testDecompressByteBufferDirectToDirect(DataSet dataSet) throws Exception { - if (!isByteBufferSupported()) { - throw new SkipException("ByteBuffer not supported"); - } + assumeTrue(isByteBufferSupported()); byte[] uncompressedOriginal = dataSet.getUncompressed(); @@ -308,7 +308,8 @@ public abstract class AbstractTestCompression assertByteBufferEqual(ByteBuffer.wrap(uncompressedOriginal), uncompressed); } - @Test(dataProvider = "data") + @ParameterizedTest + @MethodSource("getAllDataSets") public void testCompress(DataSet testCase) throws Exception { @@ -418,13 +419,12 @@ public abstract class AbstractTestCompression } } - @Test(dataProvider = "data") + @ParameterizedTest + @MethodSource("getAllDataSets") public void testCompressByteBufferHeapToHeap(DataSet dataSet) throws Exception { - if (!isByteBufferSupported()) { - throw new SkipException("ByteBuffer not supported"); - } + assumeTrue(isByteBufferSupported()); byte[] uncompressedOriginal = dataSet.getUncompressed(); @@ -436,12 +436,14 @@ public abstract class AbstractTestCompression ByteBuffer.allocate(compressor.maxCompressedLength(uncompressedOriginal.length))); } - @Test(dataProvider = "data") + @ParameterizedTest + @MethodSource("getAllDataSets") public void testCompressByteBufferHeapToDirect(DataSet dataSet) throws Exception { + assumeTrue(isByteBufferSupported()); if (!isByteBufferSupported()) { - throw new SkipException("ByteBuffer not supported"); + return; // throw new SkipException("ByteBuffer not supported"); } byte[] uncompressedOriginal = dataSet.getUncompressed(); @@ -454,13 +456,12 @@ public abstract class AbstractTestCompression ByteBuffer.allocateDirect(compressor.maxCompressedLength(uncompressedOriginal.length))); } - @Test(dataProvider = "data") + @ParameterizedTest + @MethodSource("getAllDataSets") public void testCompressByteBufferDirectToHeap(DataSet dataSet) throws Exception { - if (!isByteBufferSupported()) { - throw new SkipException("ByteBuffer not supported"); - } + assumeTrue(isByteBufferSupported()); byte[] uncompressedOriginal = dataSet.getUncompressed(); @@ -472,13 +473,12 @@ public abstract class AbstractTestCompression ByteBuffer.allocate(compressor.maxCompressedLength(uncompressedOriginal.length))); } - @Test(dataProvider = "data") + @ParameterizedTest + @MethodSource("getAllDataSets") public void testCompressByteBufferDirectToDirect(DataSet dataSet) throws Exception { - if (!isByteBufferSupported()) { - throw new SkipException("ByteBuffer not supported"); - } + assumeTrue(isByteBufferSupported()); byte[] uncompressedOriginal = dataSet.getUncompressed(); @@ -554,17 +554,8 @@ public abstract class AbstractTestCompression } } - @DataProvider(name = "data") - public Object[][] getTestCases() - throws IOException - { - Object[][] result = new Object[testCases.size()][]; - - for (int i = 0; i < testCases.size(); i++) { - result[i] = new Object[] {testCases.get(i)}; - } - - return result; + public Stream<DataSet> getAllDataSets() { + return testCases.stream(); } public static void assertByteArraysEqual(byte[] left, int leftOffset, int leftLength, byte[] right, int rightOffset, int rightLength) diff --git a/airlift-zstd/src/test/java/ai/vespa/airlift/compress/TestingModule.java b/airlift-zstd/src/test/java/ai/vespa/airlift/compress/TestingModule.java index d66c2672c3f..1ce713b1af9 100644 --- a/airlift-zstd/src/test/java/ai/vespa/airlift/compress/TestingModule.java +++ b/airlift-zstd/src/test/java/ai/vespa/airlift/compress/TestingModule.java @@ -13,40 +13,26 @@ */ package ai.vespa.airlift.compress; -import com.google.inject.Binder; -import com.google.inject.Module; -import com.google.inject.Provides; import ai.vespa.airlift.compress.benchmark.DataSet; -import org.openjdk.jmh.annotations.Param; - -import javax.inject.Singleton; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class TestingModule - implements Module { - @Override - public void configure(Binder binder) - { - } - - @Provides - @Singleton - public List<DataSet> dataSets() - throws NoSuchFieldException, IOException + public static List<DataSet> dataSets() { - String[] testNames = DataSet.class - .getDeclaredField("name") - .getAnnotation(Param.class) - .value(); + String[] testNames = DataSet.knownDataSets; List<DataSet> result = new ArrayList<>(); for (String testName : testNames) { DataSet entry = new DataSet(testName); - entry.loadFile(); + try { + entry.loadFile(); + } catch (java.io.IOException ex) { + throw new IllegalStateException("could not load dataset " + testName, ex); + } result.add(entry); } diff --git a/airlift-zstd/src/test/java/ai/vespa/airlift/compress/benchmark/DataSet.java b/airlift-zstd/src/test/java/ai/vespa/airlift/compress/benchmark/DataSet.java index 5db909eaef8..057fe7dcd8d 100644 --- a/airlift-zstd/src/test/java/ai/vespa/airlift/compress/benchmark/DataSet.java +++ b/airlift-zstd/src/test/java/ai/vespa/airlift/compress/benchmark/DataSet.java @@ -14,18 +14,13 @@ package ai.vespa.airlift.compress.benchmark; import com.google.common.io.Files; -import org.openjdk.jmh.annotations.Param; -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.Setup; -import org.openjdk.jmh.annotations.State; import java.io.File; import java.io.IOException; -@State(Scope.Thread) public class DataSet { - @Param({ + public static final String[] knownDataSets = { "canterbury/alice29.txt", "canterbury/asyoulik.txt", "canterbury/cp.html", @@ -86,7 +81,8 @@ public class DataSet "kppkn.gtb", "mapreduce-osdi-1.pdf", "urls.10K", - }) + }; + private String name; private byte[] uncompressed; @@ -105,7 +101,6 @@ public class DataSet this.uncompressed = uncompressed; } - @Setup public void loadFile() throws IOException { diff --git a/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestCompressor.java b/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestCompressor.java index 884ab8f2577..d6f13b98c71 100644 --- a/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestCompressor.java +++ b/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestCompressor.java @@ -13,9 +13,11 @@ */ package ai.vespa.airlift.zstd; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -import static org.testng.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static sun.misc.Unsafe.ARRAY_BYTE_BASE_OFFSET; public class TestCompressor @@ -30,18 +32,24 @@ public class TestCompressor ZstdFrameDecompressor.verifyMagic(buffer, address, address + buffer.length); } - @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".*buffer too small.*") + @Test public void testMagicFailsWithSmallBuffer() { byte[] buffer = new byte[3]; - ZstdFrameCompressor.writeMagic(buffer, ARRAY_BYTE_BASE_OFFSET, ARRAY_BYTE_BASE_OFFSET + buffer.length); + Throwable t = assertThrows(IllegalArgumentException.class, () -> { + ZstdFrameCompressor.writeMagic(buffer, ARRAY_BYTE_BASE_OFFSET, ARRAY_BYTE_BASE_OFFSET + buffer.length); + }); + assertTrue(t.getMessage().matches(".*buffer too small.*")); } - @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".*buffer too small.*") + @Test public void testFrameHeaderFailsWithSmallBuffer() { byte[] buffer = new byte[ZstdFrameCompressor.MAX_FRAME_HEADER_SIZE - 1]; - ZstdFrameCompressor.writeFrameHeader(buffer, ARRAY_BYTE_BASE_OFFSET, ARRAY_BYTE_BASE_OFFSET + buffer.length, 1000, 1024); + Throwable t = assertThrows(IllegalArgumentException.class, () -> { + ZstdFrameCompressor.writeFrameHeader(buffer, ARRAY_BYTE_BASE_OFFSET, ARRAY_BYTE_BASE_OFFSET + buffer.length, 1000, 1024); + }); + assertTrue(t.getMessage().matches(".*buffer too small.*")); } @Test @@ -64,22 +72,28 @@ public class TestCompressor verifyFrameHeader(Integer.MAX_VALUE, 1024, new FrameHeader(6, 1024, Integer.MAX_VALUE, -1, true)); } - @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Minimum window size is 1024") + @Test public void testMinimumWindowSize() { byte[] buffer = new byte[ZstdFrameCompressor.MAX_FRAME_HEADER_SIZE]; int address = ARRAY_BYTE_BASE_OFFSET; - ZstdFrameCompressor.writeFrameHeader(buffer, address, address + buffer.length, 2000, 1023); + Throwable t = assertThrows(IllegalArgumentException.class, () -> { + ZstdFrameCompressor.writeFrameHeader(buffer, address, address + buffer.length, 2000, 1023); + }); + assertTrue(t.getMessage().matches("Minimum window size is 1024")); } - @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "\\QWindow size of magnitude 2^10 must be multiple of 128\\E") + @Test public void testWindowSizePrecision() { byte[] buffer = new byte[ZstdFrameCompressor.MAX_FRAME_HEADER_SIZE]; int address = ARRAY_BYTE_BASE_OFFSET; - ZstdFrameCompressor.writeFrameHeader(buffer, address, address + buffer.length, 2000, 1025); + Throwable t = assertThrows(IllegalArgumentException.class, () -> { + ZstdFrameCompressor.writeFrameHeader(buffer, address, address + buffer.length, 2000, 1025); + }); + assertTrue(t.getMessage().matches("\\QWindow size of magnitude 2^10 must be multiple of 128\\E")); } private void verifyFrameHeader(int inputSize, int windowSize, FrameHeader expected) diff --git a/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestXxHash64.java b/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestXxHash64.java index b78888ca66e..9323365777d 100644 --- a/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestXxHash64.java +++ b/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestXxHash64.java @@ -15,9 +15,9 @@ package ai.vespa.airlift.zstd; import net.jpountz.xxhash.XXHash64; import net.jpountz.xxhash.XXHashFactory; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; -import static org.testng.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static sun.misc.Unsafe.ARRAY_BYTE_BASE_OFFSET; // forked from https://github.com/airlift/slice diff --git a/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestZstd.java b/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestZstd.java index f947122ce6a..e39d964a06f 100644 --- a/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestZstd.java +++ b/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestZstd.java @@ -21,13 +21,15 @@ import ai.vespa.airlift.compress.MalformedInputException; import ai.vespa.airlift.compress.benchmark.DataSet; import ai.vespa.airlift.compress.thirdparty.ZstdJniCompressor; import ai.vespa.airlift.compress.thirdparty.ZstdJniDecompressor; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.IOException; import java.util.Arrays; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.testng.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestZstd extends AbstractTestCompression @@ -168,7 +170,8 @@ public class TestZstd } // test over data sets, should the result depend on input size or its compressibility - @Test(dataProvider = "data") + @ParameterizedTest + @MethodSource("getAllDataSets") public void testGetDecompressedSize(DataSet dataSet) { Compressor compressor = getCompressor(); diff --git a/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestZstdInputStream.java b/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestZstdInputStream.java index b983389f2ef..fdf521b7d92 100644 --- a/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestZstdInputStream.java +++ b/airlift-zstd/src/test/java/ai/vespa/airlift/zstd/TestZstdInputStream.java @@ -20,7 +20,7 @@ import ai.vespa.airlift.compress.Decompressor; import ai.vespa.airlift.compress.MalformedInputException; import ai.vespa.airlift.compress.thirdparty.ZstdJniCompressor; import ai.vespa.airlift.compress.thirdparty.ZstdJniDecompressor; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.IOException; |