Apache Solr open-source search software
LUCENE-2386: reverting previous commit due to failing Solr tests
Shai Ererae525dbd83f32
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex ffa7143da2d..46cb73c95c2 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -105,12 +105,6 @@ Changes in backwards compatibility policyof incrementToken(), tokenStream(), and reusableTokenStream().(Uwe Schindler, Robert Muir)-* LUCENE-2386: IndexWriter no longer performs an empty commit upon new index- creation. Previously, if you passed an empty Directory and set OpenMode to- CREATE*, IndexWriter would make a first empty commit. If you need that- behavior you can call writer.commit() immediately after you create it.- (Shai Erera, Mike McCandless)-Changes in runtime behavior* LUCENE-1923: Made IndexReader.toString() produce somethingdiff --git a/lucene/backwards/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java b/lucene/backwards/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.javaindex 02d0227de6b..89a57571d9b 100644--- a/lucene/backwards/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java+++ b/lucene/backwards/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java@@ -113,7 +113,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseSnapshotDeletionPolicy dp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());final IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT), dp, IndexWriter.MaxFieldLength.UNLIMITED);- writer.commit();+// Force frequent flusheswriter.setMaxBufferedDocs(2);diff --git a/lucene/backwards/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java b/lucene/backwards/src/test/org/apache/lucene/index/TestBackwardsCompatibility.javaindex bb09f9b4ea9..07a7668f4ea 100644--- a/lucene/backwards/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java+++ b/lucene/backwards/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java@@ -553,7 +553,7 @@ public class TestBackwardsCompatibility extends LuceneTestCaseexpected = new String[] {"_0.cfs","_0_1.del","_0_1.s" + contentFieldIndex,- "segments_2",+ "segments_3","segments.gen"};String[] actual = dir.listAll();diff --git a/lucene/backwards/src/test/org/apache/lucene/index/TestCrash.java b/lucene/backwards/src/test/org/apache/lucene/index/TestCrash.javaindex 9bedfb68a39..09275e263c8 100644--- a/lucene/backwards/src/test/org/apache/lucene/index/TestCrash.java+++ b/lucene/backwards/src/test/org/apache/lucene/index/TestCrash.java@@ -25,24 +25,20 @@ import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.store.NoLockFactory;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;-import org.apache.lucene.index.IndexWriter;public class TestCrash extends LuceneTestCase {- private IndexWriter initIndex(boolean initialCommit) throws IOException {- return initIndex(new MockRAMDirectory(), initialCommit);+ private IndexWriter initIndex() throws IOException {+ return initIndex(new MockRAMDirectory());}- private IndexWriter initIndex(MockRAMDirectory dir, boolean initialCommit) throws IOException {+ private IndexWriter initIndex(MockRAMDirectory dir) throws IOException {dir.setLockFactory(NoLockFactory.getNoLockFactory());IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);//writer.setMaxBufferedDocs(2);writer.setMaxBufferedDocs(10);((ConcurrentMergeScheduler) writer.getMergeScheduler()).setSuppressExceptions();- if (initialCommit) {- writer.commit();- }Document doc = new Document();doc.add(new Field("content", "aaa", Field.Store.YES, Field.Index.ANALYZED));@@ -62,7 +58,7 @@ public class TestCrash extends LuceneTestCase {}public void testCrashWhileIndexing() throws IOException {- IndexWriter writer = initIndex(true);+ IndexWriter writer = initIndex();MockRAMDirectory dir = (MockRAMDirectory) writer.getDirectory();crash(writer);IndexReader reader = IndexReader.open(dir, false);@@ -70,11 +66,11 @@ public class TestCrash extends LuceneTestCase {}public void testWriterAfterCrash() throws IOException {- IndexWriter writer = initIndex(true);+ IndexWriter writer = initIndex();MockRAMDirectory dir = (MockRAMDirectory) writer.getDirectory();dir.setPreventDoubleWrite(false);crash(writer);- writer = initIndex(dir, false);+ writer = initIndex(dir);writer.close();IndexReader reader = IndexReader.open(dir, false);@@ -82,10 +78,10 @@ public class TestCrash extends LuceneTestCase {}public void testCrashAfterReopen() throws IOException {- IndexWriter writer = initIndex(false);+ IndexWriter writer = initIndex();MockRAMDirectory dir = (MockRAMDirectory) writer.getDirectory();writer.close();- writer = initIndex(dir, false);+ writer = initIndex(dir);assertEquals(314, writer.maxDoc());crash(writer);@@ -104,7 +100,7 @@ public class TestCrash extends LuceneTestCase {public void testCrashAfterClose() throws IOException {- IndexWriter writer = initIndex(false);+ IndexWriter writer = initIndex();MockRAMDirectory dir = (MockRAMDirectory) writer.getDirectory();writer.close();@@ -123,7 +119,7 @@ public class TestCrash extends LuceneTestCase {public void testCrashAfterCloseNoWait() throws IOException {- IndexWriter writer = initIndex(false);+ IndexWriter writer = initIndex();MockRAMDirectory dir = (MockRAMDirectory) writer.getDirectory();writer.close(false);@@ -142,7 +138,7 @@ public class TestCrash extends LuceneTestCase {public void testCrashReaderDeletes() throws IOException {- IndexWriter writer = initIndex(false);+ IndexWriter writer = initIndex();MockRAMDirectory dir = (MockRAMDirectory) writer.getDirectory();writer.close(false);@@ -163,7 +159,7 @@ public class TestCrash extends LuceneTestCase {public void testCrashReaderDeletesAfterClose() throws IOException {- IndexWriter writer = initIndex(false);+ IndexWriter writer = initIndex();MockRAMDirectory dir = (MockRAMDirectory) writer.getDirectory();writer.close(false);diff --git a/lucene/backwards/src/test/org/apache/lucene/index/TestDeletionPolicy.java b/lucene/backwards/src/test/org/apache/lucene/index/TestDeletionPolicy.javaindex b7a7fefee3e..c4751ff9817 100644--- a/lucene/backwards/src/test/org/apache/lucene/index/TestDeletionPolicy.java+++ b/lucene/backwards/src/test/org/apache/lucene/index/TestDeletionPolicy.java@@ -290,7 +290,7 @@ public class TestDeletionPolicy extends LuceneTestCasewriter.optimize();writer.close();- assertEquals(1, policy.numOnInit);+ assertEquals(2, policy.numOnInit);// If we are not auto committing then there should// be exactly 2 commits (one per close above):@@ -298,8 +298,8 @@ public class TestDeletionPolicy extends LuceneTestCase// Test listCommitsCollection commits = IndexReader.listCommits(dir);- // 2 from closing writer- assertEquals(2, commits.size());+ // 1 from opening writer + 2 from closing writer+ assertEquals(3, commits.size());Iterator it = commits.iterator();// Make sure we can open a reader on each commit:@@ -357,7 +357,7 @@ public class TestDeletionPolicy extends LuceneTestCasewriter.close();Collection commits = IndexReader.listCommits(dir);- assertEquals(5, commits.size());+ assertEquals(6, commits.size());IndexCommit lastCommit = null;Iterator it = commits.iterator();while(it.hasNext()) {@@ -374,7 +374,7 @@ public class TestDeletionPolicy extends LuceneTestCasewriter.optimize();writer.close();- assertEquals(6, IndexReader.listCommits(dir).size());+ assertEquals(7, IndexReader.listCommits(dir).size());// Now open writer on the commit just before optimize:writer = new IndexWriter(dir, new WhitespaceAnalyzer(), policy, IndexWriter.MaxFieldLength.LIMITED, lastCommit);@@ -395,7 +395,7 @@ public class TestDeletionPolicy extends LuceneTestCasewriter.close();// Now 8 because we made another commit- assertEquals(7, IndexReader.listCommits(dir).size());+ assertEquals(8, IndexReader.listCommits(dir).size());r = IndexReader.open(dir, true);// Not optimized because we rolled it back, and now only@@ -465,7 +465,7 @@ public class TestDeletionPolicy extends LuceneTestCasewriter.optimize();writer.close();- assertEquals(1, policy.numOnInit);+ assertEquals(2, policy.numOnInit);// If we are not auto committing then there should// be exactly 2 commits (one per close above):assertEquals(2, policy.numOnCommit);@@ -506,7 +506,7 @@ public class TestDeletionPolicy extends LuceneTestCase}assertTrue(policy.numDelete > 0);- assertEquals(N, policy.numOnInit);+ assertEquals(N+1, policy.numOnInit);assertEquals(N+1, policy.numOnCommit);// Simplistic check: just verify only the past N segments_N's still@@ -580,8 +580,8 @@ public class TestDeletionPolicy extends LuceneTestCase// this is a commitwriter.close();- assertEquals(2*(N+1)+1, policy.numOnInit);- assertEquals(2*(N+2), policy.numOnCommit);+ assertEquals(2*(N+2), policy.numOnInit);+ assertEquals(2*(N+2)-1, policy.numOnCommit);IndexSearcher searcher = new IndexSearcher(dir, false);ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;@@ -678,8 +678,8 @@ public class TestDeletionPolicy extends LuceneTestCasewriter.close();}- assertEquals(3*(N+1), policy.numOnInit);- assertEquals(3*(N+1)+1, policy.numOnCommit);+ assertEquals(1+3*(N+1), policy.numOnInit);+ assertEquals(3*(N+1), policy.numOnCommit);IndexSearcher searcher = new IndexSearcher(dir, false);ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;diff --git a/lucene/backwards/src/test/org/apache/lucene/index/TestIndexFileDeleter.java b/lucene/backwards/src/test/org/apache/lucene/index/TestIndexFileDeleter.javaindex a23a2984292..3f9b716715c 100644--- a/lucene/backwards/src/test/org/apache/lucene/index/TestIndexFileDeleter.java+++ b/lucene/backwards/src/test/org/apache/lucene/index/TestIndexFileDeleter.java@@ -136,11 +136,11 @@ public class TestIndexFileDeleter extends LuceneTestCasecopyFile(dir, "_0.cfs", "deletable");// Create some old segments file:- copyFile(dir, "segments_2", "segments");- copyFile(dir, "segments_2", "segments_1");+ copyFile(dir, "segments_3", "segments");+ copyFile(dir, "segments_3", "segments_2");// Create a bogus cfs file shadowing a non-cfs segment:- copyFile(dir, "_1.cfs", "_2.cfs");+ copyFile(dir, "_2.cfs", "_3.cfs");String[] filesPre = dir.listAll();diff --git a/lucene/backwards/src/test/org/apache/lucene/index/TestIndexReader.java b/lucene/backwards/src/test/org/apache/lucene/index/TestIndexReader.javaindex 83acfb946a4..85dedd0151c 100644--- a/lucene/backwards/src/test/org/apache/lucene/index/TestIndexReader.java+++ b/lucene/backwards/src/test/org/apache/lucene/index/TestIndexReader.java@@ -39,7 +39,6 @@ import org.apache.lucene.document.Field;import org.apache.lucene.document.FieldSelector;import org.apache.lucene.document.Fieldable;import org.apache.lucene.document.SetBasedFieldSelector;-import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.IndexReader.FieldOption;import org.apache.lucene.search.FieldCache;import org.apache.lucene.search.IndexSearcher;@@ -475,7 +474,6 @@ public class TestIndexReader extends LuceneTestCase// add 11 documents with term : aaawriter = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);- writer.commit();for (int i = 0; i < 11; i++){addDoc(writer, searchTerm.text());@@ -1767,7 +1765,6 @@ public class TestIndexReader extends LuceneTestCasepublic void testPrepareCommitIsCurrent() throws Throwable {Directory dir = new MockRAMDirectory();IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);- writer.commit();Document doc = new Document();writer.addDocument(doc);IndexReader r = IndexReader.open(dir, true);diff --git a/lucene/backwards/src/test/org/apache/lucene/index/TestIndexReaderReopen.java b/lucene/backwards/src/test/org/apache/lucene/index/TestIndexReaderReopen.javaindex 1fcf011d026..56d97826f8f 100644--- a/lucene/backwards/src/test/org/apache/lucene/index/TestIndexReaderReopen.java+++ b/lucene/backwards/src/test/org/apache/lucene/index/TestIndexReaderReopen.java@@ -36,7 +36,6 @@ import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.document.Field.Index;import org.apache.lucene.document.Field.Store;-import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.IndexWriter.MaxFieldLength;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.ScoreDoc;@@ -173,7 +172,6 @@ public class TestIndexReaderReopen extends LuceneTestCase {private void doTestReopenWithCommit (Directory dir, boolean withReopen) throws IOException {IndexWriter iwriter = new IndexWriter(dir, new KeywordAnalyzer(), true, MaxFieldLength.LIMITED);iwriter.setMergeScheduler(new SerialMergeScheduler());- iwriter.commit();IndexReader reader = IndexReader.open(dir, false);try {int M = 3;diff --git a/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriter.javaindex b8367c2768b..a47ebe66104 100644--- a/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriter.java+++ b/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriter.java@@ -47,7 +47,6 @@ import org.apache.lucene.analysis.tokenattributes.TermAttribute;import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;-import org.apache.lucene.index.IndexWriter;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.PhraseQuery;import org.apache.lucene.search.Query;@@ -784,7 +783,7 @@ public class TestIndexWriter extends LuceneTestCase {writer.close();long gen = SegmentInfos.getCurrentSegmentGeneration(dir);- assertTrue("segment generation should be > 0 but got " + gen, gen > 0);+ assertTrue("segment generation should be > 1 but got " + gen, gen > 1);// Make the next segments file, with last byte// missing, to simulate a writer that crashed while@@ -844,7 +843,7 @@ public class TestIndexWriter extends LuceneTestCase {writer.close();long gen = SegmentInfos.getCurrentSegmentGeneration(dir);- assertTrue("segment generation should be > 0 but got " + gen, gen > 0);+ assertTrue("segment generation should be > 1 but got " + gen, gen > 1);String fileNameIn = SegmentInfos.getCurrentSegmentFileName(dir);String fileNameOut = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,@@ -909,7 +908,7 @@ public class TestIndexWriter extends LuceneTestCase {writer.close();long gen = SegmentInfos.getCurrentSegmentGeneration(dir);- assertTrue("segment generation should be > 0 but got " + gen, gen > 0);+ assertTrue("segment generation should be > 1 but got " + gen, gen > 1);String[] files = dir.listAll();for(int i=0;i<files.length;i++) {@@ -2325,7 +2324,7 @@ public class TestIndexWriter extends LuceneTestCase {public void testImmediateDiskFull() throws IOException {MockRAMDirectory dir = new MockRAMDirectory();IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);- dir.setMaxSizeInBytes(Math.max(1, dir.getRecomputedActualSizeInBytes()));+ dir.setMaxSizeInBytes(dir.getRecomputedActualSizeInBytes());writer.setMaxBufferedDocs(2);final Document doc = new Document();doc.add(new Field("field", "aaa bbb ccc ddd eee fff ggg hhh iii jjj", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));@@ -2648,7 +2647,7 @@ public class TestIndexWriter extends LuceneTestCase {writer.close();long gen = SegmentInfos.getCurrentSegmentGeneration(dir);- assertTrue("segment generation should be > 0 but got " + gen, gen > 0);+ assertTrue("segment generation should be > 1 but got " + gen, gen > 1);final String segmentsFileName = SegmentInfos.getCurrentSegmentFileName(dir);IndexInput in = dir.openInput(segmentsFileName);@@ -2676,8 +2675,7 @@ public class TestIndexWriter extends LuceneTestCase {IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);writer.setMaxBufferedDocs(2);writer.setMergeFactor(5);- writer.commit();-+for (int i = 0; i < 23; i++)addDoc(writer);@@ -3544,8 +3542,7 @@ public class TestIndexWriter extends LuceneTestCase {IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);writer.setMaxBufferedDocs(2);writer.setMergeFactor(5);- writer.commit();-+for (int i = 0; i < 23; i++)addDoc(writer);@@ -3598,8 +3595,7 @@ public class TestIndexWriter extends LuceneTestCase {writer.setMaxBufferedDocs(2);writer.setMergeFactor(5);- writer.commit();-+for (int i = 0; i < 23; i++)addDoc(writer);@@ -3683,7 +3679,6 @@ public class TestIndexWriter extends LuceneTestCase {dir2 = new MockRAMDirectory();writer2 = new IndexWriter(dir2, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);- writer2.commit();cms = (ConcurrentMergeScheduler) writer2.getMergeScheduler();readers = new IndexReader[NUM_COPY];diff --git a/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterDelete.java b/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterDelete.javaindex d030d3fa09b..2a866128cb6 100644--- a/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterDelete.java+++ b/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterDelete.java@@ -23,7 +23,6 @@ import java.util.Arrays;import org.apache.lucene.analysis.WhitespaceAnalyzer;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;-import org.apache.lucene.index.IndexWriter;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.ScoreDoc;import org.apache.lucene.search.TermQuery;@@ -765,7 +764,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {MockRAMDirectory dir = new MockRAMDirectory();IndexWriter modifier = new IndexWriter(dir,new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);- modifier.commit();+dir.failOn(failure.reset());for (int i = 0; i < keywords.length; i++) {diff --git a/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java b/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterExceptions.javaindex e0edca32d8f..babc13bb4ba 100644--- a/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java+++ b/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java@@ -138,8 +138,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {((ConcurrentMergeScheduler) writer.getMergeScheduler()).setSuppressExceptions();//writer.setMaxBufferedDocs(10);writer.setRAMBufferSizeMB(0.1);- writer.commit();-+if (DEBUG)writer.setInfoStream(System.out);@@ -177,7 +176,6 @@ public class TestIndexWriterExceptions extends LuceneTestCase {((ConcurrentMergeScheduler) writer.getMergeScheduler()).setSuppressExceptions();//writer.setMaxBufferedDocs(10);writer.setRAMBufferSizeMB(0.2);- writer.commit();if (DEBUG)writer.setInfoStream(System.out);diff --git a/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterReader.java b/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterReader.javaindex 6c8799dec8c..38be635561d 100644--- a/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterReader.java+++ b/lucene/backwards/src/test/org/apache/lucene/index/TestIndexWriterReader.java@@ -30,7 +30,6 @@ import org.apache.lucene.document.Field;import org.apache.lucene.document.Field.Index;import org.apache.lucene.document.Field.Store;import org.apache.lucene.document.Field.TermVector;-import org.apache.lucene.index.IndexWriter;import org.apache.lucene.search.TermQuery;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.Query;@@ -643,7 +642,6 @@ public class TestIndexWriterReader extends LuceneTestCase {Directory dir1 = new MockRAMDirectory();IndexWriter writer = new IndexWriter(dir1, new WhitespaceAnalyzer(),IndexWriter.MaxFieldLength.LIMITED);- writer.commit();writer.setInfoStream(infoStream);// create the indexdiff --git a/lucene/backwards/src/test/org/apache/lucene/index/TestStressIndexing.java b/lucene/backwards/src/test/org/apache/lucene/index/TestStressIndexing.javaindex cc3de2a2090..01c51d5a825 100644--- a/lucene/backwards/src/test/org/apache/lucene/index/TestStressIndexing.java+++ b/lucene/backwards/src/test/org/apache/lucene/index/TestStressIndexing.java@@ -19,7 +19,6 @@ package org.apache.lucene.index;import org.apache.lucene.util.*;import org.apache.lucene.store.*;import org.apache.lucene.document.*;-import org.apache.lucene.index.IndexWriter;import org.apache.lucene.analysis.*;import org.apache.lucene.search.*;import org.apache.lucene.queryParser.*;@@ -122,7 +121,7 @@ public class TestStressIndexing extends LuceneTestCase {*/public void runStressTest(Directory directory, MergeScheduler mergeScheduler) throws Exception {IndexWriter modifier = new IndexWriter(directory, ANALYZER, true, IndexWriter.MaxFieldLength.UNLIMITED);- modifier.commit();+modifier.setMaxBufferedDocs(10);TimedThread[] threads = new TimedThread[4];diff --git a/lucene/backwards/src/test/org/apache/lucene/index/TestStressIndexing2.java b/lucene/backwards/src/test/org/apache/lucene/index/TestStressIndexing2.javaindex 0d7a8dabae3..0f02bcdaeb5 100644--- a/lucene/backwards/src/test/org/apache/lucene/index/TestStressIndexing2.java+++ b/lucene/backwards/src/test/org/apache/lucene/index/TestStressIndexing2.java@@ -16,7 +16,6 @@ package org.apache.lucene.index;import org.apache.lucene.store.*;import org.apache.lucene.document.*;-import org.apache.lucene.index.IndexWriter;import org.apache.lucene.analysis.*;import org.apache.lucene.util.LuceneTestCase;@@ -125,7 +124,6 @@ public class TestStressIndexing2 extends LuceneTestCase {public DocsAndWriter indexRandomIWReader(int nThreads, int iterations, int range, Directory dir) throws IOException, InterruptedException {Map docs = new HashMap();IndexWriter w = new MockIndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);- w.commit();w.setUseCompoundFile(false);/***diff --git a/lucene/backwards/src/test/org/apache/lucene/store/TestBufferedIndexInput.java b/lucene/backwards/src/test/org/apache/lucene/store/TestBufferedIndexInput.javaindex e89a4f7e075..def32daddb6 100755--- a/lucene/backwards/src/test/org/apache/lucene/store/TestBufferedIndexInput.java+++ b/lucene/backwards/src/test/org/apache/lucene/store/TestBufferedIndexInput.java@@ -241,7 +241,6 @@ public class TestBufferedIndexInput extends LuceneTestCase {public void testSetBufferSize() throws IOException {File indexDir = new File(System.getProperty("tempDir"), "testSetBufferSize");- indexDir.mkdirs(); // required for this MockFSDir since we don't commit on IW creation anymore.MockFSDirectory dir = new MockFSDirectory(indexDir, newRandom());try {IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);diff --git a/lucene/backwards/src/test/org/apache/lucene/store/TestLockFactory.java b/lucene/backwards/src/test/org/apache/lucene/store/TestLockFactory.javaindex 37bb83e3772..75215840b09 100755--- a/lucene/backwards/src/test/org/apache/lucene/store/TestLockFactory.java+++ b/lucene/backwards/src/test/org/apache/lucene/store/TestLockFactory.java@@ -85,8 +85,7 @@ public class TestLockFactory extends LuceneTestCase {IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true,IndexWriter.MaxFieldLength.LIMITED);- writer.commit(); // required so the second open succeed-+// Create a 2nd IndexWriter. This is normally not allowed but it should run through since we're not// using any locks:IndexWriter writer2 = null;diff --git a/lucene/backwards/src/test/org/apache/lucene/store/TestWindowsMMap.java b/lucene/backwards/src/test/org/apache/lucene/store/TestWindowsMMap.javaindex d1e54410136..45aa61b0b4d 100644--- a/lucene/backwards/src/test/org/apache/lucene/store/TestWindowsMMap.java+++ b/lucene/backwards/src/test/org/apache/lucene/store/TestWindowsMMap.java@@ -64,18 +64,14 @@ public class TestWindowsMMap extends LuceneTestCase {new File(System.getProperty("tempDir"),"testLuceneMmap").getAbsolutePath();public void testMmapIndex() throws Exception {- // sometimes the directory is not cleaned by rmDir, because on Windows it- // may take some time until the files are finally dereferenced. So clean the- // directory up front, or otherwise new IndexWriter will fail.- rmDir(new File(storePathname));- FSDirectory storeDirectory = new MMapDirectory(new File(storePathname), null);+ FSDirectory storeDirectory;+ storeDirectory = new MMapDirectory(new File(storePathname), null);// plan to add a set of useful stopwords, consider changing some of the// interior filters.StandardAnalyzer analyzer = new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT, Collections.emptySet());// TODO: something about lock timeouts and leftover locks.IndexWriter writer = new IndexWriter(storeDirectory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);- writer.commit();IndexSearcher searcher = new IndexSearcher(storeDirectory, true);for(int dx = 0; dx < 1000; dx ++) {@@ -87,16 +83,14 @@ public class TestWindowsMMap extends LuceneTestCase {searcher.close();writer.close();- rmDir(new File(storePathname));+ rmDir(new File(storePathname));}- private void rmDir(File dir) {- if (!dir.exists()) {- return;- }- for (File file : dir.listFiles()) {- file.delete();- }- dir.delete();- }+ private void rmDir(File dir) {+ File[] files = dir.listFiles();+ for (int i = 0; i < files.length; i++) {+ files[i].delete();+ }+ dir.delete();+ }}diff --git a/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/builders/TestNumericRangeFilterBuilder.java b/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/builders/TestNumericRangeFilterBuilder.javaindex b5f4915f851..5e7fe7b7ffc 100644--- a/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/builders/TestNumericRangeFilterBuilder.java+++ b/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/builders/TestNumericRangeFilterBuilder.java@@ -29,7 +29,6 @@ import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.IndexWriter;-import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.IndexWriter.MaxFieldLength;import org.apache.lucene.search.Filter;import org.apache.lucene.search.NumericRangeFilter;@@ -63,8 +62,7 @@ public class TestNumericRangeFilterBuilder extends LuceneTestCase {Filter filter = filterBuilder.getFilter(doc.getDocumentElement());RAMDirectory ramDir = new RAMDirectory();- IndexWriter writer = new IndexWriter(ramDir, new IndexWriterConfig(TEST_VERSION_CURRENT, null));- writer.commit();+ IndexWriter writer = new IndexWriter(ramDir, null, MaxFieldLength.UNLIMITED);try{IndexReader reader = IndexReader.open(ramDir, true);diff --git a/lucene/src/java/org/apache/lucene/index/DirectoryReader.java b/lucene/src/java/org/apache/lucene/index/DirectoryReader.javaindex 9833efbc14e..7abf4c71854 100644--- a/lucene/src/java/org/apache/lucene/index/DirectoryReader.java+++ b/lucene/src/java/org/apache/lucene/index/DirectoryReader.java@@ -1030,11 +1030,7 @@ class DirectoryReader extends IndexReader implements Cloneable {Collection<IndexCommit> commits = new ArrayList<IndexCommit>();SegmentInfos latest = new SegmentInfos();- try {- latest.read(dir, codecs);- } catch (IndexNotFoundException e) {- return Collections.emptyList();- }+ latest.read(dir, codecs);final long currentGen = latest.getGeneration();commits.add(new ReaderCommit(latest, dir));diff --git a/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java b/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.javaindex 88169bb7353..5059435bad5 100644--- a/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java+++ b/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java@@ -144,13 +144,16 @@ final class IndexFileDeleter {long currentGen = segmentInfos.getGeneration();indexFilenameFilter = new IndexFileNameFilter(codecs);+ String[] files = directory.listAll();+CommitPoint currentCommitPoint = null;- boolean seenIndexFiles = false;- for (String fileName : directory.listAll()) {++ for(int i=0;i<files.length;i++) {++ String fileName = files[i];if ((indexFilenameFilter.accept(null, fileName)) && !fileName.endsWith("write.lock") && !fileName.equals(IndexFileNames.SEGMENTS_GEN)) {- seenIndexFiles = true;-+// Add this file to refCounts with initial count 0:getRefCount(fileName);@@ -192,10 +195,7 @@ final class IndexFileDeleter {}}- // If we haven't seen any Lucene files, then currentCommitPoint is expected- // to be null, because it means it's a fresh Directory. Therefore it cannot- // be any NFS cache issues - so just ignore.- if (currentCommitPoint == null && seenIndexFiles) {+ if (currentCommitPoint == null) {// We did not in fact see the segments_N file// corresponding to the segmentInfos that was passed// in. Yet, it must exist, because our caller holds@@ -235,15 +235,13 @@ final class IndexFileDeleter {// Finally, give policy a chance to remove things on// startup:- if (seenIndexFiles) {- policy.onInit(commits);- }+ policy.onInit(commits);// Always protect the incoming segmentInfos since// sometime it may not be the most recent commitcheckpoint(segmentInfos, false);- startingCommitDeleted = currentCommitPoint == null ? false : currentCommitPoint.isDeleted();+ startingCommitDeleted = currentCommitPoint.isDeleted();deleteCommits();}diff --git a/lucene/src/java/org/apache/lucene/index/IndexNotFoundException.java b/lucene/src/java/org/apache/lucene/index/IndexNotFoundException.javadeleted file mode 100644index 5e7107448b8..00000000000--- a/lucene/src/java/org/apache/lucene/index/IndexNotFoundException.java+++ /dev/null@@ -1,32 +0,0 @@-package org.apache.lucene.index;--/**- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You under the Apache License, Version 2.0- * (the "License"); you may not use this file except in compliance with- * the License. You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import java.io.FileNotFoundException;--/**- * Signals that no index was found in the Directory. Possibly because the- * directory is empty, however can slso indicate an index corruption.- */-public final class IndexNotFoundException extends FileNotFoundException {-- public IndexNotFoundException(String msg) {- super(msg);- }--}diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.javaindex 3e71f822c03..9a1c78f7885 100644--- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java@@ -1115,16 +1115,25 @@ public class IndexWriter implements Closeable {// against an index that's currently open for// searching. In this case we write the next// segments_N file with no segments:+ boolean doCommit;try {segmentInfos.read(directory, codecs);segmentInfos.clear();+ doCommit = false;} catch (IOException e) {// Likely this means it's a fresh directory+ doCommit = true;}- // Record that we have a change (zero out all- // segments) pending:- changeCount++;+ if (doCommit) {+ // Only commit if there is no segments file in+ // this dir already.+ segmentInfos.commit(directory);+ } else {+ // Record that we have a change (zero out all+ // segments) pending:+ changeCount++;+ }} else {segmentInfos.read(directory, codecs);diff --git a/lucene/src/java/org/apache/lucene/index/SegmentInfos.java b/lucene/src/java/org/apache/lucene/index/SegmentInfos.javaindex 4d53e9869a0..a368cecf2bb 100644--- a/lucene/src/java/org/apache/lucene/index/SegmentInfos.java+++ b/lucene/src/java/org/apache/lucene/index/SegmentInfos.java@@ -649,7 +649,7 @@ public final class SegmentInfos extends Vector<SegmentInfo> {if (gen == -1) {// Neither approach found a generation- throw new IndexNotFoundException("no segments* file found in " + directory + ": files: " + Arrays.toString(files));+ throw new FileNotFoundException("no segments* file found in " + directory + ": files: " + Arrays.toString(files));}}diff --git a/lucene/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java b/lucene/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.javaindex 4f29e74e506..c43f16364d5 100644--- a/lucene/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java+++ b/lucene/src/test/org/apache/lucene/TestSnapshotDeletionPolicy.java@@ -45,8 +45,8 @@ import org.apache.lucene.util._TestUtil;// http://lucenebook.com//-public class TestSnapshotDeletionPolicy extends LuceneTestCase {-+public class TestSnapshotDeletionPolicy extends LuceneTestCase+{public static final String INDEX_PATH = "test.snapshots";public void testSnapshotDeletionPolicy() throws Exception {@@ -119,8 +119,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCase {TEST_VERSION_CURRENT,new StandardAnalyzer(TEST_VERSION_CURRENT)).setIndexDeletionPolicy(dp).setMaxBufferedDocs(2));- writer.commit();-+final Thread t = new Thread() {@Overridepublic void run() {diff --git a/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java b/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.javaindex d58f385d1ff..75ddaa4f103 100644--- a/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java+++ b/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java@@ -558,10 +558,11 @@ public class TestBackwardsCompatibility extends LuceneTestCase {assertTrue("could not locate the 'content' field number in the _2.cfs segment", contentFieldIndex != -1);// Now verify file names:- String[] expected = new String[] {"_0.cfs",+ String[] expected;+ expected = new String[] {"_0.cfs","_0_1.del","_0_1.s" + contentFieldIndex,- "segments_2",+ "segments_3","segments.gen"};String[] actual = dir.listAll();diff --git a/lucene/src/test/org/apache/lucene/index/TestCrash.java b/lucene/src/test/org/apache/lucene/index/TestCrash.javaindex 883d89419ec..3734f69b927 100644--- a/lucene/src/test/org/apache/lucene/index/TestCrash.java+++ b/lucene/src/test/org/apache/lucene/index/TestCrash.java@@ -28,19 +28,16 @@ import org.apache.lucene.document.Field;public class TestCrash extends LuceneTestCase {- private IndexWriter initIndex(boolean initialCommit) throws IOException {- return initIndex(new MockRAMDirectory(), initialCommit);+ private IndexWriter initIndex() throws IOException {+ return initIndex(new MockRAMDirectory());}- private IndexWriter initIndex(MockRAMDirectory dir, boolean initialCommit) throws IOException {+ private IndexWriter initIndex(MockRAMDirectory dir) throws IOException {dir.setLockFactory(NoLockFactory.getNoLockFactory());IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(10));((ConcurrentMergeScheduler) writer.getConfig().getMergeScheduler()).setSuppressExceptions();- if (initialCommit) {- writer.commit();- }-+Document doc = new Document();doc.add(new Field("content", "aaa", Field.Store.YES, Field.Index.ANALYZED));doc.add(new Field("id", "0", Field.Store.YES, Field.Index.ANALYZED));@@ -59,10 +56,7 @@ public class TestCrash extends LuceneTestCase {}public void testCrashWhileIndexing() throws IOException {- // This test relies on being able to open a reader before any commit- // happened, so we must create an initial commit just to allow that, but- // before any documents were added.- IndexWriter writer = initIndex(true);+ IndexWriter writer = initIndex();MockRAMDirectory dir = (MockRAMDirectory) writer.getDirectory();crash(writer);IndexReader reader = IndexReader.open(dir, false);@@ -70,14 +64,11 @@ public class TestCrash extends LuceneTestCase {}public void testWriterAfterCrash() throws IOException {- // This test relies on being able to open a reader before any commit- // happened, so we must create an initial commit just to allow that, but- // before any documents were added.- IndexWriter writer = initIndex(true);+ IndexWriter writer = initIndex();MockRAMDirectory dir = (MockRAMDirectory) writer.getDirectory();dir.setPreventDoubleWrite(false);crash(writer);- writer = initIndex(dir, false);+ writer = initIndex(dir);writer.close();IndexReader reader = IndexReader.open(dir, false);@@ -85,10 +76,10 @@ public class TestCrash extends LuceneTestCase {}public void testCrashAfterReopen() throws IOException {- IndexWriter writer = initIndex(false);+ IndexWriter writer = initIndex();MockRAMDirectory dir = (MockRAMDirectory) writer.getDirectory();writer.close();- writer = initIndex(dir, false);+ writer = initIndex(dir);assertEquals(314, writer.maxDoc());crash(writer);@@ -107,7 +98,7 @@ public class TestCrash extends LuceneTestCase {public void testCrashAfterClose() throws IOException {- IndexWriter writer = initIndex(false);+ IndexWriter writer = initIndex();MockRAMDirectory dir = (MockRAMDirectory) writer.getDirectory();writer.close();@@ -126,7 +117,7 @@ public class TestCrash extends LuceneTestCase {public void testCrashAfterCloseNoWait() throws IOException {- IndexWriter writer = initIndex(false);+ IndexWriter writer = initIndex();MockRAMDirectory dir = (MockRAMDirectory) writer.getDirectory();writer.close(false);@@ -145,7 +136,7 @@ public class TestCrash extends LuceneTestCase {public void testCrashReaderDeletes() throws IOException {- IndexWriter writer = initIndex(false);+ IndexWriter writer = initIndex();MockRAMDirectory dir = (MockRAMDirectory) writer.getDirectory();writer.close(false);@@ -166,7 +157,7 @@ public class TestCrash extends LuceneTestCase {public void testCrashReaderDeletesAfterClose() throws IOException {- IndexWriter writer = initIndex(false);+ IndexWriter writer = initIndex();MockRAMDirectory dir = (MockRAMDirectory) writer.getDirectory();writer.close(false);diff --git a/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java b/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.javaindex b418e59860d..2f43d52fdd3 100644--- a/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java+++ b/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java@@ -305,7 +305,7 @@ public class TestDeletionPolicy extends LuceneTestCase {writer.optimize();writer.close();- assertEquals(1, policy.numOnInit);+ assertEquals(2, policy.numOnInit);// If we are not auto committing then there should// be exactly 2 commits (one per close above):@@ -313,8 +313,8 @@ public class TestDeletionPolicy extends LuceneTestCase {// Test listCommitsCollection<IndexCommit> commits = IndexReader.listCommits(dir);- // 2 from closing writer- assertEquals(2, commits.size());+ // 1 from opening writer + 2 from closing writer+ assertEquals(3, commits.size());// Make sure we can open a reader on each commit:for (final IndexCommit commit : commits) {@@ -374,7 +374,7 @@ public class TestDeletionPolicy extends LuceneTestCase {writer.close();Collection<IndexCommit> commits = IndexReader.listCommits(dir);- assertEquals(5, commits.size());+ assertEquals(6, commits.size());IndexCommit lastCommit = null;for (final IndexCommit commit : commits) {if (lastCommit == null || commit.getGeneration() > lastCommit.getGeneration())@@ -389,7 +389,7 @@ public class TestDeletionPolicy extends LuceneTestCase {writer.optimize();writer.close();- assertEquals(6, IndexReader.listCommits(dir).size());+ assertEquals(7, IndexReader.listCommits(dir).size());// Now open writer on the commit just before optimize:writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))@@ -412,7 +412,7 @@ public class TestDeletionPolicy extends LuceneTestCase {writer.close();// Now 8 because we made another commit- assertEquals(7, IndexReader.listCommits(dir).size());+ assertEquals(8, IndexReader.listCommits(dir).size());r = IndexReader.open(dir, true);// Not optimized because we rolled it back, and now only@@ -491,7 +491,7 @@ public class TestDeletionPolicy extends LuceneTestCase {writer.optimize();writer.close();- assertEquals(1, policy.numOnInit);+ assertEquals(2, policy.numOnInit);// If we are not auto committing then there should// be exactly 2 commits (one per close above):assertEquals(2, policy.numOnCommit);@@ -537,7 +537,7 @@ public class TestDeletionPolicy extends LuceneTestCase {}assertTrue(policy.numDelete > 0);- assertEquals(N, policy.numOnInit);+ assertEquals(N+1, policy.numOnInit);assertEquals(N+1, policy.numOnCommit);// Simplistic check: just verify only the past N segments_N's still@@ -625,8 +625,8 @@ public class TestDeletionPolicy extends LuceneTestCase {// this is a commitwriter.close();- assertEquals(2*(N+1)+1, policy.numOnInit);- assertEquals(2*(N+2), policy.numOnCommit);+ assertEquals(2*(N+2), policy.numOnInit);+ assertEquals(2*(N+2)-1, policy.numOnCommit);IndexSearcher searcher = new IndexSearcher(dir, false);ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;@@ -735,8 +735,8 @@ public class TestDeletionPolicy extends LuceneTestCase {writer.close();}- assertEquals(3*(N+1), policy.numOnInit);- assertEquals(3*(N+1)+1, policy.numOnCommit);+ assertEquals(1+3*(N+1), policy.numOnInit);+ assertEquals(3*(N+1), policy.numOnCommit);IndexSearcher searcher = new IndexSearcher(dir, false);ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java b/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.javaindex f210435de5c..7ead2dd998e 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java@@ -138,11 +138,11 @@ public class TestIndexFileDeleter extends LuceneTestCase {copyFile(dir, "_0.cfs", "deletable");// Create some old segments file:- copyFile(dir, "segments_2", "segments");- copyFile(dir, "segments_2", "segments_1");+ copyFile(dir, "segments_3", "segments");+ copyFile(dir, "segments_3", "segments_2");// Create a bogus cfs file shadowing a non-cfs segment:- copyFile(dir, "_1.cfs", "_2.cfs");+ copyFile(dir, "_2.cfs", "_3.cfs");String[] filesPre = dir.listAll();diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexReader.java b/lucene/src/test/org/apache/lucene/index/TestIndexReader.javaindex 30d8cd201e9..a2a55d11f2c 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexReader.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexReader.java@@ -466,17 +466,18 @@ public class TestIndexReader extends LuceneTestCasepublic void testLockObtainFailed() throws IOException {Directory dir = new RAMDirectory();+ IndexWriter writer = null;+ IndexReader reader = null;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)));- writer.commit();+ writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));for (int i = 0; i < 11; i++) {addDoc(writer, searchTerm.text());}// Create reader:- IndexReader reader = IndexReader.open(dir, false);+ reader = IndexReader.open(dir, false);// Try to make changestry {@@ -1748,7 +1749,6 @@ public class TestIndexReader extends LuceneTestCaseDirectory dir = new MockRAMDirectory();IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));- writer.commit();Document doc = new Document();writer.addDocument(doc);IndexReader r = IndexReader.open(dir, true);diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java b/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.javaindex e99cc6639a6..f7a8855c1f4 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java@@ -174,7 +174,6 @@ public class TestIndexReaderReopen extends LuceneTestCase {IndexWriter iwriter = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new KeywordAnalyzer()).setOpenMode(OpenMode.CREATE).setMergeScheduler(new SerialMergeScheduler()));- iwriter.commit();IndexReader reader = IndexReader.open(dir, false);try {int M = 3;diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriter.javaindex 66af7aebc33..443b90bdb9a 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java@@ -778,7 +778,7 @@ public class TestIndexWriter extends LuceneTestCase {writer.close();long gen = SegmentInfos.getCurrentSegmentGeneration(dir);- assertTrue("segment generation should be > 0 but got " + gen, gen > 0);+ assertTrue("segment generation should be > 1 but got " + gen, gen > 1);// Make the next segments file, with last byte// missing, to simulate a writer that crashed while@@ -838,7 +838,7 @@ public class TestIndexWriter extends LuceneTestCase {writer.close();long gen = SegmentInfos.getCurrentSegmentGeneration(dir);- assertTrue("segment generation should be > 0 but got " + gen, gen > 0);+ assertTrue("segment generation should be > 1 but got " + gen, gen > 1);String fileNameIn = SegmentInfos.getCurrentSegmentFileName(dir);String fileNameOut = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,@@ -903,7 +903,7 @@ public class TestIndexWriter extends LuceneTestCase {writer.close();long gen = SegmentInfos.getCurrentSegmentGeneration(dir);- assertTrue("segment generation should be > 0 but got " + gen, gen > 0);+ assertTrue("segment generation should be > 1 but got " + gen, gen > 1);String[] files = dir.listAll();for(int i=0;i<files.length;i++) {@@ -2326,7 +2326,7 @@ public class TestIndexWriter extends LuceneTestCase {public void testImmediateDiskFull() throws IOException {MockRAMDirectory dir = new MockRAMDirectory();IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(2));- dir.setMaxSizeInBytes(Math.max(1, dir.getRecomputedActualSizeInBytes()));+ dir.setMaxSizeInBytes(dir.getRecomputedActualSizeInBytes());final Document doc = new Document();doc.add(new Field("field", "aaa bbb ccc ddd eee fff ggg hhh iii jjj", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));try {@@ -2644,7 +2644,7 @@ public class TestIndexWriter extends LuceneTestCase {writer.close();long gen = SegmentInfos.getCurrentSegmentGeneration(dir);- assertTrue("segment generation should be > 0 but got " + gen, gen > 0);+ assertTrue("segment generation should be > 1 but got " + gen, gen > 1);final String segmentsFileName = SegmentInfos.getCurrentSegmentFileName(dir);IndexInput in = dir.openInput(segmentsFileName);@@ -2673,8 +2673,7 @@ public class TestIndexWriter extends LuceneTestCase {TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(2));((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(5);- writer.commit();-+for (int i = 0; i < 23; i++)addDoc(writer);@@ -3535,8 +3534,7 @@ public class TestIndexWriter extends LuceneTestCase {IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(2));((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(5);- writer.commit();-+for (int i = 0; i < 23; i++)addDoc(writer);@@ -3587,8 +3585,7 @@ public class TestIndexWriter extends LuceneTestCase {IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setMaxBufferedDocs(2));((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(5);- writer.commit();-+for (int i = 0; i < 23; i++)addDoc(writer);@@ -3673,7 +3670,6 @@ public class TestIndexWriter extends LuceneTestCase {dir2 = new MockRAMDirectory();writer2 = new IndexWriter(dir2, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));- writer2.commit();cms = (ConcurrentMergeScheduler) writer2.getConfig().getMergeScheduler();readers = new IndexReader[NUM_COPY];@@ -4956,17 +4952,4 @@ public class TestIndexWriter extends LuceneTestCase {w.close();dir.close();}-- public void testNoCommits() throws Exception {- // Tests that if we don't call commit(), the directory has 0 commits. This has- // changed since LUCENE-2386, where before IW would always commit on a fresh- // new index.- Directory dir = new RAMDirectory();- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));- assertEquals("expected 0 commits!", 0, IndexReader.listCommits(dir).size());- // No changes still should generate a commit, because it's a new index.- writer.close();- assertEquals("expected 1 commits!", 1, IndexReader.listCommits(dir).size());- }-}diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.javaindex 7bb4416b754..c5e3383f76d 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java@@ -749,7 +749,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {MockRAMDirectory dir = new MockRAMDirectory();IndexWriter modifier = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));- modifier.commit();+dir.failOn(failure.reset());for (int i = 0; i < keywords.length; i++) {diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.javaindex 855b7b8b2b6..b6afdf85359 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java@@ -134,7 +134,6 @@ public class TestIndexWriterExceptions extends LuceneTestCase {MockIndexWriter writer = new MockIndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setRAMBufferSizeMB(0.1));((ConcurrentMergeScheduler) writer.getConfig().getMergeScheduler()).setSuppressExceptions();//writer.setMaxBufferedDocs(10);- writer.commit();if (VERBOSE)writer.setInfoStream(System.out);@@ -172,7 +171,6 @@ public class TestIndexWriterExceptions extends LuceneTestCase {MockIndexWriter writer = new MockIndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setRAMBufferSizeMB(0.2));((ConcurrentMergeScheduler) writer.getConfig().getMergeScheduler()).setSuppressExceptions();//writer.setMaxBufferedDocs(10);- writer.commit();if (VERBOSE)writer.setInfoStream(System.out);diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.javaindex 02ea51079da..511fdbe57c6 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java@@ -561,7 +561,6 @@ public class TestIndexWriterReader extends LuceneTestCase {public void testAfterCommit() throws Exception {Directory dir1 = new MockRAMDirectory();IndexWriter writer = new IndexWriter(dir1, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));- writer.commit();writer.setInfoStream(infoStream);// create the indexdiff --git a/lucene/src/test/org/apache/lucene/index/TestNoDeletionPolicy.java b/lucene/src/test/org/apache/lucene/index/TestNoDeletionPolicy.javaindex 3d18e96ce1c..f780a06795a 100644--- a/lucene/src/test/org/apache/lucene/index/TestNoDeletionPolicy.java+++ b/lucene/src/test/org/apache/lucene/index/TestNoDeletionPolicy.java@@ -82,7 +82,10 @@ public class TestNoDeletionPolicy extends LuceneTestCaseJ4 {doc.add(new Field("c", "a" + i, Store.YES, Index.ANALYZED));writer.addDocument(doc);writer.commit();- assertEquals("wrong number of commits !", i + 1, IndexReader.listCommits(dir).size());+ // the reason to expect i + 2 commits is because when IndexWriter is+ // created it creates a first commit. If this ever changes, then the+ // expected should be i + 1 (and this comment removed).+ assertEquals("wrong number of commits !", i + 2, IndexReader.listCommits(dir).size());}writer.close();}diff --git a/lucene/src/test/org/apache/lucene/index/TestStressIndexing.java b/lucene/src/test/org/apache/lucene/index/TestStressIndexing.javaindex 0b445839545..1bc66a190ee 100644--- a/lucene/src/test/org/apache/lucene/index/TestStressIndexing.java+++ b/lucene/src/test/org/apache/lucene/index/TestStressIndexing.java@@ -122,8 +122,7 @@ public class TestStressIndexing extends MultiCodecTestCase {TEST_VERSION_CURRENT, new SimpleAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(10).setMergeScheduler(mergeScheduler));- modifier.commit();-+TimedThread[] threads = new TimedThread[4];int numThread = 0;diff --git a/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java b/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.javaindex 78600499d61..d38ba1fe55f 100644--- a/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java+++ b/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java@@ -150,7 +150,6 @@ public class TestStressIndexing2 extends MultiCodecTestCase {IndexWriter w = new MockIndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE).setRAMBufferSizeMB(0.1).setMaxBufferedDocs(maxBufferedDocs));- w.commit();LogMergePolicy lmp = (LogMergePolicy) w.getConfig().getMergePolicy();lmp.setUseCompoundFile(false);lmp.setUseCompoundDocStore(false);diff --git a/lucene/src/test/org/apache/lucene/store/TestBufferedIndexInput.java b/lucene/src/test/org/apache/lucene/store/TestBufferedIndexInput.javaindex 361255b2de5..8156f043d23 100755--- a/lucene/src/test/org/apache/lucene/store/TestBufferedIndexInput.java+++ b/lucene/src/test/org/apache/lucene/store/TestBufferedIndexInput.java@@ -243,7 +243,6 @@ public class TestBufferedIndexInput extends LuceneTestCase {public void testSetBufferSize() throws IOException {File indexDir = new File(TEMP_DIR, "testSetBufferSize");- indexDir.mkdirs(); // required for this MockFSDir since we don't commit on IW creation anymore.MockFSDirectory dir = new MockFSDirectory(indexDir, newRandom());try {IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(diff --git a/lucene/src/test/org/apache/lucene/store/TestLockFactory.java b/lucene/src/test/org/apache/lucene/store/TestLockFactory.javaindex 6db3e64be7e..c07ece490b0 100755--- a/lucene/src/test/org/apache/lucene/store/TestLockFactory.java+++ b/lucene/src/test/org/apache/lucene/store/TestLockFactory.java@@ -82,7 +82,7 @@ public class TestLockFactory extends LuceneTestCase {NoLockFactory.class.isInstance(dir.getLockFactory()));IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));- writer.commit(); // required so the second open succeed+// Create a 2nd IndexWriter. This is normally not allowed but it should run through since we're not// using any locks:IndexWriter writer2 = null;diff --git a/lucene/src/test/org/apache/lucene/store/TestWindowsMMap.java b/lucene/src/test/org/apache/lucene/store/TestWindowsMMap.javaindex 8a9bd1559c0..8ccc79aa47c 100644--- a/lucene/src/test/org/apache/lucene/store/TestWindowsMMap.java+++ b/lucene/src/test/org/apache/lucene/store/TestWindowsMMap.java@@ -66,22 +66,17 @@ public class TestWindowsMMap extends LuceneTestCase {new File(TEMP_DIR,"testLuceneMmap").getAbsolutePath();public void testMmapIndex() throws Exception {- // sometimes the directory is not cleaned by rmDir, because on Windows it- // may take some time until the files are finally dereferenced. So clean the- // directory up front, or otherwise new IndexWriter will fail.- File dirPath = new File(storePathname);- rmDir(dirPath);- MMapDirectory dir = new MMapDirectory(dirPath, null);-+ FSDirectory storeDirectory;+ storeDirectory = new MMapDirectory(new File(storePathname), null);+// plan to add a set of useful stopwords, consider changing some of the// interior filters.StandardAnalyzer analyzer = new StandardAnalyzer(TEST_VERSION_CURRENT, Collections.emptySet());// TODO: something about lock timeouts and leftover locks.- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(+ IndexWriter writer = new IndexWriter(storeDirectory, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer).setOpenMode(OpenMode.CREATE));- writer.commit();- IndexSearcher searcher = new IndexSearcher(dir, true);+ IndexSearcher searcher = new IndexSearcher(storeDirectory, true);for(int dx = 0; dx < 1000; dx ++) {String f = randomField();@@ -92,16 +87,14 @@ public class TestWindowsMMap extends LuceneTestCase {searcher.close();writer.close();- rmDir(dirPath);+ rmDir(new File(storePathname));}- private void rmDir(File dir) {- if (!dir.exists()) {- return;- }- for (File file : dir.listFiles()) {- file.delete();- }- dir.delete();- }+ private void rmDir(File dir) {+ File[] files = dir.listFiles();+ for (int i = 0; i < files.length; i++) {+ files[i].delete();+ }+ dir.delete();+ }}