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 2013/01/28 06:00:55 UTC

svn commit: r1439252 - in /lucene/dev/branches/lucene4547/lucene: core/src/java/org/apache/lucene/index/ core/src/java/org/apache/lucene/util/ core/src/test/org/apache/lucene/index/ test-framework/src/java/org/apache/lucene/codecs/asserting/ test-frame...

Author: rmuir
Date: Mon Jan 28 05:00:54 2013
New Revision: 1439252

URL: http://svn.apache.org/viewvc?rev=1439252&view=rev
Log:
improve tests

Added:
    lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java   (with props)
    lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingNormsFormat.java   (with props)
    lucene/dev/branches/lucene4547/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.DocValuesFormat
Modified:
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/BytesRef.java
    lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
    lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
    lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingCodec.java
    lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java
    lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java?rev=1439252&r1=1439251&r2=1439252&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java Mon Jan 28 05:00:54 2013
@@ -769,7 +769,7 @@ public class CheckIndex {
           break;
         }
         
-        checkBounds(term);
+        assert term.isValid();
         
         // make sure terms arrive in order according to
         // the comp
@@ -859,7 +859,7 @@ public class CheckIndex {
               lastPos = pos;
               BytesRef payload = postings.getPayload();
               if (payload != null) {
-                checkBounds(payload);
+                assert payload.isValid();
               }
               if (payload != null && payload.length < 1) {
                 throw new RuntimeException("term " + term + ": doc " + doc + ": pos " + pos + " payload length is out of bounds " + payload.length);
@@ -1296,32 +1296,7 @@ public class CheckIndex {
     BytesRef scratch = new BytesRef();
     for (int i = 0; i < reader.maxDoc(); i++) {
       dv.get(i, scratch);
-      checkBounds(scratch);
-    }
-  }
-  
-  // basic value checks
-  private static void checkBounds(BytesRef b) {
-    if (b.bytes == null) {
-      throw new RuntimeException("bytes is null");
-    }
-    if (b.length < 0) {
-      throw new RuntimeException("length is negative: " + b.length);
-    }
-    if (b.length > b.bytes.length) {
-      throw new RuntimeException("length is out of bounds: " + b.length + ", bytes.length=" + b.bytes.length);
-    }
-    if (b.offset < 0) {
-      throw new RuntimeException("offset is negative: " + b.offset);
-    }
-    if (b.offset > b.bytes.length) {
-      throw new RuntimeException("offset out of bounds: " + b.offset + ", length=" + b.length);
-    }
-    if (b.offset + b.length < 0) {
-      throw new RuntimeException("offset+length is negative: offset=" + b.offset + ",length=" + b.length);
-    }
-    if (b.offset + b.length > b.bytes.length) {
-      throw new RuntimeException("offset+length out of bounds: offset=" + b.offset + ",length=" + b.length + ",bytes.length=" + b.bytes.length);
+      assert scratch.isValid();
     }
   }
   
@@ -1348,7 +1323,7 @@ public class CheckIndex {
     BytesRef scratch = new BytesRef();
     for (int i = 0; i <= maxOrd; i++) {
       dv.lookupOrd(i, scratch);
-      checkBounds(scratch);
+      assert scratch.isValid();
       if (lastValue != null) {
         if (scratch.compareTo(lastValue) <= 0) {
           throw new RuntimeException("dv for field: " + fieldName + " has ords out of order: " + lastValue + " >=" + scratch);

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java?rev=1439252&r1=1439251&r2=1439252&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/SlowCompositeReaderWrapper.java Mon Jan 28 05:00:54 2013
@@ -100,13 +100,11 @@ public final class SlowCompositeReaderWr
   @Override
   public NumericDocValues getNormValues(String field) throws IOException {
     ensureOpen();
-    // nocommit hmm
     return MultiDocValues.getNormValues(in, field);
   }
   
   @Override
-  public Fields getTermVectors(int docID)
-          throws IOException {
+  public Fields getTermVectors(int docID) throws IOException {
     ensureOpen();
     return in.getTermVectors(docID);
   }

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/BytesRef.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/BytesRef.java?rev=1439252&r1=1439251&r2=1439252&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/BytesRef.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/BytesRef.java Mon Jan 28 05:00:54 2013
@@ -52,13 +52,10 @@ public final class BytesRef implements C
    * bytes should not be null.
    */
   public BytesRef(byte[] bytes, int offset, int length) {
-    assert bytes != null;
-    assert offset >= 0;
-    assert length >= 0;
-    assert bytes.length >= offset + length;
     this.bytes = bytes;
     this.offset = offset;
     this.length = length;
+    assert isValid();
   }
 
   /** This instance will directly reference bytes w/o making a copy.
@@ -340,4 +337,34 @@ public final class BytesRef implements C
     copy.copyBytes(other);
     return copy;
   }
+  
+  /** 
+   * Performs internal consistency checks.
+   * Always returns true (or throws IllegalStateException) 
+   */
+  // TODO: also for the other *Ref classes
+  public boolean isValid() {
+    if (bytes == null) {
+      throw new IllegalStateException("bytes is null");
+    }
+    if (length < 0) {
+      throw new IllegalStateException("length is negative: " + length);
+    }
+    if (length > bytes.length) {
+      throw new IllegalStateException("length is out of bounds: " + length + ", bytes.length=" + bytes.length);
+    }
+    if (offset < 0) {
+      throw new IllegalStateException("offset is negative: " + offset);
+    }
+    if (offset > bytes.length) {
+      throw new IllegalStateException("offset out of bounds: " + offset + ", length=" + bytes.length);
+    }
+    if (offset + length < 0) {
+      throw new IllegalStateException("offset+length is negative: offset=" + offset + ",length=" + length);
+    }
+    if (offset + length > bytes.length) {
+      throw new IllegalStateException("offset+length out of bounds: offset=" + offset + ",length=" + length + ",bytes.length=" + bytes.length);
+    }
+    return true;
+  }
 }

Modified: lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java?rev=1439252&r1=1439251&r2=1439252&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java Mon Jan 28 05:00:54 2013
@@ -64,8 +64,6 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 
-// nocommit fails: ant test  -Dtestcase=TestBackwardsCompatibility -Dtests.method=testExactFileNames -Dtests.seed=F5A14C72AFCA024E -Dtests.slow=true -Dtests.locale=pl_PL -Dtests.timezone=America/Argentina/La_Rioja -Dtests.file.encoding=ISO-8859-1
-
 /*
   Verify we can read the pre-5.0 file format, do searches
   against it, and add documents to it.

Modified: lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java?rev=1439252&r1=1439251&r2=1439252&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java Mon Jan 28 05:00:54 2013
@@ -1019,7 +1019,6 @@ public class TestDocValuesIndexing exten
   }
 
   public void testDocValuesUnstored() throws IOException {
-    //nocommit convert!
     Directory dir = newDirectory();
     IndexWriterConfig iwconfig = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
     iwconfig.setMergePolicy(newLogMergePolicy());

Modified: lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingCodec.java?rev=1439252&r1=1439251&r2=1439252&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingCodec.java (original)
+++ lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingCodec.java Mon Jan 28 05:00:54 2013
@@ -17,7 +17,9 @@ package org.apache.lucene.codecs.asserti
  * limitations under the License.
  */
 
+import org.apache.lucene.codecs.DocValuesFormat;
 import org.apache.lucene.codecs.FilterCodec;
+import org.apache.lucene.codecs.NormsFormat;
 import org.apache.lucene.codecs.PostingsFormat;
 import org.apache.lucene.codecs.StoredFieldsFormat;
 import org.apache.lucene.codecs.TermVectorsFormat;
@@ -31,6 +33,8 @@ public final class AssertingCodec extend
   private final PostingsFormat postings = new AssertingPostingsFormat();
   private final TermVectorsFormat vectors = new AssertingTermVectorsFormat();
   private final StoredFieldsFormat storedFields = new AssertingStoredFieldsFormat();
+  private final DocValuesFormat docValues = new AssertingDocValuesFormat();
+  private final NormsFormat norms = new AssertingNormsFormat();
 
   public AssertingCodec() {
     super("Asserting", new Lucene42Codec());
@@ -50,4 +54,14 @@ public final class AssertingCodec extend
   public StoredFieldsFormat storedFieldsFormat() {
     return storedFields;
   }
+
+  @Override
+  public DocValuesFormat docValuesFormat() {
+    return docValues;
+  }
+
+  @Override
+  public NormsFormat normsFormat() {
+    return norms;
+  }
 }

Added: lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java?rev=1439252&view=auto
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java (added)
+++ lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingDocValuesFormat.java Mon Jan 28 05:00:54 2013
@@ -0,0 +1,169 @@
+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 java.io.IOException;
+
+import org.apache.lucene.codecs.DocValuesConsumer;
+import org.apache.lucene.codecs.DocValuesFormat;
+import org.apache.lucene.codecs.DocValuesProducer;
+import org.apache.lucene.codecs.lucene42.Lucene42DocValuesFormat;
+import org.apache.lucene.index.AssertingAtomicReader;
+import org.apache.lucene.index.BinaryDocValues;
+import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.index.NumericDocValues;
+import org.apache.lucene.index.SegmentReadState;
+import org.apache.lucene.index.SegmentWriteState;
+import org.apache.lucene.index.SortedDocValues;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.FixedBitSet;
+
+/**
+ * Just like {@link Lucene42DocValuesFormat} but with additional asserts.
+ */
+public class AssertingDocValuesFormat extends DocValuesFormat {
+  private final DocValuesFormat in = new Lucene42DocValuesFormat();
+  
+  public AssertingDocValuesFormat() {
+    super("Asserting");
+  }
+
+  @Override
+  public DocValuesConsumer fieldsConsumer(SegmentWriteState state) throws IOException {
+    DocValuesConsumer consumer = in.fieldsConsumer(state);
+    assert consumer != null;
+    return new AssertingDocValuesConsumer(consumer, state.segmentInfo.getDocCount());
+  }
+
+  @Override
+  public DocValuesProducer fieldsProducer(SegmentReadState state) throws IOException {
+    assert state.fieldInfos.hasDocValues();
+    DocValuesProducer producer = in.fieldsProducer(state);
+    assert producer != null;
+    return new AssertingDocValuesProducer(producer, state.segmentInfo.getDocCount());
+  }
+  
+  static class AssertingDocValuesConsumer extends DocValuesConsumer {
+    private final DocValuesConsumer in;
+    private final int maxDoc;
+    
+    AssertingDocValuesConsumer(DocValuesConsumer in, int maxDoc) {
+      this.in = in;
+      this.maxDoc = maxDoc;
+    }
+
+    @Override
+    public void addNumericField(FieldInfo field, Iterable<Number> values) throws IOException {
+      int count = 0;
+      for (Number v : values) {
+        assert v != null;
+        count++;
+      }
+      assert count == maxDoc;
+      in.addNumericField(field, values);
+    }
+    
+    @Override
+    public void addBinaryField(FieldInfo field, Iterable<BytesRef> values) throws IOException {
+      int count = 0;
+      for (BytesRef b : values) {
+        assert b != null;
+        assert b.isValid();
+        count++;
+      }
+      assert count == maxDoc;
+      in.addBinaryField(field, values);
+    }
+    
+    @Override
+    public void addSortedField(FieldInfo field, Iterable<BytesRef> values, Iterable<Number> docToOrd) throws IOException {
+      int valueCount = 0;
+      BytesRef lastValue = null;
+      for (BytesRef b : values) {
+        assert b != null;
+        assert b.isValid();
+        if (valueCount > 0) {
+          assert b.compareTo(lastValue) > 0;
+        }
+        lastValue = BytesRef.deepCopyOf(b);
+        valueCount++;
+      }
+      assert valueCount <= maxDoc;
+      
+      FixedBitSet seenOrds = new FixedBitSet(valueCount);
+      
+      int count = 0;
+      for (Number v : docToOrd) {
+        assert v != null;
+        int ord = v.intValue();
+        assert ord >= 0 && ord < valueCount;
+        seenOrds.set(ord);
+        count++;
+      }
+      
+      assert count == maxDoc;
+      assert seenOrds.cardinality() == valueCount;
+      in.addSortedField(field, values, docToOrd);
+    }
+    
+    @Override
+    public void close() throws IOException {
+      in.close();
+    }
+  }
+  
+  static class AssertingDocValuesProducer extends DocValuesProducer {
+    private final DocValuesProducer in;
+    private final int maxDoc;
+    
+    AssertingDocValuesProducer(DocValuesProducer in, int maxDoc) {
+      this.in = in;
+      this.maxDoc = maxDoc;
+    }
+
+    @Override
+    public NumericDocValues getNumeric(FieldInfo field) throws IOException {
+      assert field.getDocValuesType() == FieldInfo.DocValuesType.NUMERIC || 
+             field.getNormType() == FieldInfo.DocValuesType.NUMERIC;
+      NumericDocValues values = in.getNumeric(field);
+      assert values != null;
+      return new AssertingAtomicReader.AssertingNumericDocValues(values, maxDoc);
+    }
+
+    @Override
+    public BinaryDocValues getBinary(FieldInfo field) throws IOException {
+      assert field.getDocValuesType() == FieldInfo.DocValuesType.BINARY;
+      BinaryDocValues values = in.getBinary(field);
+      assert values != null;
+      return new AssertingAtomicReader.AssertingBinaryDocValues(values, maxDoc);
+    }
+
+    @Override
+    public SortedDocValues getSorted(FieldInfo field) throws IOException {
+      assert field.getDocValuesType() == FieldInfo.DocValuesType.SORTED;
+      SortedDocValues values = in.getSorted(field);
+      assert values != null;
+      return new AssertingAtomicReader.AssertingSortedDocValues(values, maxDoc);
+    }
+    
+    @Override
+    public void close() throws IOException {
+      in.close();
+    }
+  }
+}

Added: lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingNormsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingNormsFormat.java?rev=1439252&view=auto
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingNormsFormat.java (added)
+++ lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingNormsFormat.java Mon Jan 28 05:00:54 2013
@@ -0,0 +1,51 @@
+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 java.io.IOException;
+
+import org.apache.lucene.codecs.DocValuesConsumer;
+import org.apache.lucene.codecs.DocValuesProducer;
+import org.apache.lucene.codecs.NormsFormat;
+import org.apache.lucene.codecs.asserting.AssertingDocValuesFormat.AssertingDocValuesConsumer;
+import org.apache.lucene.codecs.asserting.AssertingDocValuesFormat.AssertingDocValuesProducer;
+import org.apache.lucene.codecs.lucene42.Lucene42NormsFormat;
+import org.apache.lucene.index.SegmentReadState;
+import org.apache.lucene.index.SegmentWriteState;
+
+/**
+ * Just like {@link Lucene42NormsFormat} but with additional asserts.
+ */
+public class AssertingNormsFormat extends NormsFormat {
+  private final NormsFormat in = new Lucene42NormsFormat();
+  
+  @Override
+  public DocValuesConsumer normsConsumer(SegmentWriteState state) throws IOException {
+    DocValuesConsumer consumer = in.normsConsumer(state);
+    assert consumer != null;
+    return new AssertingDocValuesConsumer(consumer, state.segmentInfo.getDocCount());
+  }
+
+  @Override
+  public DocValuesProducer normsProducer(SegmentReadState state) throws IOException {
+    assert state.fieldInfos.hasNorms();
+    DocValuesProducer producer = in.normsProducer(state);
+    assert producer != null;
+    return new AssertingDocValuesProducer(producer, state.segmentInfo.getDocCount());
+  }
+}

Modified: lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java?rev=1439252&r1=1439251&r2=1439252&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java (original)
+++ lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java Mon Jan 28 05:00:54 2013
@@ -86,6 +86,7 @@ public class AssertingAtomicReader exten
     public TermsEnum intersect(CompiledAutomaton automaton, BytesRef bytes) throws IOException {
       TermsEnum termsEnum = super.intersect(automaton, bytes);
       assert termsEnum != null;
+      assert bytes == null || bytes.isValid();
       return new AssertingTermsEnum(termsEnum);
     }
 
@@ -145,6 +146,7 @@ public class AssertingAtomicReader exten
       if (result == null) {
         state = State.UNPOSITIONED;
       } else {
+        assert result.isValid();
         state = State.POSITIONED;
       }
       return result;
@@ -171,7 +173,9 @@ public class AssertingAtomicReader exten
     @Override
     public BytesRef term() throws IOException {
       assert state == State.POSITIONED : "term() called on unpositioned TermsEnum";
-      return super.term();
+      BytesRef ret = super.term();
+      assert ret == null || ret.isValid();
+      return ret;
     }
 
     @Override
@@ -182,6 +186,7 @@ public class AssertingAtomicReader exten
 
     @Override
     public SeekStatus seekCeil(BytesRef term, boolean useCache) throws IOException {
+      assert term.isValid();
       SeekStatus result = super.seekCeil(term, useCache);
       if (result == SeekStatus.END) {
         state = State.UNPOSITIONED;
@@ -193,6 +198,7 @@ public class AssertingAtomicReader exten
 
     @Override
     public boolean seekExact(BytesRef text, boolean useCache) throws IOException {
+      assert text.isValid();
       if (super.seekExact(text, useCache)) {
         state = State.POSITIONED;
         return true;
@@ -210,6 +216,7 @@ public class AssertingAtomicReader exten
 
     @Override
     public void seekExact(BytesRef term, TermState state) throws IOException {
+      assert term.isValid();
       super.seekExact(term, state);
       this.state = State.POSITIONED;
     }
@@ -352,10 +359,158 @@ public class AssertingAtomicReader exten
       assert state != DocsEnumState.FINISHED : "getPayload() called after NO_MORE_DOCS";
       assert positionCount > 0 : "getPayload() called before nextPosition()!";
       BytesRef payload = super.getPayload();
-      assert payload == null || payload.length > 0 : "getPayload() returned payload with invalid length!";
+      assert payload == null || payload.isValid() && payload.length > 0 : "getPayload() returned payload with invalid length!";
       return payload;
     }
   }
+  
+  /** Wraps a NumericDocValues but with additional asserts */
+  public static class AssertingNumericDocValues extends NumericDocValues {
+    private final NumericDocValues in;
+    private final int maxDoc;
+    
+    public AssertingNumericDocValues(NumericDocValues in, int maxDoc) {
+      this.in = in;
+      this.maxDoc = maxDoc;
+    }
+
+    @Override
+    public long get(int docID) {
+      assert docID >= 0 && docID < maxDoc;
+      return in.get(docID);
+    }    
+  }
+  
+  /** Wraps a BinaryDocValues but with additional asserts */
+  public static class AssertingBinaryDocValues extends BinaryDocValues {
+    private final BinaryDocValues in;
+    private final int maxDoc;
+    
+    public AssertingBinaryDocValues(BinaryDocValues in, int maxDoc) {
+      this.in = in;
+      this.maxDoc = maxDoc;
+    }
+
+    @Override
+    public void get(int docID, BytesRef result) {
+      assert docID >= 0 && docID < maxDoc;
+      assert result.isValid();
+      in.get(docID, result);
+      assert result.isValid();
+    }
+  }
+  
+  /** Wraps a SortedDocValues but with additional asserts */
+  public static class AssertingSortedDocValues extends SortedDocValues {
+    private final SortedDocValues in;
+    private final int maxDoc;
+    private final int valueCount;
+    
+    public AssertingSortedDocValues(SortedDocValues in, int maxDoc) {
+      this.in = in;
+      this.maxDoc = maxDoc;
+      this.valueCount = in.getValueCount();
+      assert valueCount >= 1 && valueCount <= maxDoc;
+    }
+
+    @Override
+    public int getOrd(int docID) {
+      assert docID >= 0 && docID < maxDoc;
+      int ord = in.getOrd(docID);
+      assert ord >= 0 && ord < valueCount;
+      return ord;
+    }
+
+    @Override
+    public void lookupOrd(int ord, BytesRef result) {
+      assert ord >= 0 && ord < valueCount;
+      assert result.isValid();
+      in.lookupOrd(ord, result);
+      assert result.isValid();
+    }
+
+    @Override
+    public int getValueCount() {
+      int valueCount = in.getValueCount();
+      assert valueCount == this.valueCount; // should not change
+      return valueCount;
+    }
+
+    @Override
+    public void get(int docID, BytesRef result) {
+      assert docID >= 0 && docID < maxDoc;
+      assert result.isValid();
+      in.get(docID, result);
+      assert result.isValid();
+    }
+
+    @Override
+    public int lookupTerm(BytesRef key, BytesRef spare) {
+      assert key.isValid();
+      assert spare.isValid();
+      int result = in.lookupTerm(key, spare);
+      assert result < valueCount;
+      assert key.isValid();
+      assert spare.isValid();
+      return result;
+    }
+  }
+
+  @Override
+  public NumericDocValues getNumericDocValues(String field) throws IOException {
+    NumericDocValues dv = super.getNumericDocValues(field);
+    FieldInfo fi = getFieldInfos().fieldInfo(field);
+    if (dv != null) {
+      assert fi != null;
+      assert fi.getDocValuesType() == FieldInfo.DocValuesType.NUMERIC;
+      return new AssertingNumericDocValues(dv, maxDoc());
+    } else {
+      assert fi == null || fi.hasDocValues() == false;
+      return null;
+    }
+  }
+
+  @Override
+  public BinaryDocValues getBinaryDocValues(String field) throws IOException {
+    BinaryDocValues dv = super.getBinaryDocValues(field);
+    FieldInfo fi = getFieldInfos().fieldInfo(field);
+    if (dv != null) {
+      assert fi != null;
+      assert fi.getDocValuesType() == FieldInfo.DocValuesType.BINARY;
+      return new AssertingBinaryDocValues(dv, maxDoc());
+    } else {
+      assert fi == null || fi.hasDocValues() == false;
+      return null;
+    }
+  }
+
+  @Override
+  public SortedDocValues getSortedDocValues(String field) throws IOException {
+    SortedDocValues dv = super.getSortedDocValues(field);
+    FieldInfo fi = getFieldInfos().fieldInfo(field);
+    if (dv != null) {
+      assert fi != null;
+      assert fi.getDocValuesType() == FieldInfo.DocValuesType.SORTED;
+      return new AssertingSortedDocValues(dv, maxDoc());
+    } else {
+      assert fi == null || fi.hasDocValues() == false;
+      return null;
+    }
+  }
+
+  @Override
+  public NumericDocValues getNormValues(String field) throws IOException {
+    NumericDocValues dv = super.getNormValues(field);
+    FieldInfo fi = getFieldInfos().fieldInfo(field);
+    if (dv != null) {
+      assert fi != null;
+      assert fi.hasNorms();
+      return new AssertingNumericDocValues(dv, maxDoc());
+    } else {
+      assert fi == null || fi.hasNorms() == false;
+      return null;
+    }
+  }
 
   // this is the same hack as FCInvisible
   @Override

Modified: lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java?rev=1439252&r1=1439251&r2=1439252&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java (original)
+++ lucene/dev/branches/lucene4547/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java Mon Jan 28 05:00:54 2013
@@ -29,6 +29,7 @@ import java.util.Set;
 
 import org.apache.lucene.codecs.PostingsFormat;
 import org.apache.lucene.codecs.DocValuesFormat;
+import org.apache.lucene.codecs.asserting.AssertingDocValuesFormat;
 import org.apache.lucene.codecs.asserting.AssertingPostingsFormat;
 import org.apache.lucene.codecs.lucene41.Lucene41PostingsFormat;
 import org.apache.lucene.codecs.lucene41ords.Lucene41WithOrds;
@@ -144,7 +145,8 @@ public class RandomCodec extends Lucene4
     addDocValues(avoidCodecs,
         new Lucene42DocValuesFormat(),
         new DiskDocValuesFormat(),
-        new SimpleTextDocValuesFormat());
+        new SimpleTextDocValuesFormat(),
+        new AssertingDocValuesFormat());
 
     Collections.shuffle(formats, random);
     Collections.shuffle(dvFormats, random);

Added: lucene/dev/branches/lucene4547/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.DocValuesFormat
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.DocValuesFormat?rev=1439252&view=auto
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.DocValuesFormat (added)
+++ lucene/dev/branches/lucene4547/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.DocValuesFormat Mon Jan 28 05:00:54 2013
@@ -0,0 +1,16 @@
+#  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.
+
+org.apache.lucene.codecs.asserting.AssertingDocValuesFormat