Skip to content

Commit 15536c9

Browse files
committed
add murmur3_64 test suite;
1 parent 688843f commit 15536c9

File tree

7 files changed

+100037
-7
lines changed

7 files changed

+100037
-7
lines changed

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.split.client</groupId>
77
<artifactId>java-client-parent</artifactId>
8-
<version>3.3.3</version>
8+
<version>3.3.3-rc1</version>
99
</parent>
1010
<artifactId>java-client</artifactId>
1111
<packaging>jar</packaging>

client/src/main/java/io/split/client/utils/MurmurHash3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public static long[] hash128x64(final byte[] data) {
208208
* @param seed The initial seed value
209209
* @return The 128-bit hash (2 longs)
210210
*/
211-
private static long[] hash128x64(final byte[] data, final int offset, final int length, final long seed) {
211+
public static long[] hash128x64(final byte[] data, final int offset, final int length, final long seed) {
212212
long h1 = seed;
213213
long h2 = seed;
214214
final int nblocks = length >> 4;

client/src/test/java/io/split/client/impressions/ImpressionObserverTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.split.client.impressions;
22

3+
import com.google.common.base.Strings;
34
import io.split.client.dtos.KeyImpression;
45
// import jdk.nashorn.internal.ir.debug.ObjectSizeCalculator;
56
import org.junit.Test;
@@ -58,7 +59,7 @@ public void testBasicFunctionality() {
5859
}
5960

6061
@Test
61-
public void testMemoryUsageStopsWhenCacheIsFull() throws InvocationTargetException, IllegalAccessException {
62+
public void testMemoryUsageStopsWhenCacheIsFull() throws Exception {
6263

6364
Class objectSizeCalculatorClass;
6465
ClassLoader classLoader = this.getClass().getClassLoader();
@@ -67,8 +68,11 @@ public void testMemoryUsageStopsWhenCacheIsFull() throws InvocationTargetExcepti
6768
objectSizeCalculatorClass = classLoader.loadClass("jdk.nashorn.internal.ir.debug.ObjectSizeCalculator");
6869
getObjectSize = objectSizeCalculatorClass.getMethod("getObjectSize", Object.class); //getObjectSize(observer);
6970
} catch (ClassNotFoundException | NoSuchMethodException e) {
70-
_log.error("This test only runs with the hotspot JVM. PLEASE ensure it runs correctly at least locally. " +
71-
"Ignoring test now.");
71+
_log.error("This test only runs with the hotspot JVM. It's ignored locally, but mandatory on CI");
72+
if (!Strings.isNullOrEmpty(System.getenv("CI"))) { // If the CI environment variable is present
73+
throw new Exception("Setup CI to run with a hotspot JVM");
74+
}
75+
// Otherwise just ignore this test.
7276
return;
7377
}
7478

client/src/test/java/io/split/engine/splitter/HashConsistencyTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.split.engine.splitter;
22

33
import com.google.common.hash.Hashing;
4+
import io.split.client.utils.MurmurHash3;
45
import org.junit.Assert;
56
import org.junit.Ignore;
67
import org.junit.Test;
@@ -56,6 +57,13 @@ public void testGuavaMurmur3HashNonAlphaNum() throws IOException {
5657
validateFileGuavaMurmur3Hash(file);
5758
}
5859

60+
@Test
61+
public void testMurmurHash3_64() throws IOException {
62+
URL resource = getClass().getClassLoader().getResource("murmur3_64_uuids.csv");
63+
File file = new File(resource.getFile());
64+
validateFileMurmurHash3_64(file);
65+
}
66+
5967
private void validateFileLegacyHash(File file) throws IOException {
6068
BufferedReader reader = new BufferedReader(new FileReader(file));
6169
reader.readLine(); // Header
@@ -111,10 +119,28 @@ private void validateFileGuavaMurmur3Hash(File file) throws IOException {
111119
int expected_bucket = Integer.parseInt(parts[3]);
112120

113121
int hash = Hashing.murmur3_32(seed).hashString(key, Charset.forName("UTF-8")).asInt();
122+
114123
int bucket = Splitter.bucket(hash);
115124

116125
Assert.assertEquals(expected_hash, hash);
117126
Assert.assertEquals(expected_bucket, bucket);
118127
}
119128
}
129+
130+
private void validateFileMurmurHash3_64(File file) throws IOException {
131+
BufferedReader reader = new BufferedReader(new FileReader(file));
132+
reader.readLine(); // Header
133+
134+
String line;
135+
int i = 0;
136+
while ((line = reader.readLine()) != null) {
137+
String[] parts = line.split(",");
138+
String key = parts[0];
139+
long seed = Long.parseLong(parts[1]);
140+
long expected_hash = Long.parseLong(parts[2]);
141+
long[] hash = MurmurHash3.hash128x64(key.getBytes(), 0, key.length(), seed);
142+
Assert.assertEquals(expected_hash, hash[0]);
143+
144+
}
145+
}
120146
}

0 commit comments

Comments
 (0)