mirror of https://github.com/apache/lucene.git
add warnings to tests that arent really randomized
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1145701 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ea262d0ddb
commit
a540f48f07
|
@ -352,6 +352,7 @@ public abstract class LuceneTestCase extends Assert {
|
|||
state = State.INITIAL;
|
||||
staticSeed = "random".equals(TEST_SEED) ? seedRand.nextLong() : TwoLongs.fromString(TEST_SEED).l1;
|
||||
random.setSeed(staticSeed);
|
||||
random.initialized = true;
|
||||
tempDirs.clear();
|
||||
stores = Collections.synchronizedMap(new IdentityHashMap<MockDirectoryWrapper,StackTraceElement[]>());
|
||||
|
||||
|
@ -494,6 +495,8 @@ public abstract class LuceneTestCase extends Assert {
|
|||
}
|
||||
}
|
||||
}
|
||||
random.setSeed(0L);
|
||||
random.initialized = false;
|
||||
}
|
||||
|
||||
private static boolean testsFailed; /* true if any tests failed */
|
||||
|
@ -1366,7 +1369,26 @@ public abstract class LuceneTestCase extends Assert {
|
|||
private long seed;
|
||||
|
||||
private static final Random seedRand = new Random();
|
||||
protected static final Random random = new Random(0);
|
||||
protected static final SmartRandom random = new SmartRandom(0);
|
||||
|
||||
public static class SmartRandom extends Random {
|
||||
boolean initialized;
|
||||
|
||||
SmartRandom(long seed) {
|
||||
super(seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int next(int bits) {
|
||||
if (!initialized) {
|
||||
System.err.println("!!! WARNING: test is using random from static initializer !!!");
|
||||
Thread.dumpStack();
|
||||
// I wish, but it causes JRE crashes
|
||||
// throw new IllegalStateException("you cannot use this random from a static initializer in your test");
|
||||
}
|
||||
return super.next(bits);
|
||||
}
|
||||
}
|
||||
|
||||
private String name = "<unknown>";
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.apache.lucene.util.BytesRef;
|
|||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util.Version;
|
||||
import org.apache.lucene.util._TestUtil;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
// TODO: test multiple codecs here?
|
||||
|
||||
|
@ -67,13 +68,18 @@ import org.apache.lucene.util._TestUtil;
|
|||
public class TestCodecs extends LuceneTestCase {
|
||||
private static String[] fieldNames = new String[] {"one", "two", "three", "four"};
|
||||
|
||||
private final static int NUM_TEST_ITER = atLeast(20);
|
||||
private static int NUM_TEST_ITER;
|
||||
private final static int NUM_TEST_THREADS = 3;
|
||||
private final static int NUM_FIELDS = 4;
|
||||
private final static int NUM_TERMS_RAND = 50; // must be > 16 to test skipping
|
||||
private final static int DOC_FREQ_RAND = 500; // must be > 16 to test skipping
|
||||
private final static int TERM_DOC_FREQ_RAND = 20;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
NUM_TEST_ITER = atLeast(20);
|
||||
}
|
||||
|
||||
class FieldData implements Comparable {
|
||||
final FieldInfo fieldInfo;
|
||||
final TermData[] terms;
|
||||
|
|
Loading…
Reference in New Issue