lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1626830 - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/core/ lucene/core/src/test/org/apache/lucene/codecs/asserting/ lucene/core/src/test/org/apache/lucene/search/ lucene/test-framework/ lucene/test-framework/src/java/org/apache/l...
Date Mon, 22 Sep 2014 16:42:44 GMT
Author: rmuir
Date: Mon Sep 22 16:42:44 2014
New Revision: 1626830

URL: http://svn.apache.org/r1626830
Log:
LUCENE-5969: let AssertingCodec implement RandomAccessOrds, and test it directly too

Added:
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/codecs/asserting/
      - copied from r1626826, lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/
Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/core/   (props changed)
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java
    lucene/dev/branches/branch_5x/lucene/test-framework/   (props changed)
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java?rev=1626830&r1=1626829&r2=1626830&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java
Mon Sep 22 16:42:44 2014
@@ -17,9 +17,6 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
-import org.apache.lucene.codecs.Codec;
-import org.apache.lucene.codecs.lucene410.Lucene410DocValuesFormat;
-import org.apache.lucene.codecs.memory.DirectDocValuesFormat;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.SortedSetDocValuesField;
@@ -28,30 +25,12 @@ import org.apache.lucene.index.RandomInd
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util.TestUtil;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
 
 /** Tests for SortedSetSortField selectors other than MIN,
  *  these require optional codec support (random access to ordinals) */
+@SuppressCodecs("Memory") // TODO: fix MemoryDV to support random access to ordinals
 public class TestSortedSetSelector extends LuceneTestCase {
-  static Codec savedCodec;
-  
-  @BeforeClass
-  public static void beforeClass() throws Exception {
-    savedCodec = Codec.getDefault();
-    // currently only these codecs that support random access ordinals
-    int victim = random().nextInt(2);
-    switch(victim) {
-      case 0:  Codec.setDefault(TestUtil.alwaysDocValuesFormat(new DirectDocValuesFormat()));
break;
-      default: Codec.setDefault(TestUtil.alwaysDocValuesFormat(new Lucene410DocValuesFormat()));
-    }
-  }
-  
-  @AfterClass
-  public static void afterClass() throws Exception {
-    Codec.setDefault(savedCodec);
-  }
   
   public void testMax() throws Exception {
     Directory dir = newDirectory();

Modified: lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java?rev=1626830&r1=1626829&r2=1626830&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java
Mon Sep 22 16:42:44 2014
@@ -28,11 +28,14 @@ import org.apache.lucene.index.Asserting
 import org.apache.lucene.index.BinaryDocValues;
 import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.NumericDocValues;
+import org.apache.lucene.index.RandomAccessOrds;
 import org.apache.lucene.index.SegmentReadState;
 import org.apache.lucene.index.SegmentWriteState;
 import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.index.SortedNumericDocValues;
 import org.apache.lucene.index.SortedSetDocValues;
+import org.apache.lucene.index.AssertingAtomicReader.AssertingRandomAccessOrds;
+import org.apache.lucene.index.AssertingAtomicReader.AssertingSortedSetDocValues;
 import org.apache.lucene.util.Accountable;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
@@ -258,7 +261,11 @@ public class AssertingDocValuesFormat ex
       assert field.getDocValuesType() == FieldInfo.DocValuesType.SORTED_SET;
       SortedSetDocValues values = in.getSortedSet(field);
       assert values != null;
-      return new AssertingAtomicReader.AssertingSortedSetDocValues(values, maxDoc);
+      if (values instanceof RandomAccessOrds) {
+        return new AssertingRandomAccessOrds((RandomAccessOrds) values, maxDoc);
+      } else {
+        return new AssertingSortedSetDocValues(values, maxDoc);
+      }
     }
     
     @Override

Modified: lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java?rev=1626830&r1=1626829&r2=1626830&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java
Mon Sep 22 16:42:44 2014
@@ -546,6 +546,77 @@ public class AssertingAtomicReader exten
     } 
   }
   
+  /** Wraps a RandomAccessOrds but with additional asserts */
+  public static class AssertingRandomAccessOrds extends RandomAccessOrds {
+    private final RandomAccessOrds in;
+    private final int maxDoc;
+    private final long valueCount;
+    long lastOrd = NO_MORE_ORDS;
+    
+    public AssertingRandomAccessOrds(RandomAccessOrds in, int maxDoc) {
+      this.in = in;
+      this.maxDoc = maxDoc;
+      this.valueCount = in.getValueCount();
+      assert valueCount >= 0;
+    }
+    
+    @Override
+    public long nextOrd() {
+      assert lastOrd != NO_MORE_ORDS;
+      long ord = in.nextOrd();
+      assert ord < valueCount;
+      assert ord == NO_MORE_ORDS || ord > lastOrd;
+      lastOrd = ord;
+      return ord;
+    }
+
+    @Override
+    public void setDocument(int docID) {
+      assert docID >= 0 && docID < maxDoc : "docid=" + docID + ",maxDoc=" +
maxDoc;
+      in.setDocument(docID);
+      lastOrd = -2;
+    }
+
+    @Override
+    public BytesRef lookupOrd(long ord) {
+      assert ord >= 0 && ord < valueCount;
+      final BytesRef result = in.lookupOrd(ord);
+      assert result.isValid();
+      return result;
+    }
+
+    @Override
+    public long getValueCount() {
+      long valueCount = in.getValueCount();
+      assert valueCount == this.valueCount; // should not change
+      return valueCount;
+    }
+
+    @Override
+    public long lookupTerm(BytesRef key) {
+      assert key.isValid();
+      long result = in.lookupTerm(key);
+      assert result < valueCount;
+      assert key.isValid();
+      return result;
+    }
+
+    @Override
+    public long ordAt(int index) {
+      assert index < in.cardinality();
+      long ord = in.ordAt(index);
+      assert ord >= 0 && ord < valueCount;
+      return ord;
+    }
+
+    @Override
+    public int cardinality() {
+      int cardinality = in.cardinality();
+      assert cardinality >= 0;
+      return cardinality;
+    }
+  }
+  
   /** Wraps a SortedSetDocValues but with additional asserts */
   public static class AssertingSortedSetDocValues extends SortedSetDocValues {
     private final SortedSetDocValues in;
@@ -665,7 +736,11 @@ public class AssertingAtomicReader exten
     if (dv != null) {
       assert fi != null;
       assert fi.getDocValuesType() == FieldInfo.DocValuesType.SORTED_SET;
-      return new AssertingSortedSetDocValues(dv, maxDoc());
+      if (dv instanceof RandomAccessOrds) {
+        return new AssertingRandomAccessOrds((RandomAccessOrds) dv, maxDoc());
+      } else {
+        return new AssertingSortedSetDocValues(dv, maxDoc());
+      }
     } else {
       assert fi == null || fi.getDocValuesType() != FieldInfo.DocValuesType.SORTED_SET;
       return null;



Mime
View raw message