mirror of https://github.com/apache/lucene.git
fix lucenetestcase to report the actual codec used instead of always lucene40 when a test fails
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1344392 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d222ddfcc3
commit
b2a864c7ce
|
@ -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;
|
||||
|
@ -53,6 +54,9 @@ 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,
|
||||
// otherwise DWPT's .toString() calls that iterate over the map can
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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 setup
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue