Skip to content

Apache Lucene open-source search software

warn if you fix a random seed (so we dont leave the test de-randomized)

Robert Muir2fe80c49e6f5
diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
index 8a7bfff97cb..e214f388663 100644
--- a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
+++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
@@ -247,7 +247,8 @@ public abstract class LuceneTestCase extends TestCase {
if (seed != null) {
throw new IllegalStateException("please call LuceneTestCase.newRandom only once per test");
}
- return newRandom(seedRnd.nextLong());
+ this.seed = Long.valueOf(seedRnd.nextLong());
+ return new Random(seed);
}
/**
@@ -259,6 +260,7 @@ public abstract class LuceneTestCase extends TestCase {
if (this.seed != null) {
throw new IllegalStateException("please call LuceneTestCase.newRandom only once per test");
}
+ System.out.println("WARNING: random seed of testcase '" + getName() + "' is fixed to: " + seed);
this.seed = Long.valueOf(seed);
return new Random(seed);
}
diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java
index dedc0de579d..3fa12efd2cb 100644
--- a/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java
+++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java
@@ -323,7 +323,8 @@ public class LuceneTestCaseJ4 {
if (seed != null) {
throw new IllegalStateException("please call LuceneTestCaseJ4.newRandom only once per test");
}
- return newRandom(seedRnd.nextLong());
+ this.seed = Long.valueOf(seedRnd.nextLong());
+ return new Random(seed);
}
/**
@@ -335,6 +336,7 @@ public class LuceneTestCaseJ4 {
if (this.seed != null) {
throw new IllegalStateException("please call LuceneTestCaseJ4.newRandom only once per test");
}
+ System.out.println("WARNING: random seed of testcase '" + getName() + "' is fixed to: " + seed);
this.seed = Long.valueOf(seed);
return new Random(seed);
}
@@ -350,7 +352,9 @@ public class LuceneTestCaseJ4 {
* .
*/
public static Random newStaticRandom(Class<? extends LuceneTestCaseJ4> clazz) {
- return newStaticRandom(clazz, seedRnd.nextLong());
+ Long seed = seedRnd.nextLong();
+ staticSeeds.put(clazz, seed);
+ return new Random(seed);
}
/**
@@ -361,6 +365,7 @@ public class LuceneTestCaseJ4 {
*/
public static Random newStaticRandom(Class<? extends LuceneTestCaseJ4> clazz, long seed) {
staticSeeds.put(clazz, Long.valueOf(seed));
+ System.out.println("WARNING: random static seed of testclass '" + clazz + "' is fixed to: " + seed);
return new Random(seed);
}