lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r741311 - in /lucene/java/trunk: contrib/db/ contrib/db/bdb-je/ contrib/db/bdb-je/src/test/org/apache/lucene/store/je/ contrib/db/bdb/ contrib/db/bdb/src/test/org/apache/lucene/store/db/ contrib/queries/src/test/org/apache/lucene/search/tri...
Date Thu, 05 Feb 2009 21:53:41 GMT
Author: mikemccand
Date: Thu Feb  5 21:53:40 2009
New Revision: 741311

URL: http://svn.apache.org/viewvc?rev=741311&view=rev
Log:
LUCENE-1535: use random seed for randomness, but print the seed on failure for reproducibility

Modified:
    lucene/java/trunk/contrib/db/bdb-je/build.xml
    lucene/java/trunk/contrib/db/bdb-je/src/test/org/apache/lucene/store/je/JEStoreTest.java
    lucene/java/trunk/contrib/db/bdb/build.xml
    lucene/java/trunk/contrib/db/bdb/src/test/org/apache/lucene/store/db/DbStoreTest.java
    lucene/java/trunk/contrib/db/build.xml
    lucene/java/trunk/contrib/queries/src/test/org/apache/lucene/search/trie/TestTrieRangeQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestAtomicUpdate.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestByteSlices.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderReopen.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestLazyBug.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestPayloads.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing2.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestTermdocPerf.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestTransactions.java
    lucene/java/trunk/src/test/org/apache/lucene/search/BaseTestRangeFilter.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestBoolean2.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestCustomSearcherSort.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestScorerPerf.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestStressSort.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestThreadSafe.java
    lucene/java/trunk/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
    lucene/java/trunk/src/test/org/apache/lucene/store/TestWindowsMMap.java
    lucene/java/trunk/src/test/org/apache/lucene/util/LuceneTestCase.java
    lucene/java/trunk/src/test/org/apache/lucene/util/TestOpenBitSet.java
    lucene/java/trunk/src/test/org/apache/lucene/util/TestPriorityQueue.java
    lucene/java/trunk/src/test/org/apache/lucene/util/TestSmallFloat.java

Modified: lucene/java/trunk/contrib/db/bdb-je/build.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/db/bdb-je/build.xml?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/contrib/db/bdb-je/build.xml (original)
+++ lucene/java/trunk/contrib/db/bdb-je/build.xml Thu Feb  5 21:53:40 2009
@@ -23,6 +23,13 @@
 	
   <import file="../../contrib-build.xml" />
 
+  <path id="test.classpath">
+    <path refid="classpath"/>
+    <pathelement location="../../../build/classes/test/"/>
+    <path refid="junit-path"/>
+    <pathelement location="${build.dir}/classes/java"/>
+  </path>
+
   <target name="get-je-jar" unless="je.jar.exists">
     <mkdir dir="lib" />
     <get src="http://download.oracle.com/berkeley-db/je-${je.version}.zip"

Modified: lucene/java/trunk/contrib/db/bdb-je/src/test/org/apache/lucene/store/je/JEStoreTest.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/db/bdb-je/src/test/org/apache/lucene/store/je/JEStoreTest.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/contrib/db/bdb-je/src/test/org/apache/lucene/store/je/JEStoreTest.java (original)
+++ lucene/java/trunk/contrib/db/bdb-je/src/test/org/apache/lucene/store/je/JEStoreTest.java Thu Feb  5 21:53:40 2009
@@ -23,11 +23,10 @@
 import java.util.Date;
 import java.util.Random;
 
-import junit.framework.TestCase;
-
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.LuceneTestCase;
 
 import com.sleepycat.je.Cursor;
 import com.sleepycat.je.Database;
@@ -46,7 +45,7 @@
  * Adapted from Andi Vajda's org.apache.lucene.db.DbStoreTest.
  *
  */
-public class JEStoreTest extends TestCase {
+public class JEStoreTest extends LuceneTestCase {
     protected File dbHome = new File(System.getProperty("java.io.tmpdir"),"index");
 
     protected Environment env;
@@ -112,7 +111,9 @@
         final int count = 250;
         final int LENGTH_MASK = 0xffff;
 
-        Random gen = new Random(1251971);
+        Random r = newRandom();
+        final long seed = r.nextLong();
+        Random gen = new Random(seed);
         int totalLength = 0;
         int duration;
         Date end;
@@ -171,7 +172,7 @@
             txn = env.beginTransaction(null, null);
             store = new JEDirectory(txn, index, blocks);
 
-            gen = new Random(1251971);
+            gen = new Random(seed);
             start = new Date();
 
             for (int i = 0; i < count; i++) {
@@ -220,7 +221,7 @@
             txn = env.beginTransaction(null, null);
             store = new JEDirectory(txn, index, blocks);
 
-            gen = new Random(1251971);
+            gen = new Random(seed);
             start = new Date();
 
             for (int i = 0; i < count; i++) {
@@ -257,7 +258,9 @@
         final int count = 250;
         final int LENGTH_MASK = 0xffff;
 
-        Random gen = new Random(1251971);
+        Random r = newRandom();
+        final long seed = r.nextLong();
+        Random gen = new Random(seed);
         int totalLength = 0;
         int duration;
         Date end;
@@ -316,7 +319,7 @@
             txn = env.beginTransaction(null, null);
             store = new JEDirectory(txn, index, blocks);
 
-            gen = new Random(1251971);
+            gen = new Random(seed);
             start = new Date();
 
             for (int i = 0; i < count; i++) {
@@ -357,7 +360,7 @@
             txn = env.beginTransaction(null, null);
             store = new JEDirectory(txn, index, blocks);
 
-            gen = new Random(1251971);
+            gen = new Random(seed);
             start = new Date();
 
             for (int i = 0; i < count; i++) {
@@ -412,7 +415,7 @@
             txn = env.beginTransaction(null, null);
             store = new JEDirectory(txn, index, blocks);
 
-            gen = new Random(1251971);
+            gen = new Random(seed);
             start = new Date();
 
             for (int i = 0; i < count; i++) {
@@ -486,7 +489,9 @@
         final int count = 250;
         final int LENGTH_MASK = 0xffff;
 
-        Random gen = new Random(1251971);
+        Random r = newRandom();
+        final long seed = r.nextLong();
+        Random gen = new Random(seed);
         int totalLength = 0;
         int duration;
         Date end;
@@ -543,7 +548,7 @@
             txn = env.beginTransaction(null, null);
             store = new JEDirectory(txn, index, blocks);
 
-            gen = new Random(1251971);
+            gen = new Random(seed);
             start = new Date();
 
             for (int i = 0; i < count; i++) {
@@ -593,7 +598,7 @@
             txn = env.beginTransaction(null, null);
             store = new JEDirectory(txn, index, blocks);
 
-            gen = new Random(1251971);
+            gen = new Random(seed);
             start = new Date();
             for (int i = 0; i < count; i++) {
                 String name = i + ".dat";

Modified: lucene/java/trunk/contrib/db/bdb/build.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/db/bdb/build.xml?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/contrib/db/bdb/build.xml (original)
+++ lucene/java/trunk/contrib/db/bdb/build.xml Thu Feb  5 21:53:40 2009
@@ -23,6 +23,13 @@
 
   <import file="../../contrib-build.xml" />
 
+  <path id="test.classpath">
+    <path refid="classpath"/>
+    <pathelement location="../../../build/classes/test/"/>
+    <path refid="junit-path"/>
+    <pathelement location="${build.dir}/classes/java"/>
+  </path>
+
   <target name="get-db-jar" unless="db.jar.exists">
     <mkdir dir="lib" />
     <get src="http://downloads.osafoundation.org/db/db-${db.version}.jar"

Modified: lucene/java/trunk/contrib/db/bdb/src/test/org/apache/lucene/store/db/DbStoreTest.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/db/bdb/src/test/org/apache/lucene/store/db/DbStoreTest.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/contrib/db/bdb/src/test/org/apache/lucene/store/db/DbStoreTest.java (original)
+++ lucene/java/trunk/contrib/db/bdb/src/test/org/apache/lucene/store/db/DbStoreTest.java Thu Feb  5 21:53:40 2009
@@ -24,8 +24,6 @@
 import java.io.File;
 import java.io.IOException;
 
-import junit.framework.TestCase;
-
 import com.sleepycat.db.EnvironmentConfig;
 import com.sleepycat.db.Environment;
 import com.sleepycat.db.Transaction;
@@ -37,13 +35,14 @@
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.LuceneTestCase;
 
 /**
  * Tests {@link DbDirectory}.
  *
  * Adapted from org.apache.lucene.StoreTest with larger files and random bytes.
  */
-public class DbStoreTest extends TestCase {
+public class DbStoreTest extends LuceneTestCase {
     protected File dbHome = new File(System.getProperty("java.io.tmpdir"),"index");
     protected Environment env;
     protected Database index, blocks;
@@ -117,7 +116,10 @@
         final int count = 250;
         final int LENGTH_MASK = 0xffff;
 
-        Random gen = new Random(1251971);
+        Random r = newRandom();
+        final long seed = r.nextLong();
+
+        Random gen = new Random(seed);
         int totalLength = 0;
         int duration;
         Date end;
@@ -177,7 +179,7 @@
             txn = env.beginTransaction(null, null);
             store = new DbDirectory(txn, index, blocks);
 
-            gen = new Random(1251971);
+            gen = new Random(seed);
             start = new Date();
 
             for (int i = 0; i < count; i++) {
@@ -227,7 +229,7 @@
             txn = env.beginTransaction(null, null);
             store = new DbDirectory(txn, index, blocks);
 
-            gen = new Random(1251971);
+            gen = new Random(seed);
             start = new Date();
 
             for (int i = 0; i < count; i++) {
@@ -267,7 +269,10 @@
         final int count = 250;
         final int LENGTH_MASK = 0xffff;
 
-        Random gen = new Random(1251971);
+        Random r = newRandom();
+        final long seed = r.nextLong();
+
+        Random gen = new Random(seed);
         int totalLength = 0;
         int duration;
         Date end;
@@ -325,7 +330,7 @@
             txn = env.beginTransaction(null, null);
             store = new DbDirectory(txn, index, blocks);
 
-            gen = new Random(1251971);
+            gen = new Random(seed);
             start = new Date();
 
             for (int i = 0; i < count; i++) {
@@ -376,7 +381,7 @@
             txn = env.beginTransaction(null, null);
             store = new DbDirectory(txn, index, blocks);
 
-            gen = new Random(1251971);
+            gen = new Random(seed);
             start = new Date();
 
             for (int i = 0; i < count; i++) {

Modified: lucene/java/trunk/contrib/db/build.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/db/build.xml?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/contrib/db/build.xml (original)
+++ lucene/java/trunk/contrib/db/build.xml Thu Feb  5 21:53:40 2009
@@ -64,5 +64,6 @@
     <ant dir="bdb-je" target="javadocs" />
   </target>  	
 
+
 	
 </project>

Modified: lucene/java/trunk/contrib/queries/src/test/org/apache/lucene/search/trie/TestTrieRangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queries/src/test/org/apache/lucene/search/trie/TestTrieRangeQuery.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queries/src/test/org/apache/lucene/search/trie/TestTrieRangeQuery.java (original)
+++ lucene/java/trunk/contrib/queries/src/test/org/apache/lucene/search/trie/TestTrieRangeQuery.java Thu Feb  5 21:53:40 2009
@@ -36,11 +36,10 @@
 {
   private static final long distance=66666;
   
-  private static Random rnd=new Random();
-  private static RAMDirectory directory;
-  private static IndexSearcher searcher;
+  private static final RAMDirectory directory;
+  private static final IndexSearcher searcher;
   static {
-    try {
+    try {    
       directory = new RAMDirectory();
       IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(),
       true, MaxFieldLength.UNLIMITED);
@@ -136,6 +135,7 @@
   }
   
   private void testRandomTrieAndClassicRangeQuery(final TrieUtils variant) throws Exception {
+    final Random rnd=newRandom();
     String field="field"+variant.TRIE_BITS;
     // 50 random tests, the tests may also return 0 results, if min>max, but this is ok
     for (int i=0; i<50; i++) {
@@ -185,6 +185,7 @@
   }
   
   private void testRangeSplit(final TrieUtils variant) throws Exception {
+    final Random rnd=newRandom();
     String field="ascfield"+variant.TRIE_BITS;
     // 50 random tests
     for (int i=0; i<50; i++) {
@@ -225,6 +226,7 @@
   }
   
   private void testSorting(final TrieUtils variant) throws Exception {
+    final Random rnd=newRandom();
     String field="field"+variant.TRIE_BITS;
     // 10 random tests, the index order is ascending,
     // so using a reverse sort field should retun descending documents

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java Thu Feb  5 21:53:40 2009
@@ -329,6 +329,9 @@
 
   /** Used for testing */
   public static boolean anyUnhandledExceptions() {
+    if (allInstances == null) {
+      throw new RuntimeException("setTestMode() was not called; often this is because your test case's setUp method fails to call super.setUp in LuceneTestCase");
+    }
     synchronized(allInstances) {
       final int count = allInstances.size();
       // Make sure all outstanding threads are done so we see

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestAtomicUpdate.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestAtomicUpdate.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestAtomicUpdate.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestAtomicUpdate.java Thu Feb  5 21:53:40 2009
@@ -29,7 +29,7 @@
 
 public class TestAtomicUpdate extends LuceneTestCase {
   private static final Analyzer ANALYZER = new SimpleAnalyzer();
-  private static final Random RANDOM = new Random();
+  private Random RANDOM;
 
   public class MockIndexWriter extends IndexWriter {
 
@@ -179,7 +179,7 @@
     FSDirectory.
   */
   public void testAtomicUpdates() throws Exception {
-
+    RANDOM = newRandom();
     Directory directory;
 
     // First in a RAM directory:

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestByteSlices.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestByteSlices.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestByteSlices.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestByteSlices.java Thu Feb  5 21:53:40 2009
@@ -52,7 +52,7 @@
     int[] uptos = new int[NUM_STREAM];
     int[] counters = new int[NUM_STREAM];
 
-    Random r = new Random(1);
+    Random r = newRandom();
 
     ByteSliceReader reader = new ByteSliceReader();
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderReopen.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderReopen.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderReopen.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderReopen.java Thu Feb  5 21:53:40 2009
@@ -710,7 +710,7 @@
     final List readers = Collections.synchronizedList(new ArrayList());
     IndexReader firstReader = IndexReader.open(dir);
     IndexReader reader = firstReader;
-    final Random rnd = new Random();
+    final Random rnd = newRandom();
     
     ReaderThread[] threads = new ReaderThread[n];
     final Set readersToClose = Collections.synchronizedSet(new HashSet());
@@ -1113,7 +1113,7 @@
 
     IndexReader lastReader = IndexReader.open(indexDir2);
     
-    Random r = new Random(42);
+    Random r = newRandom();
     for(int i=0;i<10;i++) {
       int mod = r.nextInt(5);
       modifyIndex(mod, lastReader.directory());

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java Thu Feb  5 21:53:40 2009
@@ -1411,7 +1411,7 @@
       RAMDirectory dir = new RAMDirectory();      
       IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
       writer.setRAMBufferSizeMB(0.5);
-      Random rand = new Random(31415);
+      Random rand = newRandom();
       for(int i=0;i<3;i++) {
         // First, docs where every term is unique (heavy on
         // Posting instances)
@@ -3442,7 +3442,7 @@
     }
   }
 
-  Random r = new Random();
+  Random r;
 
   private int nextInt(int lim) {
     return r.nextInt(lim);
@@ -3498,6 +3498,7 @@
 
   // LUCENE-510
   public void testRandomUnicodeStrings() throws Throwable {
+    r = newRandom();
 
     char[] buffer = new char[20];
     char[] expected = new char[20];
@@ -3525,6 +3526,7 @@
 
   // LUCENE-510
   public void testIncrementalUnicodeStrings() throws Throwable {
+    r = newRandom();
     char[] buffer = new char[20];
     char[] expected = new char[20];
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestLazyBug.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestLazyBug.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestLazyBug.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestLazyBug.java Thu Feb  5 21:53:40 2009
@@ -25,7 +25,6 @@
 import org.apache.lucene.store.RAMDirectory;
 
 import java.util.*;
-import java.lang.reflect.Array;
 
 
 /**
@@ -34,8 +33,6 @@
  */
 public class TestLazyBug extends LuceneTestCase {
 
-  public static int BASE_SEED = 13;
-
   public static int NUM_DOCS = 500;
   public static int NUM_FIELDS = 100;
 
@@ -62,10 +59,10 @@
       }
     };
   
-  private static Directory makeIndex() throws RuntimeException { 
+  private Directory makeIndex() throws RuntimeException { 
     Directory dir = new RAMDirectory();
     try {
-      Random r = new Random(BASE_SEED + 42) ; 
+      Random r = newRandom();
       Analyzer analyzer = new SimpleAnalyzer();
       IndexWriter writer = new IndexWriter(dir, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
       
@@ -89,12 +86,12 @@
     return dir;
   }
   
-  public static void doTest(int[] docs) throws Exception {
+  public void doTest(int[] docs) throws Exception {
     Directory dir = makeIndex();
     IndexReader reader = IndexReader.open(dir);
     for (int i = 0; i < docs.length; i++) {
       Document d = reader.document(docs[i], SELECTOR);
-      String trash = d.get(MAGIC_FIELD);
+      d.get(MAGIC_FIELD);
       
       List fields = d.getFields();
       for (Iterator fi = fields.iterator(); fi.hasNext(); ) {

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestPayloads.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestPayloads.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestPayloads.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestPayloads.java Thu Feb  5 21:53:40 2009
@@ -47,6 +47,7 @@
     
     // Simple tests to test the Payload class
     public void testPayload() throws Exception {
+        rnd = newRandom();
         byte[] testData = "This is a test!".getBytes();
         Payload payload = new Payload(testData);
         assertEquals("Wrong payload length.", testData.length, payload.length());
@@ -95,6 +96,7 @@
     // Tests whether the DocumentWriter and SegmentMerger correctly enable the
     // payload bit in the FieldInfo
     public void testPayloadFieldBit() throws Exception {
+        rnd = newRandom();
         Directory ram = new RAMDirectory();
         PayloadAnalyzer analyzer = new PayloadAnalyzer();
         IndexWriter writer = new IndexWriter(ram, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
@@ -151,6 +153,7 @@
 
     // Tests if payloads are correctly stored and loaded using both RamDirectory and FSDirectory
     public void testPayloadsEncoding() throws Exception {
+        rnd = newRandom();
         // first perform the test using a RAMDirectory
         Directory dir = new RAMDirectory();
         performTest(dir);
@@ -333,13 +336,13 @@
         
     }
     
-    private static Random rnd = new Random();
+    private Random rnd;
     
-    private static void generateRandomData(byte[] data) {
+    private void generateRandomData(byte[] data) {
         rnd.nextBytes(data);
     }
 
-    private static byte[] generateRandomData(int n) {
+    private byte[] generateRandomData(int n) {
         byte[] data = new byte[n];
         generateRandomData(data);
         return data;
@@ -473,6 +476,7 @@
     }
     
     public void testThreadSafety() throws IOException {
+        rnd = newRandom();
         final int numThreads = 5;
         final int numDocs = 50;
         final ByteArrayPool pool = new ByteArrayPool(numThreads, 5);
@@ -525,7 +529,7 @@
         assertEquals(pool.size(), numThreads);
     }
     
-    private static class PoolingPayloadTokenStream extends TokenStream {
+    private class PoolingPayloadTokenStream extends TokenStream {
         private byte[] payload;
         private boolean first;
         private ByteArrayPool pool;

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java Thu Feb  5 21:53:40 2009
@@ -28,7 +28,7 @@
 
 public class TestStressIndexing extends LuceneTestCase {
   private static final Analyzer ANALYZER = new SimpleAnalyzer();
-  private static final Random RANDOM = new Random();
+  private Random RANDOM;
 
   private static abstract class TimedThread extends Thread {
     boolean failed;
@@ -67,7 +67,7 @@
     }
   }
 
-  private static class IndexerThread extends TimedThread {
+  private class IndexerThread extends TimedThread {
     IndexWriter writer;
     public int count;
     int nextID;
@@ -164,6 +164,7 @@
     FSDirectory.
   */
   public void testStressIndexAndSearching() throws Exception {
+    RANDOM = newRandom();
 
     // RAMDir
     Directory directory = new MockRAMDirectory();

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing2.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing2.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing2.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing2.java Thu Feb  5 21:53:40 2009
@@ -36,7 +36,7 @@
   static int maxBufferedDocs=3;
   static int seed=0;
 
-  static Random r = new Random(0);
+  Random r;
 
   public class MockIndexWriter extends IndexWriter {
 
@@ -53,6 +53,7 @@
   }
 
   public void testRandom() throws Throwable {
+    r = newRandom();
     Directory dir1 = new MockRAMDirectory();
     // dir1 = FSDirectory.getDirectory("foofoofoo");
     Directory dir2 = new MockRAMDirectory();
@@ -69,6 +70,7 @@
 
   public void testMultiConfig() throws Throwable {
     // test lots of smaller different params together
+    r = newRandom();
     for (int i=0; i<100; i++) {  // increase iterations for better testing
       sameFieldOrder=r.nextBoolean();
       autoCommit=r.nextBoolean();

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestTermdocPerf.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestTermdocPerf.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestTermdocPerf.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestTermdocPerf.java Thu Feb  5 21:53:40 2009
@@ -58,7 +58,7 @@
 public class TestTermdocPerf extends LuceneTestCase {
 
   void addDocs(Directory dir, final int ndocs, String field, final String val, final int maxTF, final float percentDocs) throws IOException {
-    final Random random = new Random(0);
+    final Random random = newRandom();
     final RepeatingTokenStream ts = new RepeatingTokenStream(val);
 
     Analyzer analyzer = new Analyzer() {

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestTransactions.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestTransactions.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestTransactions.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestTransactions.java Thu Feb  5 21:53:40 2009
@@ -26,7 +26,7 @@
 
 public class TestTransactions extends LuceneTestCase
 {
-  private static final Random RANDOM = new Random();
+  private Random RANDOM;
   private static volatile boolean doFail;
 
   private class RandomFailure extends MockRAMDirectory.Failure {
@@ -68,7 +68,7 @@
     }
   }
 
-  private static class IndexerThread extends TimedThread {
+  private class IndexerThread extends TimedThread {
     Directory dir1;
     Directory dir2;
     Object lock;
@@ -183,6 +183,7 @@
   }
 
   public void testTransactions() throws Throwable {
+    RANDOM = newRandom();
     MockRAMDirectory dir1 = new MockRAMDirectory();
     MockRAMDirectory dir2 = new MockRAMDirectory();
     dir1.setPreventDoubleWrite(false);

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/BaseTestRangeFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/BaseTestRangeFilter.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/BaseTestRangeFilter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/BaseTestRangeFilter.java Thu Feb  5 21:53:40 2009
@@ -32,7 +32,7 @@
     public static final boolean F = false;
     public static final boolean T = true;
     
-    Random rand = new Random(101); // use a set seed to test is deterministic
+    protected Random rand;
 
     /** 
      * Collation interacts badly with hyphens -- collation produces different
@@ -83,10 +83,12 @@
 
     public BaseTestRangeFilter(String name) {
 	super(name);
+        rand = newRandom();
         build(signedIndex);
         build(unsignedIndex);
     }
     public BaseTestRangeFilter() {
+        rand = newRandom();
         build(signedIndex);
         build(unsignedIndex);
     }

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestBoolean2.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestBoolean2.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestBoolean2.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestBoolean2.java Thu Feb  5 21:53:40 2009
@@ -152,7 +152,7 @@
   }
 
   public void testRandomQueries() throws Exception {
-    Random rnd = new Random(0);
+    Random rnd = newRandom();
 
     String[] vals = {"w1","w2","w3","w4","w5","xx","yy","zzz"};
 
@@ -163,7 +163,7 @@
       // increase number of iterations for more complete testing
       for (int i=0; i<1000; i++) {
         int level = rnd.nextInt(3);
-        BooleanQuery q1 = randBoolQuery(new Random(i), level, field, vals, null);
+        BooleanQuery q1 = randBoolQuery(new Random(rnd.nextLong()), level, field, vals, null);
 
         // Can't sort by relevance since floating point numbers may not quite
         // match up.

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java Thu Feb  5 21:53:40 2009
@@ -296,7 +296,7 @@
     }
 
     public void testRandomQueries() throws Exception {
-      final Random rnd = new Random(0);
+      final Random rnd = newRandom();
 
       String field="data";
       String[] vals = {"1","2","3","4","5","6","A","Z","B","Y","Z","X","foo"};
@@ -319,9 +319,10 @@
       // increase number of iterations for more complete testing      
       for (int i=0; i<1000; i++) {
         int lev = rnd.nextInt(maxLev);
-        BooleanQuery q1 = TestBoolean2.randBoolQuery(new Random(i), lev, field, vals, null);
-        // BooleanQuery q2 = TestBoolean2.randBoolQuery(new Random(i), lev, field, vals, minNrCB);
-        BooleanQuery q2 = TestBoolean2.randBoolQuery(new Random(i), lev, field, vals, null);
+        final long seed = rnd.nextLong();
+        BooleanQuery q1 = TestBoolean2.randBoolQuery(new Random(seed), lev, field, vals, null);
+        // BooleanQuery q2 = TestBoolean2.randBoolQuery(new Random(seed), lev, field, vals, minNrCB);
+        BooleanQuery q2 = TestBoolean2.randBoolQuery(new Random(seed), lev, field, vals, null);
         // only set minimumNumberShouldMatch on the top level query since setting
         // at a lower level can change the score.
         minNrCB.postCreate(q2);

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestCustomSearcherSort.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestCustomSearcherSort.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestCustomSearcherSort.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestCustomSearcherSort.java Thu Feb  5 21:53:40 2009
@@ -25,7 +25,6 @@
 import java.util.TreeMap;
 
 import junit.framework.Test;
-import junit.framework.TestCase;
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
 
@@ -38,6 +37,7 @@
 import org.apache.lucene.index.Term;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util.LuceneTestCase;
 
 /**
  * Unit test for sorting code.
@@ -45,7 +45,7 @@
  */
 
 public class TestCustomSearcherSort
-extends TestCase
+extends LuceneTestCase
 implements Serializable {
 
     private Directory index = null;
@@ -71,7 +71,7 @@
 	throws IOException {
 	        RAMDirectory indexStore = new RAMDirectory ();
 	        IndexWriter writer = new IndexWriter (indexStore, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
-	        RandomGen random = new RandomGen();
+	        RandomGen random = new RandomGen(newRandom());
 	        for (int i=0; i<INDEX_SIZE; ++i) { // don't decrease; if to low the problem doesn't show up
 	        Document doc = new Document();
 	            if((i%5)!=0) { // some documents must not have an entry in the first sort field
@@ -93,8 +93,9 @@
 	 * Create index and query for test cases. 
 	 */
 	public void setUp() throws Exception {
-		index = getIndex();
-	    query = new TermQuery( new Term("content", "test"));
+          super.setUp();
+          index = getIndex();
+          query = new TermQuery( new Term("content", "test"));
 	}
 
 	/**
@@ -164,7 +165,6 @@
     ScoreDoc[] resultSort = searcher.search (query, null, 1000, sort).scoreDocs;
 		checkHits(resultSort, "Sort by custom criteria: "); // check for duplicates
 		
-        String lf = System.getProperty("line.separator", "\n");
         // besides the sorting both sets of hits must be identical
         for(int hitid=0;hitid<resultSort.length; ++hitid) {
             Integer idHitDate = new Integer(resultSort[hitid].doc); // document ID from sorted search
@@ -263,12 +263,15 @@
         }
     }
     private class RandomGen {
-        private Random random = new Random(0); // to generate some arbitrary contents
-	    private Calendar base = new GregorianCalendar(1980, 1, 1);
-
-	    // Just to generate some different Lucene Date strings
-        private String getLuceneDate() {
-    	    return DateTools.timeToString(base.getTimeInMillis() + random.nextInt() - Integer.MIN_VALUE, DateTools.Resolution.DAY);
-        }
+      RandomGen(Random random) {
+        this.random = random;
+      }
+      private Random random;
+      private Calendar base = new GregorianCalendar(1980, 1, 1);
+
+      // Just to generate some different Lucene Date strings
+      private String getLuceneDate() {
+        return DateTools.timeToString(base.getTimeInMillis() + random.nextInt() - Integer.MIN_VALUE, DateTools.Resolution.DAY);
+      }
     }
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestScorerPerf.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestScorerPerf.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestScorerPerf.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestScorerPerf.java Thu Feb  5 21:53:40 2009
@@ -38,7 +38,7 @@
  * @version $Id$
  */
 public class TestScorerPerf extends LuceneTestCase {
-  Random r = new Random(0);
+  Random r;
   boolean validate = true;  // set to false when doing performance testing
 
   BitSet[] sets;
@@ -306,6 +306,7 @@
 
   public void testConjunctions() throws Exception {
     // test many small sets... the bugs will be found on boundary conditions
+    r = newRandom();
     createDummySearcher();
     validate=true;
     sets=randBitSets(1000,10);
@@ -318,6 +319,7 @@
   int bigIter=10;
 
   public void testConjunctionPerf() throws Exception {
+    r = newRandom();
     createDummySearcher();
     validate=false;
     sets=randBitSets(32,1000000);
@@ -331,6 +333,7 @@
   }
 
   public void testNestedConjunctionPerf() throws Exception {
+    r = newRandom();
     createDummySearcher();
     validate=false;
     sets=randBitSets(32,1000000);
@@ -345,6 +348,7 @@
 
 
   public void testConjunctionTerms() throws Exception {
+    r = newRandom();
     validate=false;
     RAMDirectory dir = new RAMDirectory();
     System.out.println("Creating index");
@@ -361,6 +365,7 @@
   }
 
   public void testNestedConjunctionTerms() throws Exception {
+    r = newRandom();
     validate=false;    
     RAMDirectory dir = new RAMDirectory();
     System.out.println("Creating index");
@@ -378,6 +383,7 @@
 
 
   public void testSloppyPhrasePerf() throws Exception {
+    r = newRandom();
     validate=false;    
     RAMDirectory dir = new RAMDirectory();
     System.out.println("Creating index");

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java Thu Feb  5 21:53:40 2009
@@ -180,7 +180,7 @@
     return new IndexSearcher (indexStore);
   }
   
-  public static String getRandomNumberString(int num, int low, int high) {
+  public String getRandomNumberString(int num, int low, int high) {
     StringBuilder sb = new StringBuilder();
     for (int i = 0; i < num; i++) {
       sb.append(getRandomNumber(low, high));
@@ -188,11 +188,11 @@
     return sb.toString();
   }
   
-  public static String getRandomCharString(int num) {
+  public String getRandomCharString(int num) {
     return getRandomCharString(num, 48, 122);
   }
   
-  public static String getRandomCharString(int num, int start, int end) {
+  public String getRandomCharString(int num, int start, int end) {
     StringBuilder sb = new StringBuilder();
     for (int i = 0; i < num; i++) {
       sb.append(new Character((char) getRandomNumber(start, end)));
@@ -200,9 +200,9 @@
     return sb.toString();
   }
   
-  static Random r = new Random();
+  Random r;
   
-  public static int getRandomNumber(final int low, final int high) {
+  public int getRandomNumber(final int low, final int high) {
   
     int randInt = (Math.abs(r.nextInt()) % (high - low)) + low;
 
@@ -284,6 +284,7 @@
    * Test String sorting: small queue to many matches, multi field sort, reverse sort
    */
   public void testStringSort() throws IOException, ParseException {
+    r = newRandom();
     ScoreDoc[] result = null;
     IndexSearcher searcher = getFullStrings();
     sort.setSort(new SortField[] {

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestStressSort.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestStressSort.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestStressSort.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestStressSort.java Thu Feb  5 21:53:40 2009
@@ -35,7 +35,7 @@
   // NOTE: put seed in here to make failures
   // deterministic, but do not commit with a seed (to
   // better test):
-  private final Random r = new Random();
+  private Random r;
   private Directory dir, dir2, dir3;
   private IndexSearcher searcherMultiSegment;
   private IndexSearcher searcherFewSegment;
@@ -67,7 +67,6 @@
     // NOTE: put seed in here to make failures
     // deterministic, but do not commit with a seed (to
     // better test):
-    final Random r = new Random();
     dir = new MockRAMDirectory();
     IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
     writer.setMaxBufferedDocs(17);
@@ -180,6 +179,7 @@
   }
 
   public void testSort() throws Throwable {
+    r = newRandom();
 
     // reverse & not
     // all types

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestThreadSafe.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestThreadSafe.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestThreadSafe.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestThreadSafe.java Thu Feb  5 21:53:40 2009
@@ -34,7 +34,7 @@
  * @version $Id$
  */
 public class TestThreadSafe extends LuceneTestCase {
-  Random r = new Random();
+  Random r;
   Directory dir1;
   Directory dir2;
 
@@ -48,7 +48,7 @@
     final int iter;
     final Random rand;
     // pass in random in case we want to make things reproducable
-    public Thr(int iter, Random rand, int level) {
+    public Thr(int iter, Random rand) {
       this.iter = iter;
       this.rand = rand;
     }
@@ -132,7 +132,7 @@
   void doTest(int iter, int nThreads) throws Exception {
     Thr[] tarr = new Thr[nThreads];
     for (int i=0; i<nThreads; i++) {
-      tarr[i] = new Thr(iter, new Random(), 1);
+      tarr[i] = new Thr(iter, new Random(r.nextLong()));
       tarr[i].start();
     }
     for (int i=0; i<nThreads; i++) {
@@ -144,6 +144,7 @@
   }
 
   public void testLazyLoadThreadSafety() throws Exception{
+    r = newRandom();
     dir1 = new RAMDirectory();
     // test w/ field sizes bigger than the buffer of an index input
     buildDir(dir1, 15, 5, 2000);

Modified: lucene/java/trunk/src/test/org/apache/lucene/store/TestBufferedIndexInput.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/store/TestBufferedIndexInput.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/store/TestBufferedIndexInput.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/store/TestBufferedIndexInput.java Thu Feb  5 21:53:40 2009
@@ -157,7 +157,7 @@
 
     public void testSetBufferSize() throws IOException {
       File indexDir = new File(System.getProperty("tempDir"), "testSetBufferSize");
-      MockFSDirectory dir = new MockFSDirectory(indexDir);
+      MockFSDirectory dir = new MockFSDirectory(indexDir, newRandom());
       try {
         IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
         writer.setUseCompoundFile(false);
@@ -205,11 +205,12 @@
 
       List allIndexInputs = new ArrayList();
 
-      Random rand = new Random(788);
+      Random rand;
 
       private Directory dir;
 
-      public MockFSDirectory(File path) throws IOException {
+      public MockFSDirectory(File path, Random rand) throws IOException {
+        this.rand = rand;
         lockFactory = new NoLockFactory();
         dir = FSDirectory.getDirectory(path);
       }

Modified: lucene/java/trunk/src/test/org/apache/lucene/store/TestWindowsMMap.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/store/TestWindowsMMap.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/store/TestWindowsMMap.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/store/TestWindowsMMap.java Thu Feb  5 21:53:40 2009
@@ -28,7 +28,6 @@
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.store.FSDirectory;
 
 public class TestWindowsMMap extends LuceneTestCase {
 	
@@ -37,7 +36,7 @@
 	
 	public void setUp() throws Exception {
 		super.setUp();
-		random = new Random();
+		random = newRandom();
 		System.setProperty("org.apache.lucene.FSDirectory.class", "org.apache.lucene.store.MMapDirectory");
 	}
 	

Modified: lucene/java/trunk/src/test/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/util/LuceneTestCase.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/util/LuceneTestCase.java Thu Feb  5 21:53:40 2009
@@ -20,6 +20,7 @@
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.index.ConcurrentMergeScheduler;
 import junit.framework.TestCase;
+import java.util.Random;
 
 /** Base class for all Lucene unit tests.  Currently the
  *  only added functionality over JUnit's TestCase is
@@ -54,4 +55,48 @@
       fail("ConcurrentMergeScheduler hit unhandled exceptions");
     }
   }
+  
+  /**
+   * Returns a {@link Random} instance for generating random numbers during the test.
+   * The random seed is logged during test execution and printed to System.out on any failure
+   * for reproducing the test using {@link #newRandom(long)} with the recorded seed
+   *.
+   */
+  public Random newRandom() {
+    if (seed != null) {
+      throw new IllegalStateException("please call LuceneTestCase.newRandom only once per test");
+    }
+    return newRandom(seedRnd.nextLong());
+  }
+  
+  /**
+   * Returns a {@link Random} instance for generating random numbers during the test.
+   * 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 Random newRandom(long seed) {
+    if (this.seed != null) {
+      throw new IllegalStateException("please call LuceneTestCase.newRandom only once per test");
+    }
+    this.seed = new Long(seed);
+    return new Random(seed);
+  }
+  
+  protected void runTest() throws Throwable {
+    try {
+      seed = null;
+      super.runTest();
+    } catch (Throwable e) {
+      if (seed != null) {
+        System.out.println("NOTE: random seed of testcase '" + getName() + "' was: " + seed);
+      }
+      throw e;
+    }
+  }
+  
+  // recorded seed
+  protected Long seed = null;
+  
+  // static members
+  private static final Random seedRnd = new Random();
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/util/TestOpenBitSet.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/util/TestOpenBitSet.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/util/TestOpenBitSet.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/util/TestOpenBitSet.java Thu Feb  5 21:53:40 2009
@@ -17,16 +17,14 @@
 
 package org.apache.lucene.util;
 
-import junit.framework.TestCase;
-
 import java.util.Random;
 import java.util.BitSet;
 
 /**
  * @version $Id$
  */
-public class TestOpenBitSet extends TestCase {
-  static Random rand = new Random();
+public class TestOpenBitSet extends LuceneTestCase {
+  Random rand;
 
   void doGet(BitSet a, OpenBitSet b) {
     int max = a.size();
@@ -184,17 +182,20 @@
   // large enough to flush obvious bugs, small enough to run in <.5 sec as part of a
   // larger testsuite.
   public void testSmall() {
+    rand = newRandom();
     doRandomSets(1200,1000, 1);
     doRandomSets(1200,1000, 2);
   }
 
   public void testBig() {
     // uncomment to run a bigger test (~2 minutes).
+    // rand = newRandom();
     // doRandomSets(2000,200000, 1);
     // doRandomSets(2000,200000, 2);
   }
 
   public void testEquals() {
+    rand = newRandom();
     OpenBitSet b1 = new OpenBitSet(1111);
     OpenBitSet b2 = new OpenBitSet(2222);
     assertTrue(b1.equals(b2));
@@ -218,6 +219,7 @@
   
   public void testBitUtils()
   {
+    rand = newRandom();
     long num = 100000;
     assertEquals( 5, BitUtil.ntz(num) );
     assertEquals( 5, BitUtil.ntz2(num) );

Modified: lucene/java/trunk/src/test/org/apache/lucene/util/TestPriorityQueue.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/util/TestPriorityQueue.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/util/TestPriorityQueue.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/util/TestPriorityQueue.java Thu Feb  5 21:53:40 2009
@@ -45,13 +45,12 @@
     public void testPQ()
 	throws Exception
     {
-	testPQ(10000);
+	testPQ(10000, newRandom());
     }
 
-    public static void testPQ(int count)
+  public static void testPQ(int count, Random gen)
     {
 	PriorityQueue pq = new IntegerQueue(count);
-	Random gen = new Random();
 	int sum = 0, sum2 = 0;
 
 	for (int i = 0; i < count; i++)

Modified: lucene/java/trunk/src/test/org/apache/lucene/util/TestSmallFloat.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/util/TestSmallFloat.java?rev=741311&r1=741310&r2=741311&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/util/TestSmallFloat.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/util/TestSmallFloat.java Thu Feb  5 21:53:40 2009
@@ -16,7 +16,6 @@
  * limitations under the License.
  */
 
-import org.apache.lucene.util.LuceneTestCase;
 import java.util.Random;
 
 /**
@@ -74,7 +73,7 @@
   }
 
   public void testFloatToByte() {
-    Random rand = new Random(0);
+    Random rand = newRandom();
     // up iterations for more exhaustive test after changing something
     for (int i=0; i<100000; i++) {
       float f = Float.intBitsToFloat(rand.nextInt());



Mime
View raw message