Skip to content

Commit 211bde9

Browse files
committed
test: AoS Tuple Sketch cross language
1 parent 23072ed commit 211bde9

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.datasketches.tuple.strings;
21+
22+
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
23+
import static org.apache.datasketches.common.TestUtil.javaPath;
24+
import static org.testng.Assert.assertEquals;
25+
import static org.testng.Assert.assertFalse;
26+
27+
import java.io.IOException;
28+
import java.nio.file.Files;
29+
30+
import org.apache.datasketches.common.ResizeFactor;
31+
import org.testng.annotations.Test;
32+
33+
/**
34+
* Serialize binary sketches to be tested by other language code.
35+
* Test deserialization of binary sketches serialized by other language code.
36+
*/
37+
public class AosSketchCrossLanguageTest {
38+
39+
@Test(groups = {GENERATE_JAVA_FILES})
40+
public void generateBinariesForCompatibilityTestingOneString() throws IOException {
41+
final int[] nArr = {0, 1, 10, 100, 1000, 10_000, 100_000, 1_000_000};
42+
for (int n : nArr) {
43+
final ArrayOfStringsTupleSketch sk = new ArrayOfStringsTupleSketch();
44+
for (int i = 0; i < n; i++) {
45+
sk.update(new String[] {String.valueOf(i)}, new String[] {"value" + i});
46+
}
47+
Files.newOutputStream(javaPath.resolve("aos_1_n" + n + "_java.sk")).write(sk.compact().toByteArray());
48+
}
49+
}
50+
51+
@Test(groups = {GENERATE_JAVA_FILES})
52+
public void generateBinariesForCompatibilityTestingThreeStrings() throws IOException {
53+
final int[] nArr = {0, 1, 10, 100, 1000, 10_000, 100_000, 1_000_000};
54+
for (int n : nArr) {
55+
final ArrayOfStringsTupleSketch sk = new ArrayOfStringsTupleSketch();
56+
for (int i = 0; i < n; i++) {
57+
sk.update(new String[] {String.valueOf(i)}, new String[] {"a" + i, "b" + i, "c" + i});
58+
}
59+
Files.newOutputStream(javaPath.resolve("aos_3_n" + n + "_java.sk")).write(sk.compact().toByteArray());
60+
}
61+
}
62+
63+
@Test(groups = {GENERATE_JAVA_FILES})
64+
public void generateBinariesForCompatibilityTestingNonEmptyNoEntries() throws IOException {
65+
final ArrayOfStringsTupleSketch sk = new ArrayOfStringsTupleSketch(12,
66+
ResizeFactor.X8, 0.01f);
67+
sk.update(new String[] {"key1"}, new String[] {"value1"});
68+
assertFalse(sk.isEmpty());
69+
assertEquals(sk.getRetainedEntries(), 0);
70+
Files.newOutputStream(javaPath.resolve("aos_1_non_empty_no_entries_java.sk")).write(sk.compact().toByteArray());
71+
}
72+
73+
@Test(groups = {GENERATE_JAVA_FILES})
74+
public void generateBinariesForCompatibilityTestingMultiKeyStrings() throws IOException {
75+
final int[] nArr = {0, 1, 10, 100, 1000, 10_000};
76+
for (int n : nArr) {
77+
final ArrayOfStringsTupleSketch sk = new ArrayOfStringsTupleSketch();
78+
for (int i = 0; i < n; i++) {
79+
sk.update(new String[] {"key" + i, "subkey" + (i % 10)}, new String[] {"value" + i});
80+
}
81+
Files.newOutputStream(javaPath.resolve("aos_multikey_n" + n + "_java.sk")).write(sk.compact().toByteArray());
82+
}
83+
}
84+
85+
@Test(groups = {GENERATE_JAVA_FILES})
86+
public void generateBinariesForCompatibilityTestingUnicodeStrings() throws IOException {
87+
final ArrayOfStringsTupleSketch sk = new ArrayOfStringsTupleSketch();
88+
89+
sk.update(new String[]{"키", "열쇠"}, new String[]{"밸류", "값"});
90+
sk.update(new String[]{"🔑", "🗝️"}, new String[]{"📦", "🎁"});
91+
sk.update(new String[]{"ключ1", "ключ2"}, new String[]{"ценить1", "ценить2"});
92+
93+
assertFalse(sk.isEmpty());
94+
assertEquals(sk.getRetainedEntries(), 3);
95+
96+
Files.newOutputStream(javaPath.resolve("aos_unicode_java.sk")).write(sk.compact().toByteArray());
97+
}
98+
}

0 commit comments

Comments
 (0)