LUCENE-1222: make sure IW.doAfterFlush is called regardless of whether adds or deletes are flushed

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@636045 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2008-03-11 18:16:31 +00:00
parent 29560fcf50
commit 9dc489edb1
2 changed files with 39 additions and 2 deletions

View File

@ -3231,11 +3231,11 @@ public class IndexWriter {
applyDeletes();
}
doAfterFlush();
if (flushDocs)
checkpoint();
doAfterFlush();
if (flushDocs && mergePolicy.useCompoundFile(segmentInfos, newSegment)) {
// Now build compound file
boolean success = false;

View File

@ -3231,4 +3231,41 @@ public class TestIndexWriter extends LuceneTestCase
w.close();
dir.close();
}
public class MockIndexWriter3 extends IndexWriter {
public MockIndexWriter3(Directory dir, boolean autoCommit, Analyzer a, boolean create, IndexWriter.MaxFieldLength mfl) throws IOException {
super(dir, autoCommit, a, create, mfl);
}
boolean wasCalled;
public void doAfterFlush() {
wasCalled = true;
}
}
// LUCENE-1222
public void testDoAfterFlush() throws IOException {
MockRAMDirectory dir = new MockRAMDirectory();
MockIndexWriter3 w = new MockIndexWriter3(dir, false, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
Document doc = new Document();
doc.add(new Field("field", "a field", Field.Store.YES,
Field.Index.TOKENIZED));
w.addDocument(doc);
w.commit();
assertTrue(w.wasCalled);
w.wasCalled = true;
w.deleteDocuments(new Term("field", "field"));
w.commit();
assertTrue(w.wasCalled);
w.close();
IndexReader ir = IndexReader.open(dir);
assertEquals(1, ir.maxDoc());
assertEquals(0, ir.numDocs());
ir.close();
dir.close();
}
}