lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dna...@apache.org
Subject svn commit: r499152 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/index/MultiReader.java src/test/org/apache/lucene/index/TestMultiReader.java
Date Tue, 23 Jan 2007 22:01:06 GMT
Author: dnaber
Date: Tue Jan 23 14:01:05 2007
New Revision: 499152

URL: http://svn.apache.org/viewvc?view=rev&rev=499152
Log:
LUCENE-781: fixed NPE in MultiReader.isCurrent() and getVersion()

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestMultiReader.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?view=diff&rev=499152&r1=499151&r2=499152
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Jan 23 14:01:05 2007
@@ -332,6 +332,11 @@
     life" due to this, just a possible future problem).  (Chuck
     Williams via Mike McCandless)
 
+33. LUCENE-781: Fixed the NullPointerException in MultiReader.isCurrent()
+    and MultiReader.getVersion(). isCurrent() now returns true only if
+    all its readers are current. getVersion() now throws an
+    UnsupportedOperationException.  (Daniel Naber)
+
 Optimizations
 
   1. LUCENE-586: TermDocs.skipTo() is now more efficient for

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java?view=diff&rev=499152&r1=499151&r2=499152
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java Tue Jan 23 14:01:05
2007
@@ -262,6 +262,30 @@
     }
     return fieldSet;
   }
+  
+  /**
+   * Returns <code>true</code> if all readers are still up-to-date.
+   * 
+   * @throws IOException
+   */
+  public boolean isCurrent() throws IOException {
+    for (int i = 0; i < subReaders.length; i++) {
+      IndexReader reader = subReaders[i];
+      if (!reader.isCurrent())
+        return false;
+    }
+    return true;
+  }
+
+  /**
+   * Not implemented.
+   * @throws UnsupportedOperationException
+   */
+  public long getVersion() {
+    throw new UnsupportedOperationException("This method is only implemented in " +
+        "IndexReader, not in MultiReader");
+  }
+
 }
 
 class MultiTermEnum extends TermEnum {

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestMultiReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestMultiReader.java?view=diff&rev=499152&r1=499151&r2=499152
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestMultiReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestMultiReader.java Tue Jan 23 14:01:05
2007
@@ -18,7 +18,10 @@
  */
 
 import junit.framework.TestCase;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.RAMDirectory;
 
@@ -101,5 +104,35 @@
   public void testTermVectors() {
     MultiReader reader = new MultiReader(dir, sis, false, readers);
     assertTrue(reader != null);
-  }    
+  }
+  
+  public void testIsCurrent() throws IOException {
+    RAMDirectory ramDir1=new RAMDirectory();
+    addDoc(ramDir1, "test foo", true);
+    RAMDirectory ramDir2=new RAMDirectory();
+    addDoc(ramDir2, "test blah", true);
+    IndexReader[] readers = new IndexReader[]{IndexReader.open(ramDir1), IndexReader.open(ramDir2)};
+    MultiReader mr = new MultiReader(readers);
+    assertTrue(mr.isCurrent());   // just opened, must be current
+    addDoc(ramDir1, "more text", false);
+    assertFalse(mr.isCurrent());   // has been modified, not current anymore
+    addDoc(ramDir2, "even more text", false);
+    assertFalse(mr.isCurrent());   // has been modified even more, not current anymore
+    try {
+      mr.getVersion();
+      fail();
+    } catch (UnsupportedOperationException e) {
+      // expected exception
+    }
+    mr.close();
+  }
+
+  private void addDoc(RAMDirectory ramDir1, String s, boolean create) throws IOException
{
+    IndexWriter iw = new IndexWriter(ramDir1, new StandardAnalyzer(), create);
+    Document doc = new Document();
+    doc.add(new Field("body", s, Field.Store.YES, Field.Index.TOKENIZED));
+    iw.addDocument(doc);
+    iw.close();
+  }
+
 }



Mime
View raw message