You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2011/10/31 14:02:11 UTC

svn commit: r1195437 - in /lucene/dev/branches/lucene2621/lucene/src: java/org/apache/lucene/index/codecs/perfield/PerFieldPostingsFormat.java test-framework/org/apache/lucene/util/_TestUtil.java test/org/apache/lucene/TestExternalCodecs.java

Author: mikemccand
Date: Mon Oct 31 13:02:10 2011
New Revision: 1195437

URL: http://svn.apache.org/viewvc?rev=1195437&view=rev
Log:
TestExternalCodecs passes

Modified:
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/perfield/PerFieldPostingsFormat.java
    lucene/dev/branches/lucene2621/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/TestExternalCodecs.java

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/perfield/PerFieldPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/perfield/PerFieldPostingsFormat.java?rev=1195437&r1=1195436&r2=1195437&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/perfield/PerFieldPostingsFormat.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/perfield/PerFieldPostingsFormat.java Mon Oct 31 13:02:10 2011
@@ -119,6 +119,11 @@ public abstract class PerFieldPostingsFo
         // next id and init it:
         final int formatID = formats.size();
         PostingsFormat postingsFormat = getPostingsFormat(formatName);
+        if (postingsFormat instanceof PerFieldPostingsFormat) {
+          // nocommit -- if we cutover to String formatID
+          // we can fix this?
+          throw new IllegalStateException("cannot embed PerFieldPostingsFormat inside itself");
+        }
         assert postingsFormat != null: "formatName=" + formatName + " returned null PostingsFormat impl; this=" + PerFieldPostingsFormat.this;
         // nocommit: maybe the int formatID should be
         // separate arg to .fieldsConsumer?  like we do for
@@ -275,6 +280,12 @@ public abstract class PerFieldPostingsFo
           final int formatID = in.readVInt();
           final String formatName = in.readString();
           PostingsFormat postingsFormat = getPostingsFormat(formatName);
+          if (postingsFormat instanceof PerFieldPostingsFormat) {
+            // nocommit -- if we cutover to String formatID
+            // we can fix this?
+            throw new IllegalStateException("cannot embed PerFieldPostingsFormat inside itself");
+          }
+
           // Better be defined, because it was defined
           // during indexing:
           // nocommit: real exception?

Modified: lucene/dev/branches/lucene2621/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java?rev=1195437&r1=1195436&r2=1195437&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java Mon Oct 31 13:02:10 2011
@@ -403,6 +403,33 @@ public class _TestUtil {
       
     });
   }
+
+  /** Returns a CodecProvider that can only read and write
+   *  the provided PostingsFormat, and uses default format
+   *  for DocValues and Fields. */
+  public static CodecProvider onlyFormat(final PostingsFormat postingsFormat) {
+
+    final Codec onlyCodec = new Codec("Only") {
+      private final FieldsFormat fieldsFormat = new DefaultFieldsFormat();
+      private final DocValuesFormat docValuesFormat = new DefaultDocValuesFormat();
+
+      @Override
+      public PostingsFormat postingsFormat() {
+        return postingsFormat;
+      }
+
+      @Override
+      public DocValuesFormat docValuesFormat() {
+        return docValuesFormat;
+      }                
+
+      @Override
+      public FieldsFormat fieldsFormat() {
+        return fieldsFormat;
+      }                
+    };
+    return alwaysCodec(onlyCodec);
+  }
   
   public static String getPostingsFormat(String field) {
     PostingsFormat p = CodecProvider.getDefault().getDefaultCodec().postingsFormat();

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/TestExternalCodecs.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/TestExternalCodecs.java?rev=1195437&r1=1195436&r2=1195437&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/TestExternalCodecs.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/TestExternalCodecs.java Mon Oct 31 13:02:10 2011
@@ -548,7 +548,7 @@ public class TestExternalCodecs extends 
     IndexWriter w = new IndexWriter(
         dir,
         newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).
-        setCodecProvider(_TestUtil.alwaysFormat(new CustomPerFieldPostingsFormat())).
+        setCodecProvider(_TestUtil.onlyFormat(new CustomPerFieldPostingsFormat())).
             setMergePolicy(newLogMergePolicy(3))
     );
     w.setInfoStream(VERBOSE ? System.out : null);