SOLR-15219: Fix TestPointFields integer overflow (#2460)

And also restore it's getRandomInts(..,..,bound) semantics to what it was -- positive or negative random values.
This commit is contained in:
David Smiley 2021-03-05 13:42:13 -05:00 committed by GitHub
parent 99a4bbf3a0
commit f36a867bd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 6 deletions

View File

@ -364,7 +364,7 @@ public class TestPointFields extends SolrTestCaseJ4 {
int bucketNum = 0;
int minBucketVal = min;
for (PosVal<Integer> value : sortedValues) {
while (value.val - minBucketVal >= gap) {
while ((long)value.val - (long)minBucketVal >= gap) {
++bucketNum;
minBucketVal += gap;
}
@ -2215,17 +2215,20 @@ public class TestPointFields extends SolrTestCaseJ4 {
});
}
private List<Integer> getRandomInts(int length, boolean missingVals, int bound) {
return getRandomList(length, missingVals, () -> random().nextInt(bound));
private List<Integer> getRandomInts(int length, boolean missingVals, int boundPosNeg) {
assert boundPosNeg > 0L;
return getRandomList(length, missingVals,
() -> (random().nextBoolean() ? 1 : -1) * random().nextInt(boundPosNeg));
}
private List<Integer> getRandomInts(int length, boolean missingVals) {
return getRandomList(length, missingVals, () -> random().nextInt());
}
private List<Long> getRandomLongs(int length, boolean missingVals, long bound) {
assert bound > 0L;
return getRandomList(length, missingVals, () -> random().nextLong() % bound); // see Random.nextInt(int bound)
private List<Long> getRandomLongs(int length, boolean missingVals, long boundPosNeg) {
assert boundPosNeg > 0L;
return getRandomList(length, missingVals,
() -> random().nextLong() % boundPosNeg); // see Random.nextInt(int bound)
}
private List<Long> getRandomLongs(int length, boolean missingVals) {