Skip to content

Commit

Permalink
Merge pull request #468 from apache/sub_static_const
Browse files Browse the repository at this point in the history
Substitute compile-time constants for the TestNG groups name.
  • Loading branch information
leerho authored Aug 24, 2023
2 parents 78d7228 + 10e55be commit aa0f648
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 67 deletions.
7 changes: 7 additions & 0 deletions src/test/java/org/apache/datasketches/common/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public final class TestUtil {

private static String userDir = System.getProperty("user.dir");

/**
* TestNG group constants
*/
public static final String GENERATE_JAVA_FILES = "generate_java_files";
public static final String CHECK_CPP_FILES = "check_cpp_files";
public static final String CHECK_CPP_HISTORICAL_FILES = "check_cpp_historical_files";

/**
* The full target Path for Java serialized sketches to be tested by other languages.
*/
Expand Down
24 changes: 13 additions & 11 deletions src/test/java/org/apache/datasketches/cpc/CpcCBinariesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.apache.datasketches.cpc;

import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.testng.Assert.assertEquals;
Expand All @@ -40,7 +42,7 @@ public class CpcCBinariesTest {
static PrintStream ps = System.out;
static final String LS = System.getProperty("line.separator");

@Test(groups = {"check_cpp_files"})
@Test(groups = {CHECK_CPP_FILES})
public void checkEmptyBin() {
final File file = cppPath.resolve("cpc-empty.sk").toFile();
try (MapHandle mh = Memory.map(file)) {
Expand All @@ -53,7 +55,7 @@ public void checkEmptyBin() {
}
}

@Test(groups = {"check_cpp_files"})
@Test(groups = {CHECK_CPP_FILES})
public void checkSparseBin() {
final File file = cppPath.resolve("cpc-sparse.sk").toFile();
try (MapHandle mh = Memory.map(file)) {
Expand All @@ -78,7 +80,7 @@ public void checkSparseBin() {
}
}

@Test(groups = {"check_cpp_files"})
@Test(groups = {CHECK_CPP_FILES})
public void checkHybridBin() {
final File file = cppPath.resolve("cpc-hybrid.sk").toFile();
try (MapHandle mh = Memory.map(file)) {
Expand All @@ -103,7 +105,7 @@ public void checkHybridBin() {
}
}

@Test(groups = {"check_cpp_files"})
@Test(groups = {CHECK_CPP_FILES})
public void checkPinnedBin() {
final File file = cppPath.resolve("cpc-pinned.sk").toFile();
try (MapHandle mh = Memory.map(file)) {
Expand All @@ -128,7 +130,7 @@ public void checkPinnedBin() {
}
}

@Test(groups = {"check_cpp_files"})
@Test(groups = {CHECK_CPP_FILES})
public void checkSlidingBin() {
final File file = cppPath.resolve("cpc-sliding.sk").toFile();
try (MapHandle mh = Memory.map(file)) {
Expand All @@ -155,7 +157,7 @@ public void checkSlidingBin() {

//Image checks

@Test(groups = {"check_cpp_files"})
@Test(groups = {CHECK_CPP_FILES})
public void checkEmptyImages() {
final File file = cppPath.resolve("cpc-empty.sk").toFile();
try (MapHandle mh = Memory.map(file)) {
Expand All @@ -174,7 +176,7 @@ public void checkEmptyImages() {
}
}

@Test(groups = {"check_cpp_files"})
@Test(groups = {CHECK_CPP_FILES})
public void checkSparseImages() {
final File file = cppPath.resolve("cpc-sparse.sk").toFile();
try (MapHandle mh = Memory.map(file)) {
Expand All @@ -194,7 +196,7 @@ public void checkSparseImages() {
}
}

@Test(groups = {"check_cpp_files"})
@Test(groups = {CHECK_CPP_FILES})
public void checkHybridImages() {
final File file = cppPath.resolve("cpc-hybrid.sk").toFile();
try (MapHandle mh = Memory.map(file)) {
Expand All @@ -214,7 +216,7 @@ public void checkHybridImages() {
}
}

@Test(groups = {"check_cpp_files"})
@Test(groups = {CHECK_CPP_FILES})
public void checkPinnedImages() {
final File file = cppPath.resolve("cpc-pinned.sk").toFile();
try (MapHandle mh = Memory.map(file)) {
Expand All @@ -234,7 +236,7 @@ public void checkPinnedImages() {
}
}

@Test(groups = {"check_cpp_files"})
@Test(groups = {CHECK_CPP_FILES})
public void checkSlidingImages() {
final File file = cppPath.resolve("cpc-sliding.sk").toFile();
try (MapHandle mh = Memory.map(file)) {
Expand Down Expand Up @@ -275,7 +277,7 @@ public void genSparseSketch() {
println(sk2.toString(true));
}

@Test(groups = {"generate_java_files"})
@Test(groups = {GENERATE_JAVA_FILES})
public void generateBinariesForCompatibilityTesting() throws IOException {
final int[] nArr = {0, 100, 200, 2000, 20_000};
final Flavor[] flavorArr = {Flavor.EMPTY, Flavor.SPARSE, Flavor.HYBRID, Flavor.PINNED, Flavor.SLIDING};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.datasketches.frequencies;

import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
Expand Down Expand Up @@ -83,7 +84,7 @@ public void longsToItems() {
Assert.assertEquals(sketch2.getEstimate(4L), 1);
}

@Test(groups = {"generate_java_files"})
@Test(groups = {GENERATE_JAVA_FILES})
public void generateBinariesForCompatibilityTestingLongsSketch() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1000, 10_000, 100_000, 1_000_000};
for (int n: nArr) {
Expand All @@ -96,7 +97,7 @@ public void generateBinariesForCompatibilityTestingLongsSketch() throws IOExcept
}
}

@Test(groups = {"generate_java_files"})
@Test(groups = {GENERATE_JAVA_FILES})
public void generateBinariesForCompatibilityTestingStringsSketch() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1000, 10_000, 100_000, 1_000_000};
for (final int n: nArr) {
Expand All @@ -110,7 +111,7 @@ public void generateBinariesForCompatibilityTestingStringsSketch() throws IOExce
}
}

@Test(groups = {"generate_java_files"})
@Test(groups = {GENERATE_JAVA_FILES})
public void generateBinariesForCompatibilityTestingStringsSketchAscii() throws IOException {
final ItemsSketch<String> sk = new ItemsSketch<>(64);
sk.update("aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1);
Expand All @@ -121,7 +122,7 @@ public void generateBinariesForCompatibilityTestingStringsSketchAscii() throws I
.write(sk.toByteArray(new ArrayOfStringsSerDe()));
}

@Test(groups = {"generate_java_files"})
@Test(groups = {GENERATE_JAVA_FILES})
public void generateBinariesForCompatibilityTestingStringsSketchUtf8() throws IOException {
final ItemsSketch<String> sk = new ItemsSketch<>(64);
sk.update("абвгд", 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.datasketches.hll;

import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.apache.datasketches.hll.TgtHllType.HLL_4;
import static org.apache.datasketches.hll.TgtHllType.HLL_6;
Expand All @@ -31,7 +32,7 @@

public class HllSketchSerDeTest {

@Test(groups = {"generate_java_files"})
@Test(groups = {GENERATE_JAVA_FILES})
public void generateBinariesForCompatibilityTesting() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1000, 10_000, 100_000, 1_000_000};
for (int n: nArr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

package org.apache.datasketches.kll;

import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_HISTORICAL_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
import static org.apache.datasketches.common.TestUtil.cppHistPath;
import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.testng.Assert.assertEquals;
Expand All @@ -39,7 +43,7 @@
public class KllCrossLanguageTest {
private ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe();

@Test(groups = {"generate_java_files"})
@Test(groups = {GENERATE_JAVA_FILES})
public void generateKllDoublesSketchBinaries() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1_000, 10_000, 100_000, 1_000_000};
for (int n: nArr) {
Expand All @@ -49,7 +53,7 @@ public void generateKllDoublesSketchBinaries() throws IOException {
}
}

@Test(groups = {"generate_java_files"})
@Test(groups = {GENERATE_JAVA_FILES})
public void generateKllFloatsSketchBinaries() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1_000, 10_000, 100_000, 1_000_000};
for (int n: nArr) {
Expand All @@ -59,7 +63,7 @@ public void generateKllFloatsSketchBinaries() throws IOException {
}
}

@Test(groups = {"generate_java_files"})
@Test(groups = {GENERATE_JAVA_FILES})
public void generateKllItemsSketchBinaries() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1_000, 10_000, 100_000, 1_000_000};
for (int n: nArr) {
Expand All @@ -70,7 +74,7 @@ public void generateKllItemsSketchBinaries() throws IOException {
}
}

@Test(groups = {"check_cpp_files"})
@Test(groups = {CHECK_CPP_FILES})
public void checkCppKllDoublesSketchEstimationMode() throws IOException {
final byte[] byteArr = Files.readAllBytes(cppPath.resolve("kll_double_estimation_cpp.sk"));
final KllDoublesSketch sk = KllDoublesSketch.heapify(Memory.wrap(byteArr));
Expand All @@ -79,9 +83,9 @@ public void checkCppKllDoublesSketchEstimationMode() throws IOException {
assertEquals(sk.getN(), 1000);
}

@Test(groups = {"check_cpp_historical_files"})
@Test(groups = {CHECK_CPP_HISTORICAL_FILES})
public void checkCppKllDoublesSketchOneItemVersion1() throws IOException {
final byte[] byteArr = Files.readAllBytes(cppPath.resolve("kll_sketch_double_one_item_v1.sk"));
final byte[] byteArr = Files.readAllBytes(cppHistPath.resolve("kll_sketch_double_one_item_v1.sk"));
final KllDoublesSketch sk = KllDoublesSketch.heapify(Memory.wrap(byteArr));
assertFalse(sk.isEmpty());
assertFalse(sk.isEstimationMode());
Expand All @@ -91,7 +95,7 @@ public void checkCppKllDoublesSketchOneItemVersion1() throws IOException {
assertEquals(sk.getMaxItem(), 1.0);
}

@Test(groups = {"check_cpp_files"})
@Test(groups = {CHECK_CPP_FILES})
public void checkCppKllFloatsSketchEstimationMode() throws IOException {
final byte[] byteArr = Files.readAllBytes(cppPath.resolve("kll_float_estimation_cpp.sk"));
final KllFloatsSketch sk = KllFloatsSketch.heapify(Memory.wrap(byteArr));
Expand All @@ -100,9 +104,9 @@ public void checkCppKllFloatsSketchEstimationMode() throws IOException {
assertEquals(sk.getN(), 1000);
}

@Test(groups = {"check_cpp_historical_files"})
@Test(groups = {CHECK_CPP_HISTORICAL_FILES})
public void checkCppKllFloatsSketchOneItemVersion1() throws IOException {
final byte[] byteArr = Files.readAllBytes(cppPath.resolve("kll_sketch_float_one_item_v1.sk"));
final byte[] byteArr = Files.readAllBytes(cppHistPath.resolve("kll_sketch_float_one_item_v1.sk"));
final KllFloatsSketch sk = KllFloatsSketch.heapify(Memory.wrap(byteArr));
assertFalse(sk.isEmpty());
assertFalse(sk.isEstimationMode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.datasketches.quantiles;

import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
import static org.apache.datasketches.common.TestUtil.javaPath;

import java.io.IOException;
Expand All @@ -28,7 +29,7 @@

public class DoublesSketchSerDeTest {

@Test(groups = {"generate_java_files"})
@Test(groups = {GENERATE_JAVA_FILES})
public void generateBinariesForCompatibilityTesting() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1000, 10_000, 100_000, 1_000_000};
for (final int n: nArr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

package org.apache.datasketches.quantiles;

import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_HISTORICAL_FILES;
import static org.apache.datasketches.common.TestUtil.cppHistPath;
import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.EXCLUSIVE;

import java.io.IOException;
Expand All @@ -33,7 +34,7 @@
public class ForwardCompatibilityTest {
private static final String LS = System.getProperty("line.separator");

@Test(groups = {"check_cpp_historical_files"})
@Test(groups = {CHECK_CPP_HISTORICAL_FILES})
//fullPath: sketches/src/test/resources/Qk128_n50_v0.3.0.sk
//Median2: 26.0
public void check030_50() {
Expand All @@ -43,7 +44,7 @@ public void check030_50() {
getAndCheck(ver, n, expected);
}

@Test(groups = {"check_cpp_historical_files"})
@Test(groups = {CHECK_CPP_HISTORICAL_FILES})
//fullPath: sketches/src/test/resources/Qk128_n1000_v0.3.0.sk
//Median2: 501.0
public void check030_1000() {
Expand All @@ -53,7 +54,7 @@ public void check030_1000() {
getAndCheck(ver, n, expected);
}

@Test(groups = {"check_cpp_historical_files"})
@Test(groups = {CHECK_CPP_HISTORICAL_FILES})
//fullPath: sketches/src/test/resources/Qk128_n50_v0.6.0.sk
//Median2: 26.0
public void check060_50() {
Expand All @@ -63,7 +64,7 @@ public void check060_50() {
getAndCheck(ver, n, expected);
}

@Test(groups = {"check_cpp_historical_files"})
@Test(groups = {CHECK_CPP_HISTORICAL_FILES})
//fullPath: sketches/src/test/resources/Qk128_n1000_v0.6.0.sk
//Median2: 501.0
public void check060_1000() {
Expand All @@ -73,7 +74,7 @@ public void check060_1000() {
getAndCheck(ver, n, expected);
}

@Test(groups = {"check_cpp_historical_files"})
@Test(groups = {CHECK_CPP_HISTORICAL_FILES})
//fullPath: sketches/src/test/resources/Qk128_n50_v0.8.0.sk
//Median2: 26.0
public void check080_50() {
Expand All @@ -83,7 +84,7 @@ public void check080_50() {
getAndCheck(ver, n, expected);
}

@Test(groups = {"check_cpp_historical_files"})
@Test(groups = {CHECK_CPP_HISTORICAL_FILES})
//fullPath: sketches/src/test/resources/Qk128_n1000_v0.8.0.sk
//Median2: 501.0
public void check080_1000() {
Expand All @@ -93,7 +94,7 @@ public void check080_1000() {
getAndCheck(ver, n, expected);
}

@Test(groups = {"check_cpp_historical_files"})
@Test(groups = {CHECK_CPP_HISTORICAL_FILES})
//fullPath: sketches/src/test/resources/Qk128_n50_v0.8.3.sk
//Median2: 26.0
public void check083_50() {
Expand All @@ -103,7 +104,7 @@ public void check083_50() {
getAndCheck(ver, n, expected);
}

@Test(groups = {"check_cpp_historical_files"})
@Test(groups = {CHECK_CPP_HISTORICAL_FILES})
//fullPath: sketches/src/test/resources/Qk128_n1000_v0.8.0.sk
//Median2: 501.0
public void check083_1000() {
Expand All @@ -124,7 +125,7 @@ private static void getAndCheck(String ver, int n, double quantile) {
//Read File bytes
byte[] byteArr;
try {
byteArr = Files.readAllBytes(cppPath.resolve(fileName));
byteArr = Files.readAllBytes(cppHistPath.resolve(fileName));
} catch (IOException e) { throw new SketchesArgumentException(e.getCause().toString()); }
Memory srcMem = Memory.wrap(byteArr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.apache.datasketches.quantiles;

import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.apache.datasketches.common.TestUtil.*;
import static org.testng.Assert.assertEquals;

import java.io.IOException;
Expand All @@ -31,7 +31,7 @@

public class ItemsSketchSerDeTest {

@Test(groups = {"generate_java_files"})
@Test(groups = {GENERATE_JAVA_FILES})
public void generateBinariesForCompatibilityTesting() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1000, 10_000, 100_000, 1_000_000};
for (final int n: nArr) {
Expand Down
Loading

0 comments on commit aa0f648

Please sign in to comment.