You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2010/11/08 14:56:19 UTC

svn commit: r1032570 - /lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/RandomIndexWriter.java

Author: rmuir
Date: Mon Nov  8 13:56:18 2010
New Revision: 1032570

URL: http://svn.apache.org/viewvc?rev=1032570&view=rev
Log:
improve test coverage for the single segment case

Modified:
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/RandomIndexWriter.java

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/RandomIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/RandomIndexWriter.java?rev=1032570&r1=1032569&r2=1032570&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/RandomIndexWriter.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/RandomIndexWriter.java Mon Nov  8 13:56:18 2010
@@ -42,6 +42,7 @@ public class RandomIndexWriter implement
   private final Random r;
   int docCount;
   int flushAt;
+  private boolean getReaderCalled;
 
   // Randomly calls Thread.yield so we mixup thread scheduling
   private static final class MockIndexWriter extends IndexWriter {
@@ -123,6 +124,9 @@ public class RandomIndexWriter implement
   }
 
   public IndexReader getReader() throws IOException {
+    getReaderCalled = true;
+    if (r.nextInt(4) == 2)
+      w.optimize();
     // If we are writing with PreFlexRW, force a full
     // IndexReader.open so terms are sorted in codepoint
     // order during searching:
@@ -141,7 +145,9 @@ public class RandomIndexWriter implement
   }
 
   public void close() throws IOException {
-    if (r.nextInt(4) == 2) {
+    // if someone isn't using getReader() API, we want to be sure to
+    // maybeOptimize since presumably they might open a reader on the dir.
+    if (getReaderCalled == false && r.nextInt(4) == 2) {
       w.optimize();
     }
     w.close();