lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1000424 - in /lucene/dev/trunk/lucene: contrib/misc/src/test/org/apache/lucene/misc/ contrib/remote/src/test/org/apache/lucene/search/ src/test/org/apache/lucene/search/ src/test/org/apache/lucene/search/spans/ src/test/org/apache/lucene/u...
Date Thu, 23 Sep 2010 12:19:07 GMT
Author: rmuir
Date: Thu Sep 23 12:19:07 2010
New Revision: 1000424

URL: http://svn.apache.org/viewvc?rev=1000424&view=rev
Log:
LUCENE-2659: LuceneTestCase ease of use improvements

Modified:
    lucene/dev/trunk/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.java
    lucene/dev/trunk/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java
    lucene/dev/trunk/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.java
    lucene/dev/trunk/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBoolean2.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSubScorerFreqs.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestBasics.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java

Modified: lucene/dev/trunk/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.java?rev=1000424&r1=1000423&r2=1000424&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.java
(original)
+++ lucene/dev/trunk/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.java
Thu Sep 23 12:19:07 2010
@@ -36,12 +36,10 @@ public class TestHighFreqTerms extends L
   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);
+    dir = newDirectory();
     writer = new IndexWriter(dir, newIndexWriterConfig(random,
        TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false))
        .setMaxBufferedDocs(2));

Modified: lucene/dev/trunk/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java?rev=1000424&r1=1000423&r2=1000424&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java
(original)
+++ lucene/dev/trunk/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java
Thu Sep 23 12:19:07 2010
@@ -17,8 +17,6 @@ package org.apache.lucene.search;
  * 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,20 +39,19 @@ public class TestRemoteCachingWrapperFil
   @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,
+    indexStore = newDirectory();
+    IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(
         TEST_VERSION_CURRENT, new MockAnalyzer()));
     Document doc = new Document();
-    doc.add(newField(random, "test", "test text", Field.Store.YES, Field.Index.ANALYZED));
-    doc.add(newField(random, "type", "A", Field.Store.YES, Field.Index.ANALYZED));
-    doc.add(newField(random, "other", "other test text", Field.Store.YES, Field.Index.ANALYZED));
+    doc.add(newField("test", "test text", Field.Store.YES, Field.Index.ANALYZED));
+    doc.add(newField("type", "A", Field.Store.YES, Field.Index.ANALYZED));
+    doc.add(newField("other", "other test text", Field.Store.YES, Field.Index.ANALYZED));
     writer.addDocument(doc);
     //Need a second document to search for
     doc = new Document();
-    doc.add(newField(random, "test", "test text", Field.Store.YES, Field.Index.ANALYZED));
-    doc.add(newField(random, "type", "B", Field.Store.YES, Field.Index.ANALYZED));
-    doc.add(newField(random, "other", "other test text", Field.Store.YES, Field.Index.ANALYZED));
+    doc.add(newField("test", "test text", Field.Store.YES, Field.Index.ANALYZED));
+    doc.add(newField("type", "B", Field.Store.YES, Field.Index.ANALYZED));
+    doc.add(newField("other", "other test text", Field.Store.YES, Field.Index.ANALYZED));
     writer.addDocument(doc);
     writer.optimize();
     writer.close();

Modified: lucene/dev/trunk/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.java?rev=1000424&r1=1000423&r2=1000424&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.java
(original)
+++ lucene/dev/trunk/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.java
Thu Sep 23 12:19:07 2010
@@ -29,7 +29,6 @@ import org.junit.Test;
 import static org.junit.Assert.*;
 
 import java.util.Collections;
-import java.util.Random;
 import java.util.Set;
 import java.util.HashSet;
 
@@ -40,13 +39,12 @@ public class TestRemoteSearchable extend
   @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,
+    indexStore = newDirectory();
+    IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(
         TEST_VERSION_CURRENT, new MockAnalyzer()));
     Document doc = new Document();
-    doc.add(newField(random, "test", "test text", Field.Store.YES, Field.Index.ANALYZED));
-    doc.add(newField(random, "other", "other test text", Field.Store.YES, Field.Index.ANALYZED));
+    doc.add(newField("test", "test text", Field.Store.YES, Field.Index.ANALYZED));
+    doc.add(newField("other", "other test text", Field.Store.YES, Field.Index.ANALYZED));
     writer.addDocument(doc);
     writer.optimize();
     writer.close();

Modified: lucene/dev/trunk/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java?rev=1000424&r1=1000423&r2=1000424&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java
(original)
+++ lucene/dev/trunk/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java
Thu Sep 23 12:19:07 2010
@@ -83,9 +83,8 @@ public class TestRemoteSort extends Remo
   // 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,
+    indexStore = newDirectory();
+    IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(
         TEST_VERSION_CURRENT, new MockAnalyzer())
         .setMaxBufferedDocs(2));
     ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(1000);

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java?rev=1000424&r1=1000423&r2=1000424&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java Thu
Sep 23 12:19:07 2010
@@ -94,7 +94,6 @@ public class BaseTestRangeFilter extends
   
   @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);

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBoolean2.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBoolean2.java?rev=1000424&r1=1000423&r2=1000424&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBoolean2.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBoolean2.java Thu Sep 23
12:19:07 2010
@@ -55,12 +55,11 @@ public class TestBoolean2 extends Lucene
 
   @BeforeClass
   public static void beforeClass() throws Exception {
-    Random random = newStaticRandom(TestBoolean2.class);
-    directory = newDirectory(random);
+    directory = newDirectory();
     RandomIndexWriter writer= new RandomIndexWriter(random, directory);
     for (int i = 0; i < docFields.length; i++) {
       Document doc = new Document();
-      doc.add(newField(random, field, docFields[i], Field.Store.NO, Field.Index.ANALYZED));
+      doc.add(newField(field, docFields[i], Field.Store.NO, Field.Index.ANALYZED));
       writer.addDocument(doc);
     }
     writer.close();
@@ -82,15 +81,15 @@ public class TestBoolean2 extends Lucene
     } while(docCount < 3000);
 
     RandomIndexWriter w = new RandomIndexWriter(random, dir2, 
-        newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
+        newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())
         .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000)));
     Document doc = new Document();
-    doc.add(newField(random, "field2", "xxx", Field.Store.NO, Field.Index.ANALYZED));
+    doc.add(newField("field2", "xxx", Field.Store.NO, Field.Index.ANALYZED));
     for(int i=0;i<NUM_EXTRA_DOCS/2;i++) {
       w.addDocument(doc);
     }
     doc = new Document();
-    doc.add(newField(random, "field2", "big bad bug", Field.Store.NO, Field.Index.ANALYZED));
+    doc.add(newField("field2", "big bad bug", Field.Store.NO, Field.Index.ANALYZED));
     for(int i=0;i<NUM_EXTRA_DOCS/2;i++) {
       w.addDocument(doc);
     }

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java?rev=1000424&r1=1000423&r2=1000424&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java
Thu Sep 23 12:19:07 2010
@@ -34,7 +34,6 @@ import static org.junit.Assert.*;
 import java.io.IOException;
 import java.text.Collator;
 import java.util.Locale;
-import java.util.Random;
 
 import junit.framework.Assert;
 
@@ -60,20 +59,18 @@ public class TestMultiTermConstantScore 
         "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);
+    small = newDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(random, small, new MockAnalyzer(MockTokenizer.WHITESPACE,
false));
 
     for (int i = 0; i < data.length; i++) {
       Document doc = new Document();
-      doc.add(newField(random, "id", String.valueOf(i), Field.Store.YES,
+      doc.add(newField("id", String.valueOf(i), Field.Store.YES,
           Field.Index.NOT_ANALYZED));// Field.Keyword("id",String.valueOf(i)));
       doc
-          .add(newField(random, "all", "all", Field.Store.YES,
+          .add(newField("all", "all", Field.Store.YES,
               Field.Index.NOT_ANALYZED));// Field.Keyword("all","all"));
       if (null != data[i]) {
-        doc.add(newField(random, "data", data[i], Field.Store.YES,
+        doc.add(newField("data", data[i], Field.Store.YES,
             Field.Index.ANALYZED));// Field.Text("data",data[i]));
       }
       writer.addDocument(doc);

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java?rev=1000424&r1=1000423&r2=1000424&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
Thu Sep 23 12:19:07 2010
@@ -17,8 +17,6 @@ package org.apache.lucene.search;
  * 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,14 +47,12 @@ public class TestNumericRangeQuery32 ext
   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);
+    directory = newDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(random, directory,
-        newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
+        newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())
         .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000)));
     
     NumericField

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java?rev=1000424&r1=1000423&r2=1000424&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
(original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
Thu Sep 23 12:19:07 2010
@@ -17,8 +17,6 @@ package org.apache.lucene.search;
  * 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,14 +46,12 @@ public class TestNumericRangeQuery64 ext
   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);
+    directory = newDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(random, directory,
-        newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
+        newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())
         .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000)));
     
     NumericField

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSubScorerFreqs.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSubScorerFreqs.java?rev=1000424&r1=1000423&r2=1000424&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSubScorerFreqs.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSubScorerFreqs.java Thu
Sep 23 12:19:07 2010
@@ -41,18 +41,17 @@ public class TestSubScorerFreqs extends 
   @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
     for (int i = 0; i < 31 * RANDOM_MULTIPLIER; i++) {
       Document doc = new Document();
-      doc.add(newField(random, "f", "a b c d b c d c d d", Field.Store.NO,
+      doc.add(newField("f", "a b c d b c d c d d", Field.Store.NO,
           Field.Index.ANALYZED));
       w.addDocument(doc);
 
       doc = new Document();
-      doc.add(newField(random, "f", "a b c d", Field.Store.NO, Field.Index.ANALYZED));
+      doc.add(newField("f", "a b c d", Field.Store.NO, Field.Index.ANALYZED));
       w.addDocument(doc);
     }
 

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestBasics.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestBasics.java?rev=1000424&r1=1000423&r2=1000424&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestBasics.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestBasics.java Thu Sep
23 12:19:07 2010
@@ -18,7 +18,6 @@ package org.apache.lucene.search.spans;
  */
 
 import java.io.IOException;
-import java.util.Random;
 
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.analysis.MockTokenizer;
@@ -65,15 +64,14 @@ public class TestBasics extends LuceneTe
 
   @BeforeClass
   public static void beforeClass() throws Exception {
-    Random random = newStaticRandom(TestBasics.class);
-    directory = newDirectory(random);
+    directory = newDirectory();
     RandomIndexWriter writer = new RandomIndexWriter(random, directory, 
-        newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE,
true))
+        newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE,
true))
         .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000)));
     //writer.infoStream = System.out;
     for (int i = 0; i < 1000; i++) {
       Document doc = new Document();
-      doc.add(newField(random, "field", English.intToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
+      doc.add(newField("field", English.intToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
       writer.addDocument(doc);
     }
     reader = writer.getReader();

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java?rev=1000424&r1=1000423&r2=1000424&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java Thu Sep 23
12:19:07 2010
@@ -77,6 +77,7 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Random;
 import java.util.TimeZone;
+import java.util.UUID;
 import java.util.WeakHashMap;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -217,7 +218,7 @@ public abstract class LuceneTestCase ext
     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 +242,10 @@ public abstract class LuceneTestCase ext
     }
 
     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 +280,15 @@ public abstract class LuceneTestCase ext
 
   @BeforeClass
   public static void beforeClassLuceneTestCaseJ4() {
+    staticSeed = "random".equals(TEST_SEED) ? seedRand.nextLong() : UUID.fromString(TEST_SEED).getMostSignificantBits();
+    random.setSeed(staticSeed);
     stores = Collections.synchronizedMap(new IdentityHashMap<MockDirectoryWrapper,StackTraceElement[]>());
     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;
   }
@@ -307,6 +310,11 @@ public abstract class LuceneTestCase ext
         }
       }
     stores = null;
+    // if tests failed, report some information back
+    if (testsFailed)
+      System.out.println("NOTE: test params are: codec=" + codec + 
+        ", locale=" + locale + 
+        ", timezone=" + (timeZone == null ? "(null)" : timeZone.getID()));
   }
 
   private static boolean testsFailed; /* true if any tests failed */
@@ -335,10 +343,10 @@ public abstract class LuceneTestCase ext
 
   @Before
   public void setUp() throws Exception {
+    seed = "random".equals(TEST_SEED) ? seedRand.nextLong() : UUID.fromString(TEST_SEED).getLeastSignificantBits();
+    random.setSeed(seed);
     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);
     savedUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
     Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
       public void uncaughtException(Thread t, Throwable e) {
@@ -350,7 +358,6 @@ public abstract class LuceneTestCase ext
     
     ConcurrentMergeScheduler.setTestMode();
     savedBoolMaxClauseCount = BooleanQuery.getMaxClauseCount();
-    seed = null;
   }
 
 
@@ -512,36 +519,8 @@ public abstract class LuceneTestCase ext
     dumpIterator(label, iter, stream);
   }
 
-  private static final Map<Class<? extends LuceneTestCase>,Long> staticSeeds
=
-    Collections.synchronizedMap(new WeakHashMap<Class<? extends LuceneTestCase>,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<? extends LuceneTestCase> 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<? extends LuceneTestCase> 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) {
+  public static IndexWriterConfig newIndexWriterConfig(Version v, Analyzer a) {
     return newIndexWriterConfig(random, v, a);
   }
   
@@ -586,7 +565,7 @@ public abstract class LuceneTestCase ext
    * some features of Windows, such as not allowing open files to be
    * overwritten.
    */
-  public MockDirectoryWrapper newDirectory() throws IOException {
+  public static MockDirectoryWrapper newDirectory() throws IOException {
     return newDirectory(random);
   }
   
@@ -603,11 +582,11 @@ public abstract class LuceneTestCase ext
    * provided directory. See {@link #newDirectory()} for more
    * information.
    */
-  public MockDirectoryWrapper newDirectory(Directory d) throws IOException {
+  public static MockDirectoryWrapper newDirectory(Directory d) throws IOException {
     return newDirectory(random, d);
   }
   
-  private static MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException
{
+  public static MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException
{
     StackTraceElement[] stack = new Exception().getStackTrace();
     Directory impl = newDirectoryImpl(r, TEST_DIRECTORY);
     for (String file : d.listAll()) {
@@ -618,15 +597,15 @@ public abstract class LuceneTestCase ext
     return dir;
   }
   
-  public Field newField(String name, String value, Index index) {
+  public static Field newField(String name, String value, Index index) {
     return newField(random, name, value, index);
   }
   
-  public Field newField(String name, String value, Store store, Index index) {
+  public static Field newField(String name, String value, Store store, Index index) {
     return newField(random, name, value, store, index);
   }
   
-  public Field newField(String name, String value, Store store, Index index, TermVector tv)
{
+  public static Field newField(String name, String value, Store store, Index index, TermVector
tv) {
     return newField(random, name, value, store, index, tv);
   }
   
@@ -751,27 +730,17 @@ public abstract class LuceneTestCase ext
 
   // 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) {
-      System.out.println("NOTE: random seed of testcase '" + getName() + "' was: " + seed);
-    }
+    System.out.println("NOTE: reproduce with: ant test -Dtestcase=" + getClass().getSimpleName()

+        + " -Dtestmethod=" + getName() + " -Dtests.seed=" + new UUID(staticSeed, seed));
   }
 
-  // recorded seed
-  protected Long seed = null;
-  protected Random random = null;
+  // recorded seed: for beforeClass
+  private static long staticSeed;
+  // seed for individual test methods, changed in @before
+  private long seed;
   
-  // static members
-  private static final Random seedRnd = new Random();
+  private static final Random seedRand = new Random();
+  protected static final Random random = new Random();
 
   private String name = "<unknown>";
   



Mime
View raw message