You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2010/08/09 03:25:43 UTC

svn commit: r983495 - in /lucene/dev/trunk: lucene/common-build.xml lucene/src/test/org/apache/lucene/util/LuceneTestCase.java lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java solr/build.xml solr/common-build.xml

Author: rmuir
Date: Mon Aug  9 01:25:43 2010
New Revision: 983495

URL: http://svn.apache.org/viewvc?rev=983495&view=rev
Log:
SOLR-2002: run tests under different timezones and locales

Modified:
    lucene/dev/trunk/lucene/common-build.xml
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java
    lucene/dev/trunk/solr/build.xml
    lucene/dev/trunk/solr/common-build.xml

Modified: lucene/dev/trunk/lucene/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/common-build.xml?rev=983495&r1=983494&r2=983495&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/common-build.xml (original)
+++ lucene/dev/trunk/lucene/common-build.xml Mon Aug  9 01:25:43 2010
@@ -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}"/>

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java?rev=983495&r1=983494&r2=983495&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java Mon Aug  9 01:25:43 2010
@@ -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,7 +75,11 @@ public abstract class LuceneTestCase ext
 
   /** 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:
    * multiply it by the number of iterations
@@ -86,6 +92,11 @@ public abstract class LuceneTestCase ext
   
   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 ext
     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 ext
     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 ext
       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);
       }

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java?rev=983495&r1=983494&r2=983495&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java Mon Aug  9 01:25:43 2010
@@ -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,7 +126,11 @@ 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:
    * multiply it by the number of iterations
@@ -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);
     }

Modified: lucene/dev/trunk/solr/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/build.xml?rev=983495&r1=983494&r2=983495&view=diff
==============================================================================
--- lucene/dev/trunk/solr/build.xml (original)
+++ lucene/dev/trunk/solr/build.xml Mon Aug  9 01:25:43 2010
@@ -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}"/>

Modified: lucene/dev/trunk/solr/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/common-build.xml?rev=983495&r1=983494&r2=983495&view=diff
==============================================================================
--- lucene/dev/trunk/solr/common-build.xml (original)
+++ lucene/dev/trunk/solr/common-build.xml Mon Aug  9 01:25:43 2010
@@ -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" />