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

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1452100 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2013-03-03 18:59:40 +00:00
parent 888f626b40
commit 7a28af4462
2 changed files with 18 additions and 11 deletions

View File

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

View File

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