Skip to content

Commit 1ad0be1

Browse files
Merge pull request #666 from QasimKhan5d/qasim/cpcsketch
Add Go cross-serde tests for CPC sketch
2 parents ada423c + b5ad37d commit 1ad0be1

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

pom.xml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ under the License.
9090
<!-- these are TestNG groups used for excluding / including groups of tests. See profiles section. -->
9191
<testng.generate-java-files>generate_java_files</testng.generate-java-files>
9292
<testng.check-cpp-files>check_cpp_files</testng.check-cpp-files>
93+
<testng.check-go-files>check_go_files</testng.check-go-files>
9394
<testng.check-cpp-historical-files>check_cpp_historical_files</testng.check-cpp-historical-files>
9495

9596
<!-- System-wide properties -->
@@ -625,7 +626,7 @@ under the License.
625626
<artifactId>maven-surefire-plugin</artifactId>
626627
<configuration>
627628
<groups>${testng.generate-java-files}</groups>
628-
<excludedGroups>${testng.check-cpp-files},${testng.check-cpp-historical-files}</excludedGroups>
629+
<excludedGroups>${testng.check-cpp-files},${testng.check-go-files},${testng.check-cpp-historical-files}</excludedGroups>
629630
</configuration>
630631
</plugin>
631632
</plugins>
@@ -644,7 +645,26 @@ under the License.
644645
<artifactId>maven-surefire-plugin</artifactId>
645646
<configuration>
646647
<groups>${testng.check-cpp-files}</groups>
647-
<excludedGroups>${testng.generate-java-files},${testng.check-cpp-historical-files}</excludedGroups>
648+
<excludedGroups>${testng.generate-java-files},${testng.check-go-files},${testng.check-cpp-historical-files}</excludedGroups>
649+
</configuration>
650+
</plugin>
651+
</plugins>
652+
</pluginManagement>
653+
</build>
654+
</profile>
655+
656+
<profile>
657+
<id>check-go-files</id>
658+
<build>
659+
<pluginManagement>
660+
<plugins>
661+
<plugin>
662+
<!-- Apache Parent pom, pluginManagement-->
663+
<groupId>org.apache.maven.plugins</groupId>
664+
<artifactId>maven-surefire-plugin</artifactId>
665+
<configuration>
666+
<groups>${testng.check-cpp-files}</groups>
667+
<excludedGroups>${testng.generate-java-files},${testng.check-cpp-files},${testng.check-cpp-historical-files}</excludedGroups>
648668
</configuration>
649669
</plugin>
650670
</plugins>
@@ -663,7 +683,7 @@ under the License.
663683
<artifactId>maven-surefire-plugin</artifactId>
664684
<configuration>
665685
<groups>${testng.check-cpp-historical-files}</groups>
666-
<excludedGroups>${testng.generate-java-files},${testng.check-cpp-files}</excludedGroups>
686+
<excludedGroups>${testng.generate-java-files},${testng.check-go-files},${testng.check-cpp-files}</excludedGroups>
667687
</configuration>
668688
</plugin>
669689
</plugins>

src/main/java/org/apache/datasketches/cpc/CpcSketch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ public String toString(final boolean detail) {
727727
final double errConst = mergeFlag ? log(2) : sqrt(log(2) / 2.0);
728728
final double rse = errConst / Math.sqrt(1 << lgK);
729729
final StringBuilder sb = new StringBuilder();
730-
sb.append("### CPD SKETCH - PREAMBLE:").append(LS);
730+
sb.append("### CPC SKETCH - PREAMBLE:").append(LS);
731731
sb.append(" Flavor : ").append(getFlavor()).append(LS);
732732
sb.append(" LgK : ").append(lgK).append(LS);
733733
sb.append(" Merge Flag : ").append(mergeFlag).append(LS);

src/test/java/org/apache/datasketches/common/TestUtil.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public final class TestUtil {
4747
*/
4848
public static final String GENERATE_JAVA_FILES = "generate_java_files";
4949
public static final String CHECK_CPP_FILES = "check_cpp_files";
50+
public static final String CHECK_GO_FILES = "check_go_files";
5051
public static final String CHECK_CPP_HISTORICAL_FILES = "check_cpp_historical_files";
5152

5253
/**
@@ -59,6 +60,11 @@ public final class TestUtil {
5960
*/
6061
public static final Path cppPath = createPath("serialization_test_data/cpp_generated_files");
6162

63+
/**
64+
* The full target Path for Go serialized sketches to be tested by Java.
65+
*/
66+
public static final Path goPath = createPath("serialization_test_data/go_generated_files");
67+
6268
private static Path createPath(final String projectLocalDir) {
6369
try {
6470
return Files.createDirectories(Paths.get(userDir, projectLocalDir));

src/test/java/org/apache/datasketches/cpc/CpcSketchCrossLanguageTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
package org.apache.datasketches.cpc;
2121

2222
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
23+
import static org.apache.datasketches.common.TestUtil.CHECK_GO_FILES;
2324
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
2425
import static org.apache.datasketches.common.TestUtil.cppPath;
26+
import static org.apache.datasketches.common.TestUtil.goPath;
2527
import static org.apache.datasketches.common.TestUtil.javaPath;
2628
import static org.testng.Assert.assertEquals;
2729

@@ -80,4 +82,17 @@ public void allFlavors() throws IOException {
8082
}
8183
}
8284

85+
@Test(groups = {CHECK_GO_FILES})
86+
public void checkAllFlavorsGo() throws IOException {
87+
final int[] nArr = {0, 100, 200, 2000, 20000};
88+
final Flavor[] flavorArr = {Flavor.EMPTY, Flavor.SPARSE, Flavor.HYBRID, Flavor.PINNED, Flavor.SLIDING};
89+
int flavorIdx = 0;
90+
for (int n: nArr) {
91+
final byte[] bytes = Files.readAllBytes(goPath.resolve("cpc_n" + n + "_go.sk"));
92+
final CpcSketch sketch = CpcSketch.heapify(Memory.wrap(bytes));
93+
assertEquals(sketch.getFlavor(), flavorArr[flavorIdx++]);
94+
assertEquals(sketch.getEstimate(), n, n * 0.02);
95+
}
96+
}
97+
8398
}

0 commit comments

Comments
 (0)