lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpou...@apache.org
Subject svn commit: r1584844 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/core/ lucene/core/src/test/org/apache/lucene/search/ lucene/test-framework/ lucene/test-framework/src/java/org/apache/lucene/search/ lucene/test-framework/src/java/org/apache/l...
Date Fri, 04 Apr 2014 18:12:29 GMT
Author: jpountz
Date: Fri Apr  4 18:12:28 2014
New Revision: 1584844

URL: http://svn.apache.org/r1584844
Log:
LUCENE-5501: Improved out-of-order collection testing.

Added:
    lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/search/RandomOrderCollector.java
      - copied, changed from r1584829, lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/search/RandomOrderCollector.java
Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
    lucene/dev/branches/branch_4x/lucene/test-framework/   (props changed)
    lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingBulkOutOfOrderScorer.java
    lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java
    lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java?rev=1584844&r1=1584843&r2=1584844&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java
Fri Apr  4 18:12:28 2014
@@ -138,7 +138,8 @@ public class TestBooleanScorer extends L
     w.addDocument(doc);
     final IndexReader r = w.getReader();
     w.close();
-    final IndexSearcher s = newSearcher(r);
+    // we don't wrap with AssertingIndexSearcher in order to have the original scorer in
setScorer.
+    final IndexSearcher s = newSearcher(r, true, false);
 
     final BooleanQuery q = new BooleanQuery();
     for(int term=0;term<33;term++) {
@@ -154,7 +155,7 @@ public class TestBooleanScorer extends L
       @Override
       public void setScorer(Scorer scorer) {
         // Make sure we got BooleanScorer:
-        final Class<?> clazz = scorer instanceof AssertingScorer ? ((AssertingScorer)
scorer).getIn().getClass() : scorer.getClass();
+        final Class<?> clazz = scorer.getClass();
         assertEquals("Scorer is implemented by wrong class", FakeScorer.class.getName(),
clazz.getName());
       }
       

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java?rev=1584844&r1=1584843&r2=1584844&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
Fri Apr  4 18:12:28 2014
@@ -95,7 +95,8 @@ public class TestConstantScoreQuery exte
 
       reader = writer.getReader();
       writer.close();
-      searcher = newSearcher(reader);
+      // we don't wrap with AssertingIndexSearcher in order to have the original scorer in
setScorer.
+      searcher = newSearcher(reader, true, false);
       
       // set a similarity that does not normalize our boost away
       searcher.setSimilarity(new DefaultSimilarity() {

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingBulkOutOfOrderScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingBulkOutOfOrderScorer.java?rev=1584844&r1=1584843&r2=1584844&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingBulkOutOfOrderScorer.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingBulkOutOfOrderScorer.java
Fri Apr  4 18:12:28 2014
@@ -18,93 +18,37 @@ package org.apache.lucene.search;
  */
 
 import java.io.IOException;
-import java.lang.ref.WeakReference;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
 import java.util.Random;
-import java.util.WeakHashMap;
 
-import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.util.VirtualMethod;
-
-/** A crazy {@link BulkScorer} that wraps a {@link Scorer}
+/** A crazy {@link BulkScorer} that wraps another {@link BulkScorer}
  *  but shuffles the order of the collected documents. */
 public class AssertingBulkOutOfOrderScorer extends BulkScorer {
 
+  final BulkScorer in;
   final Random random;
-  final Scorer scorer;
 
-  public AssertingBulkOutOfOrderScorer(Random random, Scorer scorer) {
+  public AssertingBulkOutOfOrderScorer(Random random, BulkScorer in) {
+    this.in = in;
     this.random = random;
-    this.scorer = scorer;
-  }
-
-  private void shuffle(int[] docIDs, float[] scores, int[] freqs, int size) {
-    for (int i = size - 1; i > 0; --i) {
-      final int other = random.nextInt(i + 1);
-
-      final int tmpDoc = docIDs[i];
-      docIDs[i] = docIDs[other];
-      docIDs[other] = tmpDoc;
-
-      final float tmpScore = scores[i];
-      scores[i] = scores[other];
-      scores[other] = tmpScore;
-      
-      final int tmpFreq = freqs[i];
-      freqs[i] = freqs[other];
-      freqs[other] = tmpFreq;
-    }
-  }
-
-  private static void flush(int[] docIDs, float[] scores, int[] freqs, int size,
-      FakeScorer scorer, Collector collector) throws IOException {
-    for (int i = 0; i < size; ++i) {
-      scorer.doc = docIDs[i];
-      scorer.freq = freqs[i];
-      scorer.score = scores[i];
-      collector.collect(scorer.doc);
-    }
   }
 
   @Override
   public boolean score(Collector collector, int max) throws IOException {
-    if (scorer.docID() == -1) {
-      scorer.nextDoc();
-    }
-
-    FakeScorer fake = new FakeScorer();
-    collector.setScorer(fake);
-
-    final int bufferSize = 1 + random.nextInt(100);
-    final int[] docIDs = new int[bufferSize];
-    final float[] scores = new float[bufferSize];
-    final int[] freqs = new int[bufferSize];
-
-    int buffered = 0;
-    int doc = scorer.docID();
-    while (doc < max) {
-      docIDs[buffered] = doc;
-      scores[buffered] = scorer.score();
-      freqs[buffered] = scorer.freq();
-
-      if (++buffered == bufferSize) {
-        shuffle(docIDs, scores, freqs, buffered);
-        flush(docIDs, scores, freqs, buffered, fake, collector);
-        buffered = 0;
-      }
-      doc = scorer.nextDoc();
-    }
-
-    shuffle(docIDs, scores, freqs, buffered);
-    flush(docIDs, scores, freqs, buffered, fake, collector);
+    final RandomOrderCollector randomCollector = new RandomOrderCollector(random, collector);
+    final boolean remaining = in.score(randomCollector, max);
+    randomCollector.flush();
+    return remaining;
+  }
 
-    return doc != Scorer.NO_MORE_DOCS;
+  @Override
+  public void score(Collector collector) throws IOException {
+    final RandomOrderCollector randomCollector = new RandomOrderCollector(random, collector);
+    in.score(randomCollector);
+    randomCollector.flush();
   }
 
   @Override
   public String toString() {
-    return "AssertingBulkOutOfOrderScorer(" + scorer + ")";
+    return "AssertingBulkOutOfOrderScorer(" + in + ")";
   }
 }

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java?rev=1584844&r1=1584843&r2=1584844&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java
Fri Apr  4 18:12:28 2014
@@ -79,22 +79,20 @@ class AssertingWeight extends Weight {
     if (AssertingBulkScorer.shouldWrap(inScorer)) {
       // The incoming scorer already has a specialized
       // implementation for BulkScorer, so we should use it:
-      return AssertingBulkScorer.wrap(new Random(random.nextLong()), inScorer);
-    } else if (scoreDocsInOrder == false && random.nextBoolean()) {
+      inScorer = AssertingBulkScorer.wrap(new Random(random.nextLong()), inScorer);
+    } else if (random.nextBoolean()) {
+      // Let super wrap this.scorer instead, so we use
+      // AssertingScorer:
+      inScorer = super.bulkScorer(context, scoreDocsInOrder, acceptDocs);
+    }
+
+    if (scoreDocsInOrder == false && random.nextBoolean()) {
       // The caller claims it can handle out-of-order
       // docs; let's confirm that by pulling docs and
       // randomly shuffling them before collection:
-      //Scorer scorer = in.scorer(context, acceptDocs);
-      Scorer scorer = scorer(context, acceptDocs);
-
-      // Scorer should not be null if bulkScorer wasn't:
-      assert scorer != null;
-      return new AssertingBulkOutOfOrderScorer(new Random(random.nextLong()), scorer);
-    } else {
-      // Let super wrap this.scorer instead, so we use
-      // AssertingScorer:
-      return super.bulkScorer(context, scoreDocsInOrder, acceptDocs);
+      inScorer = new AssertingBulkOutOfOrderScorer(new Random(random.nextLong()), inScorer);
     }
+    return inScorer;
   }
 
   @Override

Copied: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/search/RandomOrderCollector.java
(from r1584829, lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/search/RandomOrderCollector.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/search/RandomOrderCollector.java?p2=lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/search/RandomOrderCollector.java&p1=lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/search/RandomOrderCollector.java&r1=1584829&r2=1584844&rev=1584844&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/search/RandomOrderCollector.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/search/RandomOrderCollector.java
Fri Apr  4 18:12:28 2014
@@ -20,11 +20,14 @@ package org.apache.lucene.search;
 import java.io.IOException;
 import java.util.Random;
 
+import org.apache.lucene.index.AtomicReaderContext;
+
 /** Randomize collection order. Don't forget to call {@link #flush()} when
  *  collection is finished to collect buffered documents. */
-final class RandomOrderCollector extends FilterLeafCollector {
+final class RandomOrderCollector extends Collector {
 
   final Random random;
+  final Collector in;
   Scorer scorer;
   FakeScorer fakeScorer;
 
@@ -34,11 +37,11 @@ final class RandomOrderCollector extends
   final float[] scores;
   final int[] freqs;
 
-  RandomOrderCollector(Random random, LeafCollector in) {
-    super(in);
+  RandomOrderCollector(Random random, Collector in) {
     if (!in.acceptsDocsOutOfOrder()) {
       throw new IllegalArgumentException();
     }
+    this.in = in;
     this.random = random;
     bufferSize = 1 + random.nextInt(100);
     docIDs = new int[bufferSize];
@@ -102,5 +105,9 @@ final class RandomOrderCollector extends
     return in.acceptsDocsOutOfOrder();
   }
 
-}
+  @Override
+  public void setNextReader(AtomicReaderContext context) throws IOException {
+    throw new UnsupportedOperationException();
+  }
 
+}
\ No newline at end of file

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java?rev=1584844&r1=1584843&r2=1584844&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
Fri Apr  4 18:12:28 2014
@@ -1310,13 +1310,23 @@ public abstract class LuceneTestCase ext
   public static IndexSearcher newSearcher(IndexReader r) {
     return newSearcher(r, true);
   }
-  
+
   /**
    * Create a new searcher over the reader. This searcher might randomly use
-   * threads. if <code>maybeWrap</code> is true, this searcher might wrap the
-   * reader with one that returns null for getSequentialSubReaders.
+   * threads.
    */
   public static IndexSearcher newSearcher(IndexReader r, boolean maybeWrap) {
+    return newSearcher(r, maybeWrap, true);
+  }
+
+  /**
+   * Create a new searcher over the reader. This searcher might randomly use
+   * threads. if <code>maybeWrap</code> is true, this searcher might wrap the
+   * reader with one that returns null for getSequentialSubReaders. If
+   * <code>wrapWithAssertions</code> is true, this searcher might be an
+   * {@link AssertingIndexSearcher} instance.
+   */
+  public static IndexSearcher newSearcher(IndexReader r, boolean maybeWrap, boolean wrapWithAssertions)
{
     Random random = random();
     if (usually()) {
       if (maybeWrap) {
@@ -1337,7 +1347,12 @@ public abstract class LuceneTestCase ext
           throw new AssertionError(e);
         }
       }
-      IndexSearcher ret = random.nextBoolean() ? new AssertingIndexSearcher(random, r) :
new AssertingIndexSearcher(random, r.getContext());
+      final IndexSearcher ret;
+      if (wrapWithAssertions) {
+        ret = random.nextBoolean() ? new AssertingIndexSearcher(random, r) : new AssertingIndexSearcher(random,
r.getContext());
+      } else {
+        ret = random.nextBoolean() ? new IndexSearcher(r) : new IndexSearcher(r.getContext());
+      }
       ret.setSimilarity(classEnvRule.similarity);
       return ret;
     } else {
@@ -1364,9 +1379,16 @@ public abstract class LuceneTestCase ext
          }
        });
       }
-      IndexSearcher ret = random.nextBoolean() 
-          ? new AssertingIndexSearcher(random, r, ex)
-          : new AssertingIndexSearcher(random, r.getContext(), ex);
+      IndexSearcher ret;
+      if (wrapWithAssertions) {
+        ret = random.nextBoolean()
+            ? new AssertingIndexSearcher(random, r, ex)
+            : new AssertingIndexSearcher(random, r.getContext(), ex);
+      } else {
+        ret = random.nextBoolean()
+            ? new IndexSearcher(r, ex)
+            : new IndexSearcher(r.getContext(), ex);
+      }
       ret.setSimilarity(classEnvRule.similarity);
       return ret;
     }



Mime
View raw message