LUCENE-3076: add -Dtests.codecprovider

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1100175 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2011-05-06 11:42:24 +00:00
parent 826b1d32bd
commit 2f75783026
10 changed files with 51 additions and 13 deletions

View File

@ -73,6 +73,7 @@
</condition>
<property name="tests.multiplier" value="1" />
<property name="tests.codec" value="randomPerField" />
<property name="tests.codecprovider" value="random" />
<property name="tests.locale" value="random" />
<property name="tests.timezone" value="random" />
<property name="tests.directory" value="random" />
@ -499,6 +500,8 @@
<sysproperty key="tests.verbose" value="${tests.verbose}"/>
<!-- set the codec tests should run with -->
<sysproperty key="tests.codec" value="${tests.codec}"/>
<!-- set the codec provider tests should run with -->
<sysproperty key="tests.codecprovider" value="${tests.codecprovider}"/>
<!-- set the locale tests should run with -->
<sysproperty key="tests.locale" value="${tests.locale}"/>
<!-- set the timezone tests should run with -->

View File

@ -72,6 +72,11 @@ public class CodecProvider {
}
}
/** @lucene.internal */
public synchronized Set<String> listAll() {
return codecs.keySet();
}
public Collection<String> getAllExtensions() {
return knownExtensions;
}

View File

@ -137,6 +137,8 @@ public abstract class LuceneTestCase extends Assert {
// tests)
/** Gets the codec to run tests with. */
public static final String TEST_CODEC = System.getProperty("tests.codec", "randomPerField");
/** Gets the codecprovider to run tests with */
public static final String TEST_CODECPROVIDER = System.getProperty("tests.codecprovider", "random");
/** Gets the locale to run tests with */
public static final String TEST_LOCALE = System.getProperty("tests.locale", "random");
/** Gets the timezone to run tests with */
@ -329,6 +331,7 @@ public abstract class LuceneTestCase extends Assert {
tempDirs.clear();
stores = Collections.synchronizedMap(new IdentityHashMap<MockDirectoryWrapper,StackTraceElement[]>());
savedCodecProvider = CodecProvider.getDefault();
if ("random".equals(TEST_CODECPROVIDER)) {
if ("randomPerField".equals(TEST_CODEC)) {
if (random.nextInt(4) == 0) { // preflex-only setup
codec = installTestCodecs("PreFlex", CodecProvider.getDefault());
@ -339,6 +342,28 @@ public abstract class LuceneTestCase extends Assert {
} else { // ordinary setup
codec = installTestCodecs(TEST_CODEC, CodecProvider.getDefault());
}
} else {
// someone specified their own codecprovider by class
try {
Class<? extends CodecProvider> cpClazz = Class.forName(TEST_CODECPROVIDER).asSubclass(CodecProvider.class);
CodecProvider cp = cpClazz.newInstance();
String codecName;
if (TEST_CODEC.startsWith("random")) { // TODO: somehow do random per-field?!
Set<String> codecSet = cp.listAll();
String availableCodecs[] = codecSet.toArray(new String[codecSet.size()]);
codecName = availableCodecs[random.nextInt(availableCodecs.length)];
} else {
codecName = TEST_CODEC;
}
codec = cp.lookup(codecName);
cp.setDefaultFieldCodec(codecName);
CodecProvider.setDefault(cp);
} catch (Exception e) {
System.err.println("Could not instantiate CodecProvider: " + TEST_CODECPROVIDER);
throw new RuntimeException(e);
}
}
savedLocale = Locale.getDefault();
locale = TEST_LOCALE.equals("random") ? randomLocale(random) : localeForName(TEST_LOCALE);
Locale.setDefault(locale);
@ -360,16 +385,13 @@ public abstract class LuceneTestCase extends Assert {
String codecDescription;
CodecProvider cp = CodecProvider.getDefault();
if ("randomPerField".equals(TEST_CODEC)) {
if (cp instanceof RandomCodecProvider)
if ("randomPerField".equals(TEST_CODEC) && cp instanceof RandomCodecProvider) {
codecDescription = cp.toString();
else
codecDescription = "PreFlex";
} else {
codecDescription = codec.toString();
}
if (CodecProvider.getDefault() == savedCodecProvider)
if ("random".equals(TEST_CODECPROVIDER) && CodecProvider.getDefault() == savedCodecProvider)
removeTestCodecs(codec, CodecProvider.getDefault());
CodecProvider.setDefault(savedCodecProvider);
Locale.setDefault(savedLocale);

View File

@ -450,6 +450,7 @@
>
<sysproperty key="java.util.logging.config.file" value="${common-solr.dir}/testlogging.properties"/>
<sysproperty key="tests.luceneMatchVersion" value="${tests.luceneMatchVersion}"/>
<sysproperty key="tests.codecprovider" value="${tests.codecprovider}"/>
<sysproperty key="tests.codec" value="${tests.codec}"/>
<sysproperty key="tests.locale" value="${tests.locale}"/>
<sysproperty key="tests.timezone" value="${tests.timezone}"/>

View File

@ -61,6 +61,7 @@
</condition>
<property name="tests.multiplier" value="1" />
<property name="tests.codecprovider" value="random" />
<property name="tests.codec" value="randomPerField" />
<property name="tests.locale" value="random" />
<property name="tests.timezone" value="random" />

View File

@ -146,6 +146,7 @@
>
<sysproperty key="java.util.logging.config.file" value="${common-solr.dir}/testlogging.properties"/>
<sysproperty key="tests.luceneMatchVersion" value="${tests.luceneMatchVersion}"/>
<sysproperty key="tests.codecprovider" value="${tests.codecprovider}"/>
<sysproperty key="tests.codec" value="${tests.codec}"/>
<sysproperty key="tests.locale" value="${tests.locale}"/>
<sysproperty key="tests.timezone" value="${tests.timezone}"/>

View File

@ -118,6 +118,7 @@
>
<sysproperty key="java.util.logging.config.file" value="${common-solr.dir}/testlogging.properties"/>
<sysproperty key="tests.luceneMatchVersion" value="${tests.luceneMatchVersion}"/>
<sysproperty key="tests.codecprovider" value="${tests.codecprovider}"/>
<sysproperty key="tests.codec" value="${tests.codec}"/>
<sysproperty key="tests.locale" value="${tests.locale}"/>
<sysproperty key="tests.timezone" value="${tests.timezone}"/>

View File

@ -171,6 +171,7 @@
<sysproperty key="java.util.logging.config.file" value="${common-solr.dir}/testlogging.properties"/>
<sysproperty key="tests.luceneMatchVersion" value="${tests.luceneMatchVersion}"/>
<sysproperty key="tests.codec" value="${tests.codec}"/>
<sysproperty key="tests.codecprovider" value="${tests.codecprovider}"/>
<sysproperty key="tests.locale" value="${tests.locale}"/>
<sysproperty key="tests.timezone" value="${tests.timezone}"/>
<sysproperty key="tests.multiplier" value="${tests.multiplier}"/>
@ -231,6 +232,7 @@
>
<sysproperty key="java.util.logging.config.file" value="${common-solr.dir}/testlogging.properties"/>
<sysproperty key="tests.luceneMatchVersion" value="${tests.luceneMatchVersion}"/>
<sysproperty key="tests.codecprovider" value="${tests.codecprovider}"/>
<sysproperty key="tests.codec" value="${tests.codec}"/>
<sysproperty key="tests.locale" value="${tests.locale}"/>
<sysproperty key="tests.timezone" value="${tests.timezone}"/>

View File

@ -115,6 +115,7 @@
>
<sysproperty key="java.util.logging.config.file" value="${common-solr.dir}/testlogging.properties"/>
<sysproperty key="tests.luceneMatchVersion" value="${tests.luceneMatchVersion}"/>
<sysproperty key="tests.codecprovider" value="${tests.codecprovider}"/>
<sysproperty key="tests.codec" value="${tests.codec}"/>
<sysproperty key="tests.locale" value="${tests.locale}"/>
<sysproperty key="tests.timezone" value="${tests.timezone}"/>

View File

@ -114,6 +114,7 @@
>
<sysproperty key="java.util.logging.config.file" value="${common-solr.dir}/testlogging.properties"/>
<sysproperty key="tests.luceneMatchVersion" value="${tests.luceneMatchVersion}"/>
<sysproperty key="tests.codecprovider" value="${tests.codecprovider}"/>
<sysproperty key="tests.codec" value="${tests.codec}"/>
<sysproperty key="tests.locale" value="${tests.locale}"/>
<sysproperty key="tests.timezone" value="${tests.timezone}"/>