LUCENE-7571: Take into account float precision loss when generating unique values.

This commit is contained in:
Martijn van Groningen 2017-06-19 11:41:59 +02:00 committed by Martijn van Groningen
parent 64093d6df1
commit 09b0eee5bb
No known key found for this signature in database
GPG Key ID: AB236F4FCF2AF12A
1 changed files with 4 additions and 1 deletions

View File

@ -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));