Apache Lucene open-source search software
fix lucenetestcase to report the actual codec used instead of always lucene40 when a test fails
Robert Muirb2a864c7ce0f
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java b/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.javaindex 1a8f1a58e72..28da1872ebb 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/RandomCodec.java@@ -20,6 +20,7 @@ package org.apache.lucene.index;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;+import java.util.HashSet;import java.util.List;import java.util.Locale;import java.util.Map;@@ -52,6 +53,9 @@ import org.apache.lucene.util._TestUtil;public class RandomCodec extends Lucene40Codec {/** Shuffled list of postings formats to use for new mappings */private List<PostingsFormat> formats = new ArrayList<PostingsFormat>();++ /** unique set of format names this codec knows about */+ public Set<String> formatNames = new HashSet<String>();/** memorized field->postingsformat mappings */// note: we have to sync this map even though its just for debugging/toString,@@ -109,6 +113,7 @@ public class RandomCodec extends Lucene40Codec {for (PostingsFormat p : postings) {if (!avoidCodecs.contains(p.getName())) {formats.add(p);+ formatNames.add(p.getName());}}}diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java b/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.javaindex ca0df2f5bc9..ebc74d8f1a2 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java@@ -116,7 +116,7 @@ public final class RunListenerPrintReproduceInfo extends RunListener {/** print some useful debugging information about the environment */static void printDebuggingInformation() {if (classEnvRule != null) {- System.err.println("NOTE: test params are: codec=" + Codec.getDefault() ++ System.err.println("NOTE: test params are: codec=" + classEnvRule.codec +", sim=" + classEnvRule.similarity +", locale=" + classEnvRule.locale +", timezone=" + (classEnvRule.timeZone == null ? "(null)" : classEnvRule.timeZone.getID()));diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.javaindex 264967ad946..027aa681f52 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java@@ -64,6 +64,7 @@ final class TestRuleSetupAndRestoreClassEnv extends AbstractBeforeAfterRule {Locale locale;TimeZone timeZone;Similarity similarity;+ Codec codec;/*** @see SuppressCodecs@@ -154,7 +155,6 @@ final class TestRuleSetupAndRestoreClassEnv extends AbstractBeforeAfterRule {PREFLEX_IMPERSONATION_IS_ACTIVE = false;savedCodec = Codec.getDefault();- final Codec codec;int randomVal = random.nextInt(10);/* note: re-enable this if we make a 4.x impersonator* if ("Lucene3x".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal < 2 && !shouldAvoidCodec("Lucene3x"))) { // preflex-only setupdiff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreInstanceEnv.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreInstanceEnv.javaindex 555f788e7c5..d6a0a90afdf 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreInstanceEnv.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreInstanceEnv.java@@ -1,5 +1,8 @@package org.apache.lucene.util;+import org.apache.lucene.codecs.Codec;+import org.apache.lucene.codecs.PostingsFormat;+import org.apache.lucene.index.RandomCodec;import org.apache.lucene.search.BooleanQuery;import org.junit.internal.AssumptionViolatedException;@@ -30,11 +33,26 @@ final class TestRuleSetupAndRestoreInstanceEnv extends AbstractBeforeAfterRule {protected void before() {savedBoolMaxClauseCount = BooleanQuery.getMaxClauseCount();- final String defFormat = _TestUtil.getPostingsFormat("thisCodeMakesAbsolutelyNoSenseCanWeDeleteIt");- if (LuceneTestCase.shouldAvoidCodec(defFormat)) {+ Codec codec = Codec.getDefault();+ if (LuceneTestCase.shouldAvoidCodec(codec.getName())) {throw new AssumptionViolatedException(- "Method not allowed to use codec: " + defFormat + ".");+ "Method not allowed to use codec: " + codec.getName() + ".");}+ // TODO: make this more efficient+ if (codec instanceof RandomCodec) {+ for (String name : ((RandomCodec)codec).formatNames) {+ if (LuceneTestCase.shouldAvoidCodec(name)) {+ throw new AssumptionViolatedException(+ "Method not allowed to use postings format: " + name + ".");+ }+ }+ }+ PostingsFormat pf = codec.postingsFormat();+ if (LuceneTestCase.shouldAvoidCodec(pf.getName())) {+ throw new AssumptionViolatedException(+ "Method not allowed to use postings format: " + pf.getName() + ".");+ }+}protected void after() {