Index: lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java (revision 998682) +++ lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java (working copy) @@ -34,7 +34,6 @@ import java.io.IOException; import java.text.Collator; import java.util.Locale; -import java.util.Random; import junit.framework.Assert; @@ -60,8 +59,6 @@ "B 2 4 5 6", "Y 3 5 6", null, "C 3 6", "X 4 5 6" }; - Random random = newStaticRandom(TestMultiTermConstantScore.class); - small = newDirectory(random); RandomIndexWriter writer = new RandomIndexWriter(random, small, new MockAnalyzer(MockTokenizer.WHITESPACE, false)); Index: lucene/src/test/org/apache/lucene/search/spans/TestBasics.java =================================================================== --- lucene/src/test/org/apache/lucene/search/spans/TestBasics.java (revision 998682) +++ lucene/src/test/org/apache/lucene/search/spans/TestBasics.java (working copy) @@ -18,7 +18,6 @@ */ import java.io.IOException; -import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; @@ -65,7 +64,6 @@ @BeforeClass public static void beforeClass() throws Exception { - Random random = newStaticRandom(TestBasics.class); directory = newDirectory(random); RandomIndexWriter writer = new RandomIndexWriter(random, directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true)) Index: lucene/src/test/org/apache/lucene/search/TestSubScorerFreqs.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestSubScorerFreqs.java (revision 998682) +++ lucene/src/test/org/apache/lucene/search/TestSubScorerFreqs.java (working copy) @@ -41,7 +41,6 @@ @BeforeClass public static void makeIndex() throws Exception { dir = new RAMDirectory(); - Random random = newStaticRandom(TestSubScorerFreqs.class); RandomIndexWriter w = new RandomIndexWriter( random, dir); // make sure we have more than one segment occationally Index: lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java =================================================================== --- lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java (revision 998682) +++ lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java (working copy) @@ -94,7 +94,6 @@ @BeforeClass public static void beforeClassBaseTestRangeFilter() throws Exception { - Random random = newStaticRandom(BaseTestRangeFilter.class); signedIndexDir = new TestIndex(random, Integer.MAX_VALUE, Integer.MIN_VALUE, true); unsignedIndexDir = new TestIndex(random, Integer.MAX_VALUE, 0, false); signedIndexReader = build(random, signedIndexDir); Index: lucene/src/test/org/apache/lucene/search/TestBoolean2.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestBoolean2.java (revision 998682) +++ lucene/src/test/org/apache/lucene/search/TestBoolean2.java (working copy) @@ -55,7 +55,6 @@ @BeforeClass public static void beforeClass() throws Exception { - Random random = newStaticRandom(TestBoolean2.class); directory = newDirectory(random); RandomIndexWriter writer= new RandomIndexWriter(random, directory); for (int i = 0; i < docFields.length; i++) { Index: lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java (revision 998682) +++ lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java (working copy) @@ -17,8 +17,6 @@ * limitations under the License. */ -import java.util.Random; - import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -49,11 +47,9 @@ private static Directory directory = null; private static IndexReader reader = null; private static IndexSearcher searcher = null; - private static Random random = null; @BeforeClass public static void beforeClass() throws Exception { - random = newStaticRandom(TestNumericRangeQuery32.class); directory = newDirectory(random); RandomIndexWriter writer = new RandomIndexWriter(random, directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()) Index: lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java (revision 998682) +++ lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java (working copy) @@ -17,8 +17,6 @@ * limitations under the License. */ -import java.util.Random; - import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -48,11 +46,9 @@ private static Directory directory = null; private static IndexReader reader = null; private static IndexSearcher searcher = null; - private static Random random = null; @BeforeClass public static void beforeClass() throws Exception { - random = newStaticRandom(TestNumericRangeQuery64.class); directory = newDirectory(random); RandomIndexWriter writer = new RandomIndexWriter(random, directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()) Index: lucene/src/test/org/apache/lucene/util/LuceneTestCase.java =================================================================== --- lucene/src/test/org/apache/lucene/util/LuceneTestCase.java (revision 999016) +++ lucene/src/test/org/apache/lucene/util/LuceneTestCase.java (working copy) @@ -217,7 +217,7 @@ final boolean codecHasParam; int codecParam = 0; if (codec.equals("random")) { - codec = pickRandomCodec(seedRnd); + codec = pickRandomCodec(random); codecHasParam = false; } else { Matcher m = codecWithParam.matcher(codec); @@ -241,10 +241,10 @@ } swapCodec(new MockSepCodec()); - swapCodec(new PulsingCodec(codecHasParam && "Pulsing".equals(codec) ? codecParam : _TestUtil.nextInt(seedRnd, 1, 20))); - swapCodec(new MockFixedIntBlockCodec(codecHasParam && "MockFixedIntBlock".equals(codec) ? codecParam : _TestUtil.nextInt(seedRnd, 1, 2000))); + swapCodec(new PulsingCodec(codecHasParam && "Pulsing".equals(codec) ? codecParam : _TestUtil.nextInt(random, 1, 20))); + swapCodec(new MockFixedIntBlockCodec(codecHasParam && "MockFixedIntBlock".equals(codec) ? codecParam : _TestUtil.nextInt(random, 1, 2000))); // baseBlockSize cannot be over 127: - swapCodec(new MockVariableIntBlockCodec(codecHasParam && "MockVariableIntBlock".equals(codec) ? codecParam : _TestUtil.nextInt(seedRnd, 1, 127))); + swapCodec(new MockVariableIntBlockCodec(codecHasParam && "MockVariableIntBlock".equals(codec) ? codecParam : _TestUtil.nextInt(random, 1, 127))); return cp.lookup(codec); } @@ -279,13 +279,14 @@ @BeforeClass public static void beforeClassLuceneTestCaseJ4() { + random.setSeed(seed); stores = Collections.synchronizedMap(new IdentityHashMap()); codec = installTestCodecs(); savedLocale = Locale.getDefault(); - locale = TEST_LOCALE.equals("random") ? randomLocale(seedRnd) : localeForName(TEST_LOCALE); + locale = TEST_LOCALE.equals("random") ? randomLocale(random) : localeForName(TEST_LOCALE); Locale.setDefault(locale); savedTimeZone = TimeZone.getDefault(); - timeZone = TEST_TIMEZONE.equals("random") ? randomTimeZone(seedRnd) : TimeZone.getTimeZone(TEST_TIMEZONE); + timeZone = TEST_TIMEZONE.equals("random") ? randomTimeZone(random) : TimeZone.getTimeZone(TEST_TIMEZONE); TimeZone.setDefault(timeZone); testsFailed = false; } @@ -337,8 +338,7 @@ public void setUp() throws Exception { Assert.assertFalse("ensure your tearDown() calls super.tearDown()!!!", setup); setup = true; - seed = Long.valueOf(TEST_SEED.equals("random") ? seedRnd.nextLong() : Long.parseLong(TEST_SEED)); - random = new Random(seed); + random.setSeed(seed); savedUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { @@ -350,7 +350,6 @@ ConcurrentMergeScheduler.setTestMode(); savedBoolMaxClauseCount = BooleanQuery.getMaxClauseCount(); - seed = null; } @@ -512,34 +511,6 @@ dumpIterator(label, iter, stream); } - private static final Map,Long> staticSeeds = - Collections.synchronizedMap(new WeakHashMap,Long>()); - - /** - * Returns a {@link Random} instance for generating random numbers from a beforeclass - * annotated method. - * The random seed is logged during test execution and printed to System.out on any failure - * for reproducing the test using {@link #newStaticRandom(Class, long)} with the recorded seed - * . - */ - public static Random newStaticRandom(Class clazz) { - Long seed = seedRnd.nextLong(); - staticSeeds.put(clazz, seed); - return new Random(seed); - } - - /** - * Returns a {@link Random} instance for generating random numbers from a beforeclass - * annotated method. - * If an error occurs in the test that is not reproducible, you can use this method to - * initialize the number generator with the seed that was printed out during the failing test. - */ - public static Random newStaticRandom(Class 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); - } - /** create a new index writer config with random defaults */ public IndexWriterConfig newIndexWriterConfig(Version v, Analyzer a) { return newIndexWriterConfig(random, v, a); @@ -755,27 +726,19 @@ // We get here from InterceptTestCaseEvents on the 'failed' event.... public void reportAdditionalFailureInfo() { - Long staticSeed = staticSeeds.get(getClass()); - if (staticSeed != null) { - System.out.println("NOTE: random static seed of testclass '" + getName() + "' was: " + staticSeed); - } - System.out.println("NOTE: random codec of testcase '" + getName() + "' was: " + codec); if (TEST_LOCALE.equals("random")) System.out.println("NOTE: random locale of testcase '" + getName() + "' was: " + locale); if (TEST_TIMEZONE.equals("random")) // careful to not deliver NPE here in case they forgot super.setUp System.out.println("NOTE: random timezone of testcase '" + getName() + "' was: " + (timeZone == null ? "(null)" : timeZone.getID())); - if (seed != null) { + if (TEST_SEED.equals("random")) { System.out.println("NOTE: random seed of testcase '" + getName() + "' was: " + seed); } } // recorded seed - protected Long seed = null; - protected Random random = null; - - // static members - private static final Random seedRnd = new Random(); + private static final long seed = TEST_SEED.equals("random") ? System.currentTimeMillis() : Long.parseLong(TEST_SEED); + protected static final Random random = new Random(seed); private String name = ""; Index: lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.java =================================================================== --- lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.java (revision 998682) +++ lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.java (working copy) @@ -36,11 +36,9 @@ private static IndexWriter writer =null; private static Directory dir = null; private static IndexReader reader =null; - private static Random random = null; @BeforeClass public static void setUpClass() throws Exception { - random = newStaticRandom(TestHighFreqTerms.class); dir = newDirectory(random); writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)) Index: lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java =================================================================== --- lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java (revision 998682) +++ lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java (working copy) @@ -17,8 +17,6 @@ * limitations under the License. */ -import java.util.Random; - import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -41,7 +39,6 @@ @BeforeClass public static void beforeClass() throws Exception { // construct an index - Random random = newStaticRandom(TestRemoteCachingWrapperFilter.class); indexStore = newDirectory(random); IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())); Index: lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java =================================================================== --- lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java (revision 998682) +++ lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java (working copy) @@ -83,7 +83,6 @@ // create an index of all the documents, or just the x, or just the y documents @BeforeClass public static void beforeClass() throws Exception { - Random random = newStaticRandom(TestRemoteSort.class); indexStore = newDirectory(random); IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()) Index: lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.java =================================================================== --- lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.java (revision 998682) +++ lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.java (working copy) @@ -29,7 +29,6 @@ import static org.junit.Assert.*; import java.util.Collections; -import java.util.Random; import java.util.Set; import java.util.HashSet; @@ -40,7 +39,6 @@ @BeforeClass public static void beforeClass() throws Exception { // construct an index - Random random = newStaticRandom(TestRemoteSearchable.class); indexStore = newDirectory(random); IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));