Index: lucene/src/test/org/apache/lucene/search/TestAutomatonQueryUnicode.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestAutomatonQueryUnicode.java (revision 963263) +++ lucene/src/test/org/apache/lucene/search/TestAutomatonQueryUnicode.java (working copy) @@ -18,12 +18,16 @@ */ import java.io.IOException; +import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; +import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.automaton.Automaton; @@ -36,14 +40,17 @@ */ public class TestAutomatonQueryUnicode extends LuceneTestCase { private IndexSearcher searcher; + private Directory directory; + private RandomIndexWriter writer; private final String FN = "field"; public void setUp() throws Exception { super.setUp(); - RAMDirectory directory = new RAMDirectory(); - IndexWriter writer = new IndexWriter(directory, new MockAnalyzer(), true, - IndexWriter.MaxFieldLength.LIMITED); + Random random = newRandom(); + directory = new RAMDirectory(); + writer = new RandomIndexWriter(random, directory, + new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())); Document doc = new Document(); Field titleField = new Field("title", "some title", Field.Store.NO, Field.Index.ANALYZED); @@ -79,13 +86,14 @@ writer.addDocument(doc); field.setValue("\uFFFD\uFFFD"); writer.addDocument(doc); - writer.optimize(); - writer.close(); - searcher = new IndexSearcher(directory, true); + IndexReader reader = writer.getReader(); + searcher = new IndexSearcher(reader); } public void tearDown() throws Exception { + writer.close(); searcher.close(); + directory.close(); super.tearDown(); } Index: lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java (revision 963263) +++ lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java (working copy) @@ -26,8 +26,11 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; +import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util._TestUtil; @@ -40,13 +43,16 @@ public class TestWildcardRandom extends LuceneTestCase { private Searcher searcher; private Random random; + private Directory dir; + private RandomIndexWriter writer; @Override protected void setUp() throws Exception { super.setUp(); - RAMDirectory dir = new RAMDirectory(); - IndexWriter writer = new IndexWriter(dir, new MockAnalyzer(), - IndexWriter.MaxFieldLength.UNLIMITED); + random = newRandom(); + dir = new RAMDirectory(); + writer = new RandomIndexWriter(random, dir, + new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())); Document doc = new Document(); Field field = new Field("field", "", Field.Store.NO, Field.Index.ANALYZED); @@ -58,9 +64,8 @@ writer.addDocument(doc); } - writer.optimize(); - writer.close(); - searcher = new IndexSearcher(dir); + IndexReader reader = writer.getReader(); + searcher = new IndexSearcher(reader); } private char N() { @@ -82,6 +87,7 @@ } private void assertPatternHits(String pattern, int numHits) throws Exception { + // TODO: run with different rewrites Query wq = new WildcardQuery(new Term("field", fillPattern(pattern))); TopDocs docs = searcher.search(wq, 25); assertEquals("Incorrect hits for pattern: " + pattern, numHits, docs.totalHits); @@ -89,12 +95,13 @@ @Override protected void tearDown() throws Exception { + writer.close(); searcher.close(); + dir.close(); super.tearDown(); } - public void testWildcards() throws Exception { - random = newRandom(System.nanoTime()); + public void testWildcards() throws Exception {; for (int i = 0; i < 100*_TestUtil.getRandomMultiplier(); i++) { assertPatternHits("NNNN", 1); assertPatternHits("?NNN", 10); Index: lucene/src/test/org/apache/lucene/search/TestAutomatonQuery.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestAutomatonQuery.java (revision 963263) +++ lucene/src/test/org/apache/lucene/search/TestAutomatonQuery.java (working copy) @@ -18,13 +18,17 @@ */ import java.io.IOException; +import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.index.TermsEnum; +import org.apache.lucene.store.Directory; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.automaton.Automaton; @@ -32,15 +36,18 @@ import org.apache.lucene.util.automaton.BasicOperations; public class TestAutomatonQuery extends LuceneTestCase { + private Directory directory; private IndexSearcher searcher; - + private RandomIndexWriter writer; + private final String FN = "field"; public void setUp() throws Exception { super.setUp(); - RAMDirectory directory = new RAMDirectory(); - IndexWriter writer = new IndexWriter(directory, new MockAnalyzer(), true, - IndexWriter.MaxFieldLength.LIMITED); + Random random = newRandom(); + directory = new RAMDirectory(); + writer = new RandomIndexWriter(random, directory, + new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())); Document doc = new Document(); Field titleField = new Field("title", "some title", Field.Store.NO, Field.Index.ANALYZED); @@ -57,13 +64,14 @@ field.setValue("doc three has some different stuff" + " with numbers 1234 5678.9 and letter b"); writer.addDocument(doc); - writer.optimize(); - writer.close(); - searcher = new IndexSearcher(directory, true); + IndexReader reader = writer.getReader(); + searcher = new IndexSearcher(reader); } public void tearDown() throws Exception { + writer.close(); searcher.close(); + directory.close(); super.tearDown(); } Index: lucene/src/test/org/apache/lucene/search/TestBoolean2.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestBoolean2.java (revision 963263) +++ lucene/src/test/org/apache/lucene/search/TestBoolean2.java (working copy) @@ -23,8 +23,8 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.index.IndexReader; import org.apache.lucene.queryParser.ParseException; @@ -41,7 +41,9 @@ public class TestBoolean2 extends LuceneTestCase { private IndexSearcher searcher; private IndexSearcher bigSearcher; + private RandomIndexWriter bigWriter; private IndexReader reader; + private Random rnd; private static int NUM_EXTRA_DOCS = 6000; public static final String field = "field"; @@ -51,8 +53,9 @@ @Override protected void setUp() throws Exception { super.setUp(); + rnd = newRandom(); RAMDirectory directory = new RAMDirectory(); - IndexWriter writer= new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())); + RandomIndexWriter writer= new RandomIndexWriter(rnd, directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())); for (int i = 0; i < docFields.length; i++) { Document doc = new Document(); doc.add(new Field(field, docFields[i], Field.Store.NO, Field.Index.ANALYZED)); @@ -69,14 +72,14 @@ int docCount = 0; do { final Directory copy = new RAMDirectory(dir2); - IndexWriter w = new IndexWriter(dir2, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())); + RandomIndexWriter w = new RandomIndexWriter(rnd, dir2, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())); w.addIndexes(new Directory[] {copy}); docCount = w.maxDoc(); w.close(); mulFactor *= 2; } while(docCount < 3000); - IndexWriter w = new IndexWriter(dir2, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())); + RandomIndexWriter w = new RandomIndexWriter(rnd, dir2, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())); Document doc = new Document(); doc.add(new Field("field2", "xxx", Field.Store.NO, Field.Index.ANALYZED)); for(int i=0;i,Long> staticSeeds = new Hashtable,Long>(); + + public static Random newStaticRandom(Class clazz) { + return newStaticRandom(clazz, seedRnd.nextLong()); + } + + public static Random newStaticRandom(Class clazz, long seed) { + staticSeeds.put(clazz, Long.valueOf(seed)); + return new Random(seed); + } + public String getName() { return this.name; } @@ -348,6 +360,11 @@ // 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); + } + if (seed != null) { System.out.println("NOTE: random seed of testcase '" + getName() + "' was: " + seed); }