lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r1291772 - /lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
Date Tue, 21 Feb 2012 13:29:23 GMT
Author: uschindler
Date: Tue Feb 21 13:29:23 2012
New Revision: 1291772

URL: http://svn.apache.org/viewvc?rev=1291772&view=rev
Log:
Improve test coverage on IndexReaders by more fancy wrapping (completely random)

Modified:
    lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java

Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java?rev=1291772&r1=1291771&r2=1291772&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
(original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
Tue Feb 21 13:29:23 2012
@@ -55,6 +55,8 @@ import org.apache.lucene.document.Field;
 import org.apache.lucene.document.FieldType;
 import org.apache.lucene.index.AtomicReader;
 import org.apache.lucene.index.CompositeReader;
+import org.apache.lucene.index.FilterAtomicReader;
+import org.apache.lucene.index.Fields;
 import org.apache.lucene.index.MultiReader;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexReader;
@@ -1344,6 +1346,41 @@ public abstract class LuceneTestCase ext
       throw new RuntimeException(e);
     }
   }
+  
+  /** Sometimes wrap the IndexReader as slow, parallel or filter reader (or combinations
of that) */
+  public static IndexReader maybeWrapReader(IndexReader r) throws IOException {
+    if (rarely()) {
+      for (int i = 0, c = random.nextInt(6)+1; i < c; i++) {
+        switch(random.nextInt(4)) {
+          case 0:
+            r = SlowCompositeReaderWrapper.wrap(r);
+            break;
+          case 1:
+            r = (r instanceof AtomicReader) ?
+              new ParallelAtomicReader((AtomicReader) r) :
+              new ParallelCompositeReader((CompositeReader) r);
+            break;
+          case 2:
+            r = new MultiReader(r);
+            break;
+          case 3:
+            if (r instanceof AtomicReader) {
+              r = new FilterAtomicReader((AtomicReader) r) {
+                @Override
+                public Fields fields() throws IOException {
+                  return new FilterFields(super.fields());
+                }
+              };
+            }
+            break;
+          default:
+            fail("should not get here");
+        }
+      }
+    }
+    //System.out.println(r);
+    return r;
+  }
 
   /** create a new searcher over the reader.
    * This searcher might randomly use threads. */
@@ -1358,18 +1395,8 @@ public abstract class LuceneTestCase ext
    */
   public static IndexSearcher newSearcher(IndexReader r, boolean maybeWrap) throws IOException
{
     if (usually()) {
-      if (maybeWrap && rarely()) {
-        r = SlowCompositeReaderWrapper.wrap(r);
-      }
-      if (maybeWrap && rarely()) {
-        // just wrap as MultiReader/ParallelXReader with one subreader
-        if (random.nextBoolean()) {
-          r = (r instanceof AtomicReader) ?
-            new ParallelAtomicReader((AtomicReader) r) :
-            new ParallelCompositeReader((CompositeReader) r);
-        } else if (r instanceof CompositeReader) { // only wrap if not already atomic (some
tests may fail)
-          r = new MultiReader(r);
-        }
+      if (maybeWrap) {
+        r = maybeWrapReader(r);
       }
       IndexSearcher ret = random.nextBoolean() ? new AssertingIndexSearcher(random, r) :
new AssertingIndexSearcher(random, r.getTopReaderContext());
       ret.setSimilarity(similarity);



Mime
View raw message