Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

Improve speed of nightly tests by not creating new random instances all the time

Uwe Schindler7a28af446261
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestArrayUtil.java b/lucene/core/src/test/org/apache/lucene/util/TestArrayUtil.java
index 3e3ea2d4297..61ed951ccc2 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestArrayUtil.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestArrayUtil.java
@@ -19,6 +19,7 @@ package org.apache.lucene.util;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Random;
public class TestArrayUtil extends LuceneTestCase {
@@ -49,10 +50,11 @@ public class TestArrayUtil extends LuceneTestCase {
}
public void testInvalidElementSizes() {
- int num = atLeast(10000);
+ final Random rnd = random();
+ final int num = atLeast(10000);
for (int iter = 0; iter < num; iter++) {
- final int minTargetSize = random().nextInt(Integer.MAX_VALUE);
- final int elemSize = random().nextInt(11);
+ final int minTargetSize = rnd.nextInt(Integer.MAX_VALUE);
+ final int elemSize = rnd.nextInt(11);
final int v = ArrayUtil.oversize(minTargetSize, elemSize);
assertTrue(v >= minTargetSize);
}
@@ -118,9 +120,10 @@ public class TestArrayUtil extends LuceneTestCase {
}
private Integer[] createRandomArray(int maxSize) {
- final Integer[] a = new Integer[random().nextInt(maxSize) + 1];
+ final Random rnd = random();
+ final Integer[] a = new Integer[rnd.nextInt(maxSize) + 1];
for (int i = 0; i < a.length; i++) {
- a[i] = Integer.valueOf(random().nextInt(a.length));
+ a[i] = Integer.valueOf(rnd.nextInt(a.length));
}
return a;
}
@@ -146,9 +149,10 @@ public class TestArrayUtil extends LuceneTestCase {
}
private Integer[] createSparseRandomArray(int maxSize) {
- final Integer[] a = new Integer[random().nextInt(maxSize) + 1];
+ final Random rnd = random();
+ final Integer[] a = new Integer[rnd.nextInt(maxSize) + 1];
for (int i = 0; i < a.length; i++) {
- a[i] = Integer.valueOf(random().nextInt(2));
+ a[i] = Integer.valueOf(rnd.nextInt(2));
}
return a;
}
@@ -223,14 +227,15 @@ public class TestArrayUtil extends LuceneTestCase {
}
public void testMergeSortStability() {
+ final Random rnd = random();
Item[] items = new Item[100];
for (int i = 0; i < items.length; i++) {
// half of the items have value but same order. The value of this items is sorted,
// so they should always be in order after sorting.
// The other half has defined order, but no (-1) value (they should appear after
// all above, when sorted).
- final boolean equal = random().nextBoolean();
- items[i] = new Item(equal ? (i+1) : -1, equal ? 0 : (random().nextInt(1000)+1));
+ final boolean equal = rnd.nextBoolean();
+ items[i] = new Item(equal ? (i+1) : -1, equal ? 0 : (rnd.nextInt(1000)+1));
}
if (VERBOSE) System.out.println("Before: " + Arrays.toString(items));
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestCollectionUtil.java b/lucene/core/src/test/org/apache/lucene/util/TestCollectionUtil.java
index f6d4016a1d0..819ffe8d44e 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestCollectionUtil.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestCollectionUtil.java
@@ -22,13 +22,15 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
+import java.util.Random;
public class TestCollectionUtil extends LuceneTestCase {
private List<Integer> createRandomList(int maxSize) {
- final Integer[] a = new Integer[random().nextInt(maxSize) + 1];
+ final Random rnd = random();
+ final Integer[] a = new Integer[rnd.nextInt(maxSize) + 1];
for (int i = 0; i < a.length; i++) {
- a[i] = Integer.valueOf(random().nextInt(a.length));
+ a[i] = Integer.valueOf(rnd.nextInt(a.length));
}
return Arrays.asList(a);
}