lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r636045 - in /lucene/java/trunk/src: java/org/apache/lucene/index/IndexWriter.java test/org/apache/lucene/index/TestIndexWriter.java
Date Tue, 11 Mar 2008 18:16:33 GMT
Author: mikemccand
Date: Tue Mar 11 11:16:31 2008
New Revision: 636045

URL: http://svn.apache.org/viewvc?rev=636045&view=rev
Log:
LUCENE-1222: make sure IW.doAfterFlush is called regardless of whether adds or deletes are
flushed

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java?rev=636045&r1=636044&r2=636045&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java Tue Mar 11 11:16:31
2008
@@ -3231,10 +3231,10 @@
         applyDeletes();
       }
       
+      doAfterFlush();
+
       if (flushDocs)
         checkpoint();
-
-      doAfterFlush();
 
       if (flushDocs && mergePolicy.useCompoundFile(segmentInfos, newSegment)) {
         // Now build compound file

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=636045&r1=636044&r2=636045&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java Tue Mar 11 11:16:31
2008
@@ -3231,4 +3231,41 @@
     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();
+  }
 }



Mime
View raw message