From 09b0eee5bbc90652b78aece27cba89998dff7816 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 19 Jun 2017 11:41:59 +0200 Subject: [PATCH] LUCENE-7571: Take into account float precision loss when generating unique values. --- .../src/test/org/apache/lucene/search/join/TestJoinUtil.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java index 49dd333de15..1503de8cc3b 100644 --- a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java +++ b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java @@ -1325,7 +1325,10 @@ public class TestJoinUtil extends LuceneTestCase { String uniqueRandomValue; do { // the trick is to generate values which will be ordered similarly for string, ints&longs, positive nums makes it easier - final int nextInt = random.nextInt(Integer.MAX_VALUE); + // + // Additionally in order to avoid precision loss when joining via a float field we can't generate values higher than + // 0xFFFFFF, so we can't use Integer#MAX_VALUE as upper bound here: + final int nextInt = random.nextInt(0xFFFFFF); uniqueRandomValue = String.format(Locale.ROOT, "%08x", nextInt); assert nextInt == Integer.parseUnsignedInt(uniqueRandomValue,16); } while ("".equals(uniqueRandomValue) || trackSet.contains(uniqueRandomValue));