From 94848afc6574ef3e0baace5a2f6a7cb0f6fb486b Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Tue, 14 Dec 2010 16:24:16 +0000 Subject: [PATCH] improve the random handling in these tests git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1049144 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/index/TestIndexWriterExceptions.java | 4 ++-- .../apache/lucene/index/TestIndexWriterReader.java | 3 ++- .../lucene/index/TestNRTReaderWithThreads.java | 6 +++--- .../apache/lucene/index/TestPerSegmentDeletes.java | 2 +- .../test/org/apache/lucene/util/TestSetOnce.java | 14 ++++++-------- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java index ce7a0e7cc70..270eda7914e 100644 --- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java +++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java @@ -50,7 +50,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase { IndexWriter writer; - final Random r = new java.util.Random(47); + final Random r = new Random(random.nextLong()); volatile Throwable failure; public IndexerThread(int i, IndexWriter writer) { @@ -128,7 +128,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase { ThreadLocal doFail = new ThreadLocal(); private class MockIndexWriter extends IndexWriter { - Random r = new java.util.Random(17); + Random r = new Random(random.nextLong()); public MockIndexWriter(Directory dir, IndexWriterConfig conf) throws IOException { super(dir, conf); diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java index 5c357927e33..0c961193ab3 100644 --- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java +++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java @@ -837,10 +837,11 @@ public class TestIndexWriterReader extends LuceneTestCase { final Thread[] threads = new Thread[NUM_THREAD]; for(int i=0;i set; boolean success = false; + final Random RAND; + + public SetOnceThread(Random random) { + RAND = new Random(random.nextLong()); + } @Override public void run() { @@ -46,8 +51,6 @@ public class TestSetOnce extends LuceneTestCase { } } - private static final Random RAND = new Random(); - @Test public void testEmptyCtor() throws Exception { SetOnce set = new SetOnce(); @@ -71,15 +74,10 @@ public class TestSetOnce extends LuceneTestCase { @Test public void testSetMultiThreaded() throws Exception { - long seed = RAND.nextLong(); - RAND.setSeed(seed); - if (VERBOSE) { - System.out.println("testSetMultiThreaded: seed=" + seed); - } final SetOnce set = new SetOnce(); SetOnceThread[] threads = new SetOnceThread[10]; for (int i = 0; i < threads.length; i++) { - threads[i] = new SetOnceThread(); + threads[i] = new SetOnceThread(random); threads[i].setName("t-" + (i+1)); threads[i].set = set; }