mirror of https://github.com/apache/lucene.git
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:
parent
29560fcf50
commit
9dc489edb1
|
@ -3231,11 +3231,11 @@ public class IndexWriter {
|
||||||
applyDeletes();
|
applyDeletes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doAfterFlush();
|
||||||
|
|
||||||
if (flushDocs)
|
if (flushDocs)
|
||||||
checkpoint();
|
checkpoint();
|
||||||
|
|
||||||
doAfterFlush();
|
|
||||||
|
|
||||||
if (flushDocs && mergePolicy.useCompoundFile(segmentInfos, newSegment)) {
|
if (flushDocs && mergePolicy.useCompoundFile(segmentInfos, newSegment)) {
|
||||||
// Now build compound file
|
// Now build compound file
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
|
|
@ -3231,4 +3231,41 @@ public class TestIndexWriter extends LuceneTestCase
|
||||||
w.close();
|
w.close();
|
||||||
dir.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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue