lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r984298 [3/6] - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/backwards/src/ lucene/backwards/src/test/org/apache/lucene/analysis/ lucene/backwards/src/test/org/apache/lucene/document/ lucene/backwards/src/test/org/apache/lucene/inde...
Date Wed, 11 Aug 2010 04:01:48 GMT
Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReader.java?rev=984298&r1=984297&r2=984298&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReader.java Wed Aug 11 04:01:46 2010
@@ -28,6 +28,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.HashMap;
+import java.util.Random;
 import java.util.Set;
 import java.util.SortedSet;
 
@@ -67,7 +68,15 @@ public class TestIndexReader extends Luc
 //        TestRunner.run (new TestIndexReader("testDeleteReaderReaderConflict"));
 //        TestRunner.run (new TestIndexReader("testFilesOpenClose"));
     }
-
+    
+    private Random random;
+    
+    @Override
+    public void setUp() throws Exception {
+      super.setUp();
+      random = newRandom();
+    }
+    
     public TestIndexReader(String name) {
         super(name);
     }
@@ -79,7 +88,7 @@ public class TestIndexReader extends Luc
       commitUserData.put("foo", "fighters");
       
       // set up writer
-      IndexWriter writer = new IndexWriter(d, new IndexWriterConfig(
+      IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random,
           TEST_VERSION_CURRENT, new StandardAnalyzer(TEST_VERSION_CURRENT))
       .setMaxBufferedDocs(2));
       for(int i=0;i<27;i++)
@@ -102,7 +111,7 @@ public class TestIndexReader extends Luc
       assertTrue(c.equals(r.getIndexCommit()));
 
       // Change the index
-      writer = new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT,
+      writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
           new StandardAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(
               OpenMode.APPEND).setMaxBufferedDocs(2));
       for(int i=0;i<7;i++)
@@ -114,7 +123,7 @@ public class TestIndexReader extends Luc
       assertFalse(r2.getIndexCommit().isOptimized());
       r3.close();
 
-      writer = new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT,
+      writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
         new StandardAnalyzer(TEST_VERSION_CURRENT))
         .setOpenMode(OpenMode.APPEND));
       writer.optimize();
@@ -129,7 +138,7 @@ public class TestIndexReader extends Luc
     
     public void testIsCurrent() throws Exception {
       RAMDirectory d = new MockRAMDirectory();
-      IndexWriter writer = new IndexWriter(d, new IndexWriterConfig(
+      IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random, 
         TEST_VERSION_CURRENT, new StandardAnalyzer(TEST_VERSION_CURRENT)));
       addDocumentWithFields(writer);
       writer.close();
@@ -137,13 +146,13 @@ public class TestIndexReader extends Luc
       IndexReader reader = IndexReader.open(d, false);
       assertTrue(reader.isCurrent());
       // modify index by adding another document:
-      writer = new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT,
+      writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
           new StandardAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
       addDocumentWithFields(writer);
       writer.close();
       assertFalse(reader.isCurrent());
       // re-create index:
-      writer = new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT,
+      writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
           new StandardAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
       addDocumentWithFields(writer);
       writer.close();
@@ -159,7 +168,7 @@ public class TestIndexReader extends Luc
     public void testGetFieldNames() throws Exception {
         RAMDirectory d = new MockRAMDirectory();
         // set up writer
-        IndexWriter writer = new IndexWriter(d, new IndexWriterConfig(
+        IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random, 
             TEST_VERSION_CURRENT, new StandardAnalyzer(TEST_VERSION_CURRENT)));
         addDocumentWithFields(writer);
         writer.close();
@@ -172,7 +181,7 @@ public class TestIndexReader extends Luc
         assertTrue(fieldNames.contains("unstored"));
         reader.close();
         // add more documents
-        writer = new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT,
+        writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
             new StandardAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
         // want to get some more segments here
         int mergeFactor = ((LogMergePolicy) writer.getConfig().getMergePolicy()).getMergeFactor();
@@ -251,7 +260,7 @@ public class TestIndexReader extends Luc
   public void testTermVectors() throws Exception {
     RAMDirectory d = new MockRAMDirectory();
     // set up writer
-    IndexWriter writer = new IndexWriter(d, new IndexWriterConfig(
+    IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random, 
         TEST_VERSION_CURRENT, new StandardAnalyzer(TEST_VERSION_CURRENT)));
     // want to get some more segments here
     // new termvector fields
@@ -314,7 +323,7 @@ public class TestIndexReader extends Luc
         Term searchTerm = new Term("content", "aaa");
 
         //  add 100 documents with term : aaa
-        writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+        writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
         for (int i = 0; i < 100; i++) {
             addDoc(writer, searchTerm.text());
         }
@@ -354,7 +363,7 @@ public class TestIndexReader extends Luc
         Directory dir = new RAMDirectory();
         byte[] bin = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
         
-        IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+        IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
         
         for (int i = 0; i < 10; i++) {
           addDoc(writer, "document number " + (i + 1));
@@ -363,7 +372,7 @@ public class TestIndexReader extends Luc
           addDocumentWithTermVectorFields(writer);
         }
         writer.close();
-        writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
+        writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
         Document doc = new Document();
         doc.add(new Field("bin1", bin));
         doc.add(new Field("junk", "junk text", Field.Store.NO, Field.Index.ANALYZED));
@@ -400,7 +409,7 @@ public class TestIndexReader extends Luc
         // force optimize
 
 
-        writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
+        writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
         writer.optimize();
         writer.close();
         reader = IndexReader.open(dir, false);
@@ -428,7 +437,7 @@ public class TestIndexReader extends Luc
         Term searchTerm = new Term("content", "aaa");
 
         //  add 11 documents with term : aaa
-        writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+        writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
         for (int i = 0; i < 11; i++) {
             addDoc(writer, searchTerm.text());
         }
@@ -469,7 +478,7 @@ public class TestIndexReader extends Luc
         Term searchTerm = new Term("content", "aaa");
 
         //  add 11 documents with term : aaa
-        IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+        IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
         writer.commit();
         for (int i = 0; i < 11; i++) {
             addDoc(writer, searchTerm.text());
@@ -513,7 +522,7 @@ public class TestIndexReader extends Luc
         Term searchTerm = new Term("content", "aaa");
 
         //  add 1 documents with term : aaa
-        writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+        writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
         addDoc(writer, searchTerm.text());
         writer.close();
 
@@ -557,7 +566,7 @@ public class TestIndexReader extends Luc
         Term searchTerm = new Term("content", "aaa");
 
         //  add 1 documents with term : aaa
-        writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+        writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
         ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false);
         ((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false);
         addDoc(writer, searchTerm.text());
@@ -611,7 +620,7 @@ public class TestIndexReader extends Luc
         Term searchTerm2 = new Term("content", "bbb");
 
         //  add 100 documents with term : aaa
-        IndexWriter writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
+        IndexWriter writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
         for (int i = 0; i < 100; i++) {
             addDoc(writer, searchTerm.text());
         }
@@ -626,7 +635,7 @@ public class TestIndexReader extends Luc
         assertTermDocsCount("first reader", reader, searchTerm2, 0);
 
         // add 100 documents with term : bbb
-        writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
+        writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
         for (int i = 0; i < 100; i++) {
             addDoc(writer, searchTerm2.text());
         }
@@ -691,7 +700,7 @@ public class TestIndexReader extends Luc
         // Create initial data set
         File dirFile = new File(TEMP_DIR, "testIndex");
         Directory dir = getDirectory();
-        IndexWriter writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+        IndexWriter writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
         addDoc(writer, "test");
         writer.close();
         dir.close();
@@ -701,7 +710,7 @@ public class TestIndexReader extends Luc
         dir = getDirectory();
 
         // Now create the data set again, just as before
-        writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
+        writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
         addDoc(writer, "test");
         writer.close();
         dir.close();
@@ -727,7 +736,7 @@ public class TestIndexReader extends Luc
           else
             dir = getDirectory();
           assertFalse(IndexReader.indexExists(dir));
-          IndexWriter writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
+          IndexWriter writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
           addDocumentWithFields(writer);
           assertTrue(IndexWriter.isLocked(dir));		// writer open, so dir is locked
           writer.close();
@@ -744,7 +753,7 @@ public class TestIndexReader extends Luc
           // incremented:
           Thread.sleep(1000);
 
-          writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
+          writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
           addDocumentWithFields(writer);
           writer.close();
           reader = IndexReader.open(dir, false);
@@ -761,7 +770,7 @@ public class TestIndexReader extends Luc
     public void testVersion() throws IOException {
       Directory dir = new MockRAMDirectory();
       assertFalse(IndexReader.indexExists(dir));
-      IndexWriter writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+      IndexWriter writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
       addDocumentWithFields(writer);
       assertTrue(IndexWriter.isLocked(dir));		// writer open, so dir is locked
       writer.close();
@@ -772,7 +781,7 @@ public class TestIndexReader extends Luc
       reader.close();
       // modify index and check version has been
       // incremented:
-      writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
+      writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
       addDocumentWithFields(writer);
       writer.close();
       reader = IndexReader.open(dir, false);
@@ -783,10 +792,10 @@ public class TestIndexReader extends Luc
 
     public void testLock() throws IOException {
       Directory dir = new MockRAMDirectory();
-      IndexWriter writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+      IndexWriter writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
       addDocumentWithFields(writer);
       writer.close();
-      writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
+      writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
       IndexReader reader = IndexReader.open(dir, false);
       try {
         reader.deleteDocument(0);
@@ -803,7 +812,7 @@ public class TestIndexReader extends Luc
 
     public void testUndeleteAll() throws IOException {
       Directory dir = new MockRAMDirectory();
-      IndexWriter writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+      IndexWriter writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
       addDocumentWithFields(writer);
       addDocumentWithFields(writer);
       writer.close();
@@ -820,7 +829,7 @@ public class TestIndexReader extends Luc
 
     public void testUndeleteAllAfterClose() throws IOException {
       Directory dir = new MockRAMDirectory();
-      IndexWriter writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+      IndexWriter writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
       addDocumentWithFields(writer);
       addDocumentWithFields(writer);
       writer.close();
@@ -837,7 +846,7 @@ public class TestIndexReader extends Luc
 
     public void testUndeleteAllAfterCloseThenReopen() throws IOException {
       Directory dir = new MockRAMDirectory();
-      IndexWriter writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+      IndexWriter writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
       addDocumentWithFields(writer);
       addDocumentWithFields(writer);
       writer.close();
@@ -874,7 +883,7 @@ public class TestIndexReader extends Luc
       
       // First build up a starting index:
       RAMDirectory startDir = new MockRAMDirectory();
-      IndexWriter writer = new IndexWriter(startDir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+      IndexWriter writer = new IndexWriter(startDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
       for(int i=0;i<157;i++) {
         Document d = new Document();
         d.add(new Field("id", Integer.toString(i), Field.Store.YES, Field.Index.NOT_ANALYZED));
@@ -1064,7 +1073,7 @@ public class TestIndexReader extends Luc
 
     public void testDocsOutOfOrderJIRA140() throws IOException {
       Directory dir = new MockRAMDirectory();      
-      IndexWriter writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+      IndexWriter writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
       for(int i=0;i<11;i++) {
         addDoc(writer, "aaa");
       }
@@ -1082,7 +1091,7 @@ public class TestIndexReader extends Luc
       }
       reader.close();
 
-      writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
+      writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.APPEND));
 
       // We must add more docs to get a new segment written
       for(int i=0;i<11;i++) {
@@ -1104,7 +1113,7 @@ public class TestIndexReader extends Luc
     public void testExceptionReleaseWriteLockJIRA768() throws IOException {
 
       Directory dir = new MockRAMDirectory();      
-      IndexWriter writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+      IndexWriter writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
       addDoc(writer, "aaa");
       writer.close();
 
@@ -1178,7 +1187,7 @@ public class TestIndexReader extends Luc
         //  add 100 documents with term : aaa
         //  add 100 documents with term : bbb
         //  add 100 documents with term : ccc
-        IndexWriter writer  = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
+        IndexWriter writer  = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE));
         for (int i = 0; i < 100; i++) {
             addDoc(writer, searchTerm1.text());
             addDoc(writer, searchTerm2.text());
@@ -1401,9 +1410,10 @@ public class TestIndexReader extends Luc
       RAMDirectory d = new MockRAMDirectory();
 
       // set up writer
-      IndexWriter writer = new IndexWriter(d, new IndexWriterConfig(
+      IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random, 
           TEST_VERSION_CURRENT, new StandardAnalyzer(TEST_VERSION_CURRENT))
       .setMaxBufferedDocs(2));
+      ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
       for(int i=0;i<27;i++)
         addDocumentWithFields(writer);
       writer.close();
@@ -1418,9 +1428,10 @@ public class TestIndexReader extends Luc
       assertTrue(c.equals(r.getIndexCommit()));
 
       // Change the index
-      writer = new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT,
+      writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
           new StandardAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(
               OpenMode.APPEND).setMaxBufferedDocs(2));
+      ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
       for(int i=0;i<7;i++)
         addDocumentWithFields(writer);
       writer.close();
@@ -1430,7 +1441,7 @@ public class TestIndexReader extends Luc
       assertFalse(r2.getIndexCommit().isOptimized());
       r2.close();
 
-      writer = new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT,
+      writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
         new StandardAnalyzer(TEST_VERSION_CURRENT))
         .setOpenMode(OpenMode.APPEND));
       writer.optimize();
@@ -1446,7 +1457,7 @@ public class TestIndexReader extends Luc
 
     public void testReadOnly() throws Throwable {
       RAMDirectory d = new MockRAMDirectory();
-      IndexWriter writer = new IndexWriter(d, new IndexWriterConfig(
+      IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random, 
         TEST_VERSION_CURRENT, new StandardAnalyzer(TEST_VERSION_CURRENT)));
       addDocumentWithFields(writer);
       writer.commit();
@@ -1461,9 +1472,10 @@ public class TestIndexReader extends Luc
         // expected
       }
       
-      writer = new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT,
+      writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
         new StandardAnalyzer(TEST_VERSION_CURRENT))
         .setOpenMode(OpenMode.APPEND));
+      ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
       addDocumentWithFields(writer);
       writer.close();
 
@@ -1480,7 +1492,7 @@ public class TestIndexReader extends Luc
         // expected
       }
 
-      writer = new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT,
+      writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
         new StandardAnalyzer(TEST_VERSION_CURRENT))
         .setOpenMode(OpenMode.APPEND));
       writer.optimize();
@@ -1488,6 +1500,7 @@ public class TestIndexReader extends Luc
 
       // Make sure reopen to a single segment is still readonly:
       IndexReader r3 = r2.reopen();
+      assertFalse(r3 == r2);
       r2.close();
       
       assertFalse(r == r2);
@@ -1500,7 +1513,7 @@ public class TestIndexReader extends Luc
       }
 
       // Make sure write lock isn't held
-      writer = new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT,
+      writer = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
           new StandardAnalyzer(TEST_VERSION_CURRENT))
       .setOpenMode(OpenMode.APPEND));
       writer.close();
@@ -1512,7 +1525,7 @@ public class TestIndexReader extends Luc
   // LUCENE-1474
   public void testIndexReader() throws Exception {
     Directory dir = new RAMDirectory();
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, 
         TEST_VERSION_CURRENT, new StandardAnalyzer(TEST_VERSION_CURRENT)));
     writer.addDocument(createDocument("a"));
     writer.addDocument(createDocument("b"));
@@ -1530,7 +1543,7 @@ public class TestIndexReader extends Luc
   public void testIndexReaderUnDeleteAll() throws Exception {
     MockRAMDirectory dir = new MockRAMDirectory();
     dir.setPreventDoubleWrite(false);
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, 
         TEST_VERSION_CURRENT, new StandardAnalyzer(TEST_VERSION_CURRENT)));
     writer.addDocument(createDocument("a"));
     writer.addDocument(createDocument("b"));
@@ -1572,7 +1585,7 @@ public class TestIndexReader extends Luc
 
     Directory dir = new MockRAMDirectory();
     
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, 
         TEST_VERSION_CURRENT, new StandardAnalyzer(TEST_VERSION_CURRENT))
         .setMaxBufferedDocs(2));
     writer.addDocument(createDocument("a"));
@@ -1597,7 +1610,7 @@ public class TestIndexReader extends Luc
   // reuse the doc values arrays in FieldCache
   public void testFieldCacheReuseAfterClone() throws Exception {
     Directory dir = new MockRAMDirectory();
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
     Document doc = new Document();
     doc.add(new Field("number", "17", Field.Store.NO, Field.Index.NOT_ANALYZED));
     writer.addDocument(doc);
@@ -1628,9 +1641,10 @@ public class TestIndexReader extends Luc
   // FieldCache
   public void testFieldCacheReuseAfterReopen() throws Exception {
     Directory dir = new MockRAMDirectory();
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
     Document doc = new Document();
     doc.add(new Field("number", "17", Field.Store.NO, Field.Index.NOT_ANALYZED));
+    ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
     writer.addDocument(doc);
     writer.commit();
 
@@ -1660,7 +1674,8 @@ public class TestIndexReader extends Luc
   // reopen switches readOnly
   public void testReopenChangeReadonly() throws Exception {
     Directory dir = new MockRAMDirectory();
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(-1));
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(10);
     Document doc = new Document();
     doc.add(new Field("number", "17", Field.Store.NO, Field.Index.NOT_ANALYZED));
     writer.addDocument(doc);
@@ -1701,7 +1716,7 @@ public class TestIndexReader extends Luc
   // LUCENE-1586: getUniqueTermCount
   public void testUniqueTermCount() throws Exception {
     Directory dir = new MockRAMDirectory();
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
     Document doc = new Document();
     doc.add(new Field("field", "a b c d e f g h i j k l m n o p q r s t u v w x y z", Field.Store.NO, Field.Index.ANALYZED));
     doc.add(new Field("number", "0 1 2 3 4 5 6 7 8 9", Field.Store.NO, Field.Index.ANALYZED));
@@ -1734,7 +1749,7 @@ public class TestIndexReader extends Luc
   // LUCENE-1609: don't load terms index
   public void testNoTermsIndex() throws Throwable {
     Directory dir = new MockRAMDirectory();
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
     Document doc = new Document();
     doc.add(new Field("field", "a b c d e f g h i j k l m n o p q r s t u v w x y z", Field.Store.NO, Field.Index.ANALYZED));
     doc.add(new Field("number", "0 1 2 3 4 5 6 7 8 9", Field.Store.NO, Field.Index.ANALYZED));
@@ -1752,7 +1767,8 @@ public class TestIndexReader extends Luc
     assertFalse(((SegmentReader) r.getSequentialSubReaders()[0]).termsIndexLoaded());
 
     assertEquals(-1, ((SegmentReader) r.getSequentialSubReaders()[0]).getTermInfosIndexDivisor());
-    writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+    writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
+    ((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);
     writer.addDocument(doc);
     writer.close();
 
@@ -1771,7 +1787,7 @@ public class TestIndexReader extends Luc
   // LUCENE-2046
   public void testPrepareCommitIsCurrent() throws Throwable {
     Directory dir = new MockRAMDirectory();
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, 
         TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
     writer.commit();
     Document doc = new Document();

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java?rev=984298&r1=984297&r2=984298&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java Wed Aug 11 04:01:46 2010
@@ -17,6 +17,8 @@ package org.apache.lucene.index;
  * limitations under the License.
  */
 
+import java.util.Random;
+
 import org.apache.lucene.index.SegmentReader.Norm;
 import org.apache.lucene.search.Similarity;
 import org.apache.lucene.analysis.SimpleAnalyzer;
@@ -33,11 +35,18 @@ import org.apache.lucene.util.LuceneTest
  * implemented properly
  */
 public class TestIndexReaderClone extends LuceneTestCase {
-
+  Random random;
+  
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    random = newRandom();
+  }
+  
   public void testCloneReadOnlySegmentReader() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
 
-    TestIndexReaderReopen.createIndex(dir1, false);
+    TestIndexReaderReopen.createIndex(random, dir1, false);
     IndexReader reader = IndexReader.open(dir1, false);
     IndexReader readOnlyReader = reader.clone(true);
     if (!isReadOnly(readOnlyReader)) {
@@ -56,7 +65,7 @@ public class TestIndexReaderClone extend
   public void testCloneNoChangesStillReadOnly() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
 
-    TestIndexReaderReopen.createIndex(dir1, true);
+    TestIndexReaderReopen.createIndex(random, dir1, true);
     IndexReader r1 = IndexReader.open(dir1, false);
     IndexReader r2 = r1.clone(false);
     if (!deleteWorked(1, r2)) {
@@ -72,7 +81,7 @@ public class TestIndexReaderClone extend
   public void testCloneWriteToOrig() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
 
-    TestIndexReaderReopen.createIndex(dir1, true);
+    TestIndexReaderReopen.createIndex(random, dir1, true);
     IndexReader r1 = IndexReader.open(dir1, false);
     IndexReader r2 = r1.clone(false);
     if (!deleteWorked(1, r1)) {
@@ -88,7 +97,7 @@ public class TestIndexReaderClone extend
   public void testCloneWriteToClone() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
 
-    TestIndexReaderReopen.createIndex(dir1, true);
+    TestIndexReaderReopen.createIndex(random, dir1, true);
     IndexReader r1 = IndexReader.open(dir1, false);
     IndexReader r2 = r1.clone(false);
     if (!deleteWorked(1, r2)) {
@@ -111,7 +120,7 @@ public class TestIndexReaderClone extend
   public void testReopenSegmentReaderToMultiReader() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
 
-    TestIndexReaderReopen.createIndex(dir1, false);
+    TestIndexReaderReopen.createIndex(random, dir1, false);
     IndexReader reader1 = IndexReader.open(dir1, false);
 
     TestIndexReaderReopen.modifyIndex(5, dir1);
@@ -129,7 +138,7 @@ public class TestIndexReaderClone extend
   public void testCloneWriteableToReadOnly() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
 
-    TestIndexReaderReopen.createIndex(dir1, true);
+    TestIndexReaderReopen.createIndex(random, dir1, true);
     IndexReader reader = IndexReader.open(dir1, false);
     IndexReader readOnlyReader = reader.clone(true);
     if (!isReadOnly(readOnlyReader)) {
@@ -151,7 +160,7 @@ public class TestIndexReaderClone extend
   public void testReopenWriteableToReadOnly() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
 
-    TestIndexReaderReopen.createIndex(dir1, true);
+    TestIndexReaderReopen.createIndex(random, dir1, true);
     IndexReader reader = IndexReader.open(dir1, false);
     final int docCount = reader.numDocs();
     assertTrue(deleteWorked(1, reader));
@@ -172,7 +181,7 @@ public class TestIndexReaderClone extend
   public void testCloneReadOnlyToWriteable() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
 
-    TestIndexReaderReopen.createIndex(dir1, true);
+    TestIndexReaderReopen.createIndex(random, dir1, true);
     IndexReader reader1 = IndexReader.open(dir1, true);
 
     IndexReader reader2 = reader1.clone(false);
@@ -195,9 +204,9 @@ public class TestIndexReaderClone extend
   public void testReadOnlyCloneAfterOptimize() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
 
-    TestIndexReaderReopen.createIndex(dir1, true);
+    TestIndexReaderReopen.createIndex(random, dir1, true);
     IndexReader reader1 = IndexReader.open(dir1, false);
-    IndexWriter w = new IndexWriter(dir1, new IndexWriterConfig(
+    IndexWriter w = new IndexWriter(dir1, newIndexWriterConfig(random,
         TEST_VERSION_CURRENT, new SimpleAnalyzer(TEST_VERSION_CURRENT)));
     w.optimize();
     w.close();
@@ -222,7 +231,7 @@ public class TestIndexReaderClone extend
   public void testCloneReadOnlyDirectoryReader() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
 
-    TestIndexReaderReopen.createIndex(dir1, true);
+    TestIndexReaderReopen.createIndex(random, dir1, true);
     IndexReader reader = IndexReader.open(dir1, false);
     IndexReader readOnlyReader = reader.clone(true);
     if (!isReadOnly(readOnlyReader)) {
@@ -242,9 +251,9 @@ public class TestIndexReaderClone extend
 
   public void testParallelReader() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
-    TestIndexReaderReopen.createIndex(dir1, true);
+    TestIndexReaderReopen.createIndex(random, dir1, true);
     final Directory dir2 = new MockRAMDirectory();
-    TestIndexReaderReopen.createIndex(dir2, true);
+    TestIndexReaderReopen.createIndex(random, dir2, true);
     IndexReader r1 = IndexReader.open(dir1, false);
     IndexReader r2 = IndexReader.open(dir2, false);
 
@@ -292,9 +301,9 @@ public class TestIndexReaderClone extend
 
   public void testMixedReaders() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
-    TestIndexReaderReopen.createIndex(dir1, true);
+    TestIndexReaderReopen.createIndex(random, dir1, true);
     final Directory dir2 = new MockRAMDirectory();
-    TestIndexReaderReopen.createIndex(dir2, true);
+    TestIndexReaderReopen.createIndex(random, dir2, true);
     IndexReader r1 = IndexReader.open(dir1, false);
     IndexReader r2 = IndexReader.open(dir2, false);
 
@@ -307,7 +316,7 @@ public class TestIndexReaderClone extend
 
   public void testSegmentReaderUndeleteall() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
-    TestIndexReaderReopen.createIndex(dir1, false);
+    TestIndexReaderReopen.createIndex(random, dir1, false);
     SegmentReader origSegmentReader = SegmentReader.getOnlySegmentReader(dir1);
     origSegmentReader.deleteDocument(10);
     assertDelDocsRefCountEquals(1, origSegmentReader);
@@ -320,7 +329,7 @@ public class TestIndexReaderClone extend
   
   public void testSegmentReaderCloseReferencing() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
-    TestIndexReaderReopen.createIndex(dir1, false);
+    TestIndexReaderReopen.createIndex(random, dir1, false);
     SegmentReader origSegmentReader = SegmentReader.getOnlySegmentReader(dir1);
     origSegmentReader.deleteDocument(1);
     origSegmentReader.setNorm(4, "field1", 0.5f);
@@ -339,7 +348,7 @@ public class TestIndexReaderClone extend
   
   public void testSegmentReaderDelDocsReferenceCounting() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
-    TestIndexReaderReopen.createIndex(dir1, false);
+    TestIndexReaderReopen.createIndex(random, dir1, false);
 
     IndexReader origReader = IndexReader.open(dir1, false);
     SegmentReader origSegmentReader = SegmentReader.getOnlySegmentReader(origReader);
@@ -402,7 +411,7 @@ public class TestIndexReaderClone extend
   // LUCENE-1648
   public void testCloneWithDeletes() throws Throwable {
     final Directory dir1 = new MockRAMDirectory();
-    TestIndexReaderReopen.createIndex(dir1, false);
+    TestIndexReaderReopen.createIndex(random, dir1, false);
     IndexReader origReader = IndexReader.open(dir1, false);
     origReader.deleteDocument(1);
 
@@ -419,7 +428,7 @@ public class TestIndexReaderClone extend
   // LUCENE-1648
   public void testCloneWithSetNorm() throws Throwable {
     final Directory dir1 = new MockRAMDirectory();
-    TestIndexReaderReopen.createIndex(dir1, false);
+    TestIndexReaderReopen.createIndex(random, dir1, false);
     IndexReader orig = IndexReader.open(dir1, false);
     orig.setNorm(1, "field1", 17.0f);
     final byte encoded = Similarity.getDefault().encodeNormValue(17.0f);
@@ -449,7 +458,7 @@ public class TestIndexReaderClone extend
   public void testCloneSubreaders() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
  
-    TestIndexReaderReopen.createIndex(dir1, true);
+    TestIndexReaderReopen.createIndex(random, dir1, true);
     IndexReader reader = IndexReader.open(dir1, false);
     reader.deleteDocument(1); // acquire write lock
     IndexReader[] subs = reader.getSequentialSubReaders();
@@ -468,7 +477,7 @@ public class TestIndexReaderClone extend
 
   public void testLucene1516Bug() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
-    TestIndexReaderReopen.createIndex(dir1, false);
+    TestIndexReaderReopen.createIndex(random, dir1, false);
     IndexReader r1 = IndexReader.open(dir1, false);
     r1.incRef();
     IndexReader r2 = r1.clone(false);
@@ -485,7 +494,7 @@ public class TestIndexReaderClone extend
 
   public void testCloseStoredFields() throws Exception {
     final Directory dir = new MockRAMDirectory();
-    IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random,
         TEST_VERSION_CURRENT, new SimpleAnalyzer(TEST_VERSION_CURRENT)));
     ((LogMergePolicy) w.getConfig().getMergePolicy()).setUseCompoundFile(false);
     ((LogMergePolicy) w.getConfig().getMergePolicy()).setUseCompoundDocStore(false);

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java?rev=984298&r1=984297&r2=984298&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java Wed Aug 11 04:01:46 2010
@@ -20,6 +20,7 @@ package org.apache.lucene.index;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Random;
 
 import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.lucene.analysis.Analyzer;
@@ -83,6 +84,7 @@ public class TestIndexReaderCloneNorms e
    */
   public void testNorms() throws IOException {
     // test with a single index: index1
+    Random random = newRandom();
     File indexDir1 = new File(TEMP_DIR, "lucenetestindex1");
     Directory dir1 = FSDirectory.open(indexDir1);
     IndexWriter.unlock(dir1);
@@ -90,8 +92,8 @@ public class TestIndexReaderCloneNorms e
     norms = new ArrayList<Float>();
     modifiedNorms = new ArrayList<Float>();
 
-    createIndex(dir1);
-    doTestNorms(dir1);
+    createIndex(random, dir1);
+    doTestNorms(random, dir1);
 
     // test with a single index: index2
     ArrayList<Float> norms1 = norms;
@@ -105,15 +107,15 @@ public class TestIndexReaderCloneNorms e
     File indexDir2 = new File(TEMP_DIR, "lucenetestindex2");
     Directory dir2 = FSDirectory.open(indexDir2);
 
-    createIndex(dir2);
-    doTestNorms(dir2);
+    createIndex(random, dir2);
+    doTestNorms(random, dir2);
 
     // add index1 and index2 to a third index: index3
     File indexDir3 = new File(TEMP_DIR, "lucenetestindex3");
     Directory dir3 = FSDirectory.open(indexDir3);
 
-    createIndex(dir3);
-    IndexWriter iw = new IndexWriter(dir3, new IndexWriterConfig(
+    createIndex(random, dir3);
+    IndexWriter iw = new IndexWriter(dir3, newIndexWriterConfig(random,
         TEST_VERSION_CURRENT, anlzr).setOpenMode(OpenMode.APPEND)
         .setMaxBufferedDocs(5));
     ((LogMergePolicy) iw.getConfig().getMergePolicy()).setMergeFactor(3);
@@ -129,10 +131,10 @@ public class TestIndexReaderCloneNorms e
 
     // test with index3
     verifyIndex(dir3);
-    doTestNorms(dir3);
+    doTestNorms(random, dir3);
 
     // now with optimize
-    iw = new IndexWriter(dir3, new IndexWriterConfig(TEST_VERSION_CURRENT,
+    iw = new IndexWriter(dir3, newIndexWriterConfig(random, TEST_VERSION_CURRENT,
         anlzr).setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(5));
     ((LogMergePolicy) iw.getConfig().getMergePolicy()).setMergeFactor(3);
     iw.optimize();
@@ -145,8 +147,8 @@ public class TestIndexReaderCloneNorms e
   }
 
   // try cloning and reopening the norms
-  private void doTestNorms(Directory dir) throws IOException {
-    addDocs(dir, 12, true);
+  private void doTestNorms(Random random, Directory dir) throws IOException {
+    addDocs(random, dir, 12, true);
     IndexReader ir = IndexReader.open(dir, false);
     verifyIndex(ir);
     modifyNormsForF1(ir);
@@ -165,7 +167,7 @@ public class TestIndexReaderCloneNorms e
   
   public void testNormsClose() throws IOException { 
     Directory dir1 = new MockRAMDirectory(); 
-    TestIndexReaderReopen.createIndex(dir1, false);
+    TestIndexReaderReopen.createIndex(newRandom(), dir1, false);
     SegmentReader reader1 = SegmentReader.getOnlySegmentReader(dir1);
     reader1.norms("field1");
     Norm r1norm = reader1.norms.get("field1");
@@ -181,7 +183,7 @@ public class TestIndexReaderCloneNorms e
   
   public void testNormsRefCounting() throws IOException { 
     Directory dir1 = new MockRAMDirectory(); 
-    TestIndexReaderReopen.createIndex(dir1, false);
+    TestIndexReaderReopen.createIndex(newRandom(), dir1, false);
     IndexReader reader1 = IndexReader.open(dir1, false);
         
     IndexReader reader2C = (IndexReader) reader1.clone();
@@ -232,8 +234,8 @@ public class TestIndexReaderCloneNorms e
     dir1.close();
   }
   
-  private void createIndex(Directory dir) throws IOException {
-    IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(
+  private void createIndex(Random random, Directory dir) throws IOException {
+    IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(random,
         TEST_VERSION_CURRENT, anlzr).setOpenMode(OpenMode.CREATE)
         .setMaxBufferedDocs(5).setSimilarity(similarityOne));
     LogMergePolicy lmp = (LogMergePolicy) iw.getConfig().getMergePolicy();
@@ -284,9 +286,9 @@ public class TestIndexReaderCloneNorms e
     }
   }
 
-  private void addDocs(Directory dir, int ndocs, boolean compound)
+  private void addDocs(Random random, Directory dir, int ndocs, boolean compound)
       throws IOException {
-    IndexWriterConfig conf = new IndexWriterConfig(
+    IndexWriterConfig conf = newIndexWriterConfig(random,
             TEST_VERSION_CURRENT, anlzr).setOpenMode(OpenMode.APPEND)
             .setMaxBufferedDocs(5).setSimilarity(similarityOne);
     LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java?rev=984298&r1=984297&r2=984298&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java Wed Aug 11 04:01:46 2010
@@ -54,8 +54,9 @@ public class TestIndexReaderReopen exten
   
   public void testReopen() throws Exception {
     final Directory dir1 = new MockRAMDirectory();
+    Random random = newRandom();
     
-    createIndex(dir1, false);
+    createIndex(random, dir1, false);
     performDefaultTests(new TestReopen() {
 
       @Override
@@ -73,7 +74,7 @@ public class TestIndexReaderReopen exten
     
     final Directory dir2 = new MockRAMDirectory();
     
-    createIndex(dir2, true);
+    createIndex(random, dir2, true);
     performDefaultTests(new TestReopen() {
 
       @Override
@@ -91,10 +92,11 @@ public class TestIndexReaderReopen exten
   }
   
   public void testParallelReaderReopen() throws Exception {
+    Random random = newRandom();
     final Directory dir1 = new MockRAMDirectory();
-    createIndex(dir1, true);
+    createIndex(random, dir1, true);
     final Directory dir2 = new MockRAMDirectory();
-    createIndex(dir2, true);
+    createIndex(random, dir2, true);
     
     performDefaultTests(new TestReopen() {
 
@@ -117,9 +119,9 @@ public class TestIndexReaderReopen exten
     dir2.close();
     
     final Directory dir3 = new MockRAMDirectory();
-    createIndex(dir3, true);
+    createIndex(random, dir3, true);
     final Directory dir4 = new MockRAMDirectory();
-    createIndex(dir4, true);
+    createIndex(random, dir4, true);
 
     performTestsWithExceptionInReopen(new TestReopen() {
 
@@ -152,26 +154,26 @@ public class TestIndexReaderReopen exten
   // try this once with reopen once recreate, on both RAMDir and FSDir.
   public void testCommitReopenFS () throws IOException {
     Directory dir = FSDirectory.open(indexDir);
-    doTestReopenWithCommit(dir, true);
+    doTestReopenWithCommit(newRandom(), dir, true);
     dir.close();
   }
   public void testCommitRecreateFS () throws IOException {
     Directory dir = FSDirectory.open(indexDir);
-    doTestReopenWithCommit(dir, false);
+    doTestReopenWithCommit(newRandom(), dir, false);
     dir.close();
   }
   public void testCommitReopenRAM () throws IOException {
     Directory dir = new MockRAMDirectory();
-    doTestReopenWithCommit(dir, true);
+    doTestReopenWithCommit(newRandom(), dir, true);
     dir.close();
   }
   public void testCommitRecreateRAM () throws IOException {
     Directory dir = new MockRAMDirectory();
-    doTestReopenWithCommit(dir, false);
+    doTestReopenWithCommit(newRandom(), dir, false);
   }
 
-  private void doTestReopenWithCommit (Directory dir, boolean withReopen) throws IOException {
-    IndexWriter iwriter = new IndexWriter(dir, new IndexWriterConfig(
+  private void doTestReopenWithCommit (Random random, Directory dir, boolean withReopen) throws IOException {
+    IndexWriter iwriter = new IndexWriter(dir, newIndexWriterConfig(random,
         TEST_VERSION_CURRENT, new KeywordAnalyzer()).setOpenMode(
         OpenMode.CREATE).setMergeScheduler(new SerialMergeScheduler()));
     iwriter.commit();
@@ -215,12 +217,12 @@ public class TestIndexReaderReopen exten
   }
   
   public void testMultiReaderReopen() throws Exception {
-
+    Random random = newRandom();
     final Directory dir1 = new MockRAMDirectory();
-    createIndex(dir1, true);
+    createIndex(random, dir1, true);
 
     final Directory dir2 = new MockRAMDirectory();
-    createIndex(dir2, true);
+    createIndex(random, dir2, true);
 
     performDefaultTests(new TestReopen() {
 
@@ -243,10 +245,10 @@ public class TestIndexReaderReopen exten
     dir2.close();
     
     final Directory dir3 = new MockRAMDirectory();
-    createIndex(dir3, true);
+    createIndex(random, dir3, true);
 
     final Directory dir4 = new MockRAMDirectory();
-    createIndex(dir4, true);
+    createIndex(random, dir4, true);
 
     performTestsWithExceptionInReopen(new TestReopen() {
 
@@ -272,16 +274,17 @@ public class TestIndexReaderReopen exten
   }
 
   public void testMixedReaders() throws Exception {
+    Random random = newRandom();
     final Directory dir1 = new MockRAMDirectory();
-    createIndex(dir1, true);
+    createIndex(random, dir1, true);
     final Directory dir2 = new MockRAMDirectory();
-    createIndex(dir2, true);
+    createIndex(random, dir2, true);
     final Directory dir3 = new MockRAMDirectory();
-    createIndex(dir3, false);
+    createIndex(random, dir3, false);
     final Directory dir4 = new MockRAMDirectory();
-    createIndex(dir4, true);
+    createIndex(random, dir4, true);
     final Directory dir5 = new MockRAMDirectory();
-    createIndex(dir5, false);
+    createIndex(random, dir5, false);
     
     performDefaultTests(new TestReopen() {
 
@@ -359,10 +362,10 @@ public class TestIndexReaderReopen exten
   }
   
   public void testReferenceCounting() throws IOException {
-   
+    Random random = newRandom();
     for (int mode = 0; mode < 4; mode++) {
       Directory dir1 = new MockRAMDirectory();
-      createIndex(dir1, true);
+      createIndex(random, dir1, true);
      
       IndexReader reader0 = IndexReader.open(dir1, false);
       assertRefCountEquals(1, reader0);
@@ -465,11 +468,12 @@ public class TestIndexReaderReopen exten
 
 
   public void testReferenceCountingMultiReader() throws IOException {
+    Random random = newRandom();
     for (int mode = 0; mode <=1; mode++) {
       Directory dir1 = new MockRAMDirectory();
-      createIndex(dir1, false);
+      createIndex(random, dir1, false);
       Directory dir2 = new MockRAMDirectory();
-      createIndex(dir2, true);
+      createIndex(random, dir2, true);
       
       IndexReader reader1 = IndexReader.open(dir1, false);
       assertRefCountEquals(1, reader1);
@@ -536,11 +540,12 @@ public class TestIndexReaderReopen exten
   }
 
   public void testReferenceCountingParallelReader() throws IOException {
+    Random random = newRandom();
     for (int mode = 0; mode <=1; mode++) {
       Directory dir1 = new MockRAMDirectory();
-      createIndex(dir1, false);
+      createIndex(random, dir1, false);
       Directory dir2 = new MockRAMDirectory();
-      createIndex(dir2, true);
+      createIndex(random, dir2, true);
       
       IndexReader reader1 = IndexReader.open(dir1, false);
       assertRefCountEquals(1, reader1);
@@ -612,7 +617,7 @@ public class TestIndexReaderReopen exten
   
   public void testNormsRefCounting() throws IOException {
     Directory dir1 = new MockRAMDirectory();
-    createIndex(dir1, false);
+    createIndex(newRandom(), dir1, false);
     
     IndexReader reader1 = IndexReader.open(dir1, false);
     SegmentReader segmentReader1 = SegmentReader.getOnlySegmentReader(reader1);
@@ -703,8 +708,8 @@ public class TestIndexReaderReopen exten
   public void testThreadSafety() throws Exception {
     final Directory dir = new MockRAMDirectory();
     final int n = 30 * RANDOM_MULTIPLIER;
-
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+    Random random = newRandom();
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
         TEST_VERSION_CURRENT, new StandardAnalyzer(TEST_VERSION_CURRENT)));
     for (int i = 0; i < n; i++) {
       writer.addDocument(createDocument(i, 3));
@@ -740,7 +745,7 @@ public class TestIndexReaderReopen exten
     final List<ReaderCouple> readers = Collections.synchronizedList(new ArrayList<ReaderCouple>());
     IndexReader firstReader = IndexReader.open(dir, false);
     IndexReader reader = firstReader;
-    final Random rnd = newRandom();
+    final Random rnd = random;
     
     ReaderThread[] threads = new ReaderThread[n];
     final Set<IndexReader> readersToClose = Collections.synchronizedSet(new HashSet<IndexReader>());
@@ -948,9 +953,9 @@ public class TestIndexReaderReopen exten
     }
   }
   
-  public static void createIndex(Directory dir, boolean multiSegment) throws IOException {
+  public static void createIndex(Random random, Directory dir, boolean multiSegment) throws IOException {
     IndexWriter.unlock(dir);
-    IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random,
         TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
         .setMergePolicy(new LogDocMergePolicy()));
     
@@ -1103,7 +1108,7 @@ public class TestIndexReaderReopen exten
   
   public void testCloseOrig() throws Throwable {
     Directory dir = new MockRAMDirectory();
-    createIndex(dir, false);
+    createIndex(newRandom(), dir, false);
     IndexReader r1 = IndexReader.open(dir, false);
     IndexReader r2 = IndexReader.open(dir, false);
     r2.deleteDocument(0);
@@ -1124,7 +1129,7 @@ public class TestIndexReaderReopen exten
 
   public void testDeletes() throws Throwable {
     Directory dir = new MockRAMDirectory();
-    createIndex(dir, false); // Create an index with a bunch of docs (1 segment)
+    createIndex(newRandom(), dir, false); // Create an index with a bunch of docs (1 segment)
 
     modifyIndex(0, dir); // Get delete bitVector on 1st segment
     modifyIndex(5, dir); // Add a doc (2 segments)
@@ -1157,7 +1162,7 @@ public class TestIndexReaderReopen exten
 
   public void testDeletes2() throws Throwable {
     Directory dir = new MockRAMDirectory();
-    createIndex(dir, false);
+    createIndex(newRandom(), dir, false);
     // Get delete bitVector
     modifyIndex(0, dir);
     IndexReader r1 = IndexReader.open(dir, false);
@@ -1193,8 +1198,9 @@ public class TestIndexReaderReopen exten
 
   public void testReopenOnCommit() throws Throwable {
     Directory dir = new MockRAMDirectory();
-    IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
-        TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setIndexDeletionPolicy(new KeepAllCommits()));
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(),
+        TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setIndexDeletionPolicy(new KeepAllCommits()).setMaxBufferedDocs(-1));
+    ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(10);
     for(int i=0;i<4;i++) {
       Document doc = new Document();
       doc.add(new Field("id", ""+i, Field.Store.NO, Field.Index.NOT_ANALYZED));



Mime
View raw message