From 3b559e01bef5093840c5adf94f4eeb9bd06550eb Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Thu, 30 Mar 2017 10:14:41 +0200 Subject: [PATCH] Fixed sliced search tests that rely on BytesRef.hashCode output --- .../java/org/elasticsearch/search/slice/TermsSliceQuery.java | 2 +- .../org/elasticsearch/search/slice/TermsSliceQueryTests.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/slice/TermsSliceQuery.java b/core/src/main/java/org/elasticsearch/search/slice/TermsSliceQuery.java index 947014f43e0..ddc02d32e55 100644 --- a/core/src/main/java/org/elasticsearch/search/slice/TermsSliceQuery.java +++ b/core/src/main/java/org/elasticsearch/search/slice/TermsSliceQuery.java @@ -48,7 +48,7 @@ import java.io.IOException; */ public final class TermsSliceQuery extends SliceQuery { // Fixed seed for computing term hashCode - private static final int SEED = 7919; + public static final int SEED = 7919; public TermsSliceQuery(String field, int id, int max) { super(field, id, max); diff --git a/core/src/test/java/org/elasticsearch/search/slice/TermsSliceQueryTests.java b/core/src/test/java/org/elasticsearch/search/slice/TermsSliceQueryTests.java index e00dabc6363..3fa4ce41052 100644 --- a/core/src/test/java/org/elasticsearch/search/slice/TermsSliceQueryTests.java +++ b/core/src/test/java/org/elasticsearch/search/slice/TermsSliceQueryTests.java @@ -34,6 +34,7 @@ import org.apache.lucene.search.QueryUtils; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.StringHelper; import org.elasticsearch.common.UUIDs; import org.elasticsearch.test.ESTestCase; @@ -72,7 +73,8 @@ public class TermsSliceQueryTests extends ESTestCase { Document doc = new Document(); String uuid = UUIDs.base64UUID(); BytesRef br = new BytesRef(uuid); - int id = Math.floorMod(br.hashCode(), max); + int hashCode = StringHelper.murmurhash3_x86_32(br, TermsSliceQuery.SEED); + int id = Math.floorMod(hashCode, max); sliceCounters[id] ++; doc.add(new StringField("uuid", uuid, Field.Store.YES)); w.addDocument(doc);