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 2014/09/22 18:38:51 UTC

svn commit: r1626826 - in /lucene/dev/trunk/lucene: core/src/test/org/apache/lucene/codecs/asserting/ core/src/test/org/apache/lucene/search/ test-framework/src/java/org/apache/lucene/codecs/asserting/ test-framework/src/java/org/apache/lucene/index/

Author: rmuir
Date: Mon Sep 22 16:38:51 2014
New Revision: 1626826

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

Added:
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingDocValuesFormat.java   (with props)
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingNormsFormat.java   (with props)
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingPostingsFormat.java   (with props)
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingStoredFieldsFormat.java   (with props)
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingTermVectorsFormat.java   (with props)
Modified:
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java
    lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java
    lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java

Added: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingDocValuesFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingDocValuesFormat.java?rev=1626826&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingDocValuesFormat.java (added)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingDocValuesFormat.java Mon Sep 22 16:38:51 2014
@@ -0,0 +1,31 @@
+package org.apache.lucene.codecs.asserting;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.codecs.Codec;
+import org.apache.lucene.index.BasePostingsFormatTestCase;
+
+/** Test AssertingPostingsFormat directly */
+public class TestAssertingDocValuesFormat extends BasePostingsFormatTestCase {
+  private final Codec codec = new AssertingCodec();
+  
+  @Override
+  protected Codec getCodec() {
+    return codec;
+  } 
+}

Added: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingNormsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingNormsFormat.java?rev=1626826&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingNormsFormat.java (added)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingNormsFormat.java Mon Sep 22 16:38:51 2014
@@ -0,0 +1,31 @@
+package org.apache.lucene.codecs.asserting;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.codecs.Codec;
+import org.apache.lucene.index.BaseNormsFormatTestCase;
+
+/** Test AssertingNormsFormat directly */
+public class TestAssertingNormsFormat extends BaseNormsFormatTestCase {
+  private final Codec codec = new AssertingCodec();
+  
+  @Override
+  protected Codec getCodec() {
+    return codec;
+  } 
+}

Added: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingPostingsFormat.java?rev=1626826&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingPostingsFormat.java (added)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingPostingsFormat.java Mon Sep 22 16:38:51 2014
@@ -0,0 +1,31 @@
+package org.apache.lucene.codecs.asserting;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.codecs.Codec;
+import org.apache.lucene.index.BaseDocValuesFormatTestCase;
+
+/** Test AssertingDocValuesFormat directly */
+public class TestAssertingPostingsFormat extends BaseDocValuesFormatTestCase {
+  private final Codec codec = new AssertingCodec();
+  
+  @Override
+  protected Codec getCodec() {
+    return codec;
+  } 
+}

Added: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingStoredFieldsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingStoredFieldsFormat.java?rev=1626826&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingStoredFieldsFormat.java (added)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingStoredFieldsFormat.java Mon Sep 22 16:38:51 2014
@@ -0,0 +1,31 @@
+package org.apache.lucene.codecs.asserting;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.codecs.Codec;
+import org.apache.lucene.index.BaseTermVectorsFormatTestCase;
+
+/** Test AssertingTermVectorsFormat directly */
+public class TestAssertingStoredFieldsFormat extends BaseTermVectorsFormatTestCase {
+  private final Codec codec = new AssertingCodec();
+  
+  @Override
+  protected Codec getCodec() {
+    return codec;
+  } 
+}

Added: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingTermVectorsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingTermVectorsFormat.java?rev=1626826&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingTermVectorsFormat.java (added)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/codecs/asserting/TestAssertingTermVectorsFormat.java Mon Sep 22 16:38:51 2014
@@ -0,0 +1,31 @@
+package org.apache.lucene.codecs.asserting;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.codecs.Codec;
+import org.apache.lucene.index.BaseStoredFieldsFormatTestCase;
+
+/** Test AssertingStoredFieldsFormat directly */
+public class TestAssertingTermVectorsFormat extends BaseStoredFieldsFormatTestCase {
+  private final Codec codec = new AssertingCodec();
+  
+  @Override
+  protected Codec getCodec() {
+    return codec;
+  } 
+}

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java?rev=1626826&r1=1626825&r2=1626826&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java Mon Sep 22 16:38:51 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/trunk/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java?rev=1626826&r1=1626825&r2=1626826&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java Mon Sep 22 16:38:51 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/trunk/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java?rev=1626826&r1=1626825&r2=1626826&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java Mon Sep 22 16:38:51 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;