SOLR-2002: run tests under different timezones and locales

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@983495 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2010-08-09 01:25:43 +00:00
parent 63f30c694d
commit 796fd9a5a3
5 changed files with 85 additions and 3 deletions

View File

@ -57,6 +57,8 @@
<property name="threadsPerProcessor" value="1" />
<property name="random.multiplier" value="1" />
<property name="tests.codec" value="random" />
<property name="tests.locale" value="random" />
<property name="tests.timezone" value="random" />
<property name="javac.deprecation" value="off"/>
<property name="javac.debug" value="on"/>
@ -437,6 +439,10 @@
<sysproperty key="tests.verbose" value="${tests.verbose}"/>
<!-- set the codec tests should run with -->
<sysproperty key="tests.codec" value="${tests.codec}"/>
<!-- set the locale tests should run with -->
<sysproperty key="tests.locale" value="${tests.locale}"/>
<!-- set the timezone tests should run with -->
<sysproperty key="tests.timezone" value="${tests.timezone}"/>
<!-- TODO: create propertyset for test properties, so each project can have its own set -->
<sysproperty key="random.multiplier" value="${random.multiplier}"/>

View File

@ -22,10 +22,12 @@ import java.io.PrintStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Locale;
import java.util.Random;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.util.TimeZone;
import junit.framework.TestCase;
@ -73,6 +75,10 @@ public abstract class LuceneTestCase extends TestCase {
/** Gets the codec to run tests with. */
public static final String TEST_CODEC = LuceneTestCaseJ4.TEST_CODEC;
/** Gets the locale to run tests with */
static final String TEST_LOCALE = LuceneTestCaseJ4.TEST_LOCALE;
/** Gets the timezone to run tests with */
static final String TEST_TIMEZONE = LuceneTestCaseJ4.TEST_TIMEZONE;
/**
* A random multiplier which you should use when writing random tests:
@ -86,6 +92,11 @@ public abstract class LuceneTestCase extends TestCase {
private Codec codec;
private Locale locale;
private Locale savedLocale;
private TimeZone timeZone;
private TimeZone savedTimeZone;
/** Used to track if setUp and tearDown are called correctly from subclasses */
private boolean setup;
@ -125,6 +136,16 @@ public abstract class LuceneTestCase extends TestCase {
ConcurrentMergeScheduler.setTestMode();
savedBoolMaxClauseCount = BooleanQuery.getMaxClauseCount();
codec = LuceneTestCaseJ4.installTestCodecs();
savedLocale = Locale.getDefault();
locale = TEST_LOCALE.equals("random")
? LuceneTestCaseJ4.randomLocale(seedRnd)
: LuceneTestCaseJ4.localeForName(TEST_LOCALE);
Locale.setDefault(locale);
savedTimeZone = TimeZone.getDefault();
timeZone = TEST_TIMEZONE.equals("random")
? LuceneTestCaseJ4.randomTimeZone(seedRnd)
: TimeZone.getTimeZone(TEST_TIMEZONE);
TimeZone.setDefault(timeZone);
}
/**
@ -151,6 +172,8 @@ public abstract class LuceneTestCase extends TestCase {
setup = false;
BooleanQuery.setMaxClauseCount(savedBoolMaxClauseCount);
LuceneTestCaseJ4.removeTestCodecs(codec);
Locale.setDefault(savedLocale);
TimeZone.setDefault(savedTimeZone);
try {
Thread.setDefaultUncaughtExceptionHandler(savedUncaughtExceptionHandler);
@ -309,6 +332,10 @@ public abstract class LuceneTestCase extends TestCase {
super.runBare();
} catch (Throwable e) {
System.out.println("NOTE: random codec of testcase '" + getName() + "' was: " + codec);
if (TEST_LOCALE.equals("random"))
System.out.println("NOTE: random locale of testcase '" + getName() + "' was: " + locale);
if (TEST_TIMEZONE.equals("random"))
System.out.println("NOTE: random timezone of testcase '" + getName() + "' was: " + timeZone.getID());
if (seed != null) {
System.out.println("NOTE: random seed of testcase '" + getName() + "' was: " + seed);
}

View File

@ -51,10 +51,12 @@ import java.io.PrintStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Locale;
import java.util.Random;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.WeakHashMap;
import java.util.Collections;
import java.lang.reflect.Method;
@ -124,6 +126,10 @@ public class LuceneTestCaseJ4 {
// tests)
/** Gets the codec to run tests with. */
static final String TEST_CODEC = System.getProperty("tests.codec", "random");
/** Gets the locale to run tests with */
static final String TEST_LOCALE = System.getProperty("tests.locale", "random");
/** Gets the timezone to run tests with */
static final String TEST_TIMEZONE = System.getProperty("tests.timezone", "random");
/**
* A random multiplier which you should use when writing random tests:
@ -158,6 +164,11 @@ public class LuceneTestCaseJ4 {
private static String savedDefaultCodec;
private static Codec codec;
private static Locale locale;
private static Locale savedLocale;
private static TimeZone timeZone;
private static TimeZone savedTimeZone;
private static final String[] TEST_CODECS = new String[] {"MockSep", "MockFixedIntBlock", "MockVariableIntBlock"};
private static void swapCodec(Codec c) {
@ -231,11 +242,19 @@ public class LuceneTestCaseJ4 {
@BeforeClass
public static void beforeClassLuceneTestCaseJ4() {
codec = installTestCodecs();
savedLocale = Locale.getDefault();
locale = TEST_LOCALE.equals("random") ? randomLocale(seedRnd) : localeForName(TEST_LOCALE);
Locale.setDefault(locale);
savedTimeZone = TimeZone.getDefault();
timeZone = TEST_TIMEZONE.equals("random") ? randomTimeZone(seedRnd) : TimeZone.getTimeZone(TEST_TIMEZONE);
TimeZone.setDefault(timeZone);
}
@AfterClass
public static void afterClassLuceneTestCaseJ4() {
removeTestCodecs(codec);
Locale.setDefault(savedLocale);
TimeZone.setDefault(savedTimeZone);
}
// This is how we get control when errors occur.
@ -514,6 +533,29 @@ public class LuceneTestCaseJ4 {
return c;
}
/** return a random Locale from the available locales on the system */
public static Locale randomLocale(Random random) {
Locale locales[] = Locale.getAvailableLocales();
return locales[random.nextInt(locales.length)];
}
/** return a random TimeZone from the available timezones on the system */
public static TimeZone randomTimeZone(Random random) {
String tzIds[] = TimeZone.getAvailableIDs();
return TimeZone.getTimeZone(tzIds[random.nextInt(tzIds.length)]);
}
/** return a Locale object equivalent to its programmatic name */
public static Locale localeForName(String localeName) {
String elements[] = localeName.split("\\_");
switch(elements.length) {
case 3: return new Locale(elements[0], elements[1], elements[2]);
case 2: return new Locale(elements[0], elements[1]);
case 1: return new Locale(elements[0]);
default: throw new IllegalArgumentException("Invalid Locale: " + localeName);
}
}
public String getName() {
return this.name;
}
@ -538,7 +580,10 @@ public class LuceneTestCaseJ4 {
}
System.out.println("NOTE: random codec of testcase '" + getName() + "' was: " + codec);
if (TEST_LOCALE.equals("random"))
System.out.println("NOTE: random locale of testcase '" + getName() + "' was: " + locale);
if (TEST_TIMEZONE.equals("random"))
System.out.println("NOTE: random timezone of testcase '" + getName() + "' was: " + timeZone.getID());
if (seed != null) {
System.out.println("NOTE: random seed of testcase '" + getName() + "' was: " + seed);
}

View File

@ -441,6 +441,8 @@
<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.locale" value="${tests.locale}"/>
<sysproperty key="tests.timezone" value="${tests.timezone}"/>
<sysproperty key="jetty.insecurerandom" value="1"/>
<sysproperty key="tempDir" file="@{tempDir}/@{threadNum}"/>
<jvmarg line="${dir.prop}"/>

View File

@ -45,6 +45,8 @@
<property name="threadsPerProcessor" value="2"/>
<property name="tests.codec" value="random" />
<property name="tests.locale" value="random" />
<property name="tests.timezone" value="random" />
<!-- Example directory -->
<property name="example" value="${common-solr.dir}/example" />