lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1154926 - /lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
Date Mon, 08 Aug 2011 11:35:37 GMT
Author: rmuir
Date: Mon Aug  8 11:35:37 2011
New Revision: 1154926

URL: http://svn.apache.org/viewvc?rev=1154926&view=rev
Log:
LUCENE-3362: use a seed for the test runner, so tests work better from IDEs/maven

Modified:
    lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java

Modified: lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java?rev=1154926&r1=1154925&r2=1154926&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
(original)
+++ lucene/dev/trunk/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
Mon Aug  8 11:35:37 2011
@@ -322,24 +322,24 @@ public abstract class LuceneTestCase ext
     }
   }
 
-  private static class TwoLongs {
-    public final long l1, l2;
+  private static class ThreeLongs {
+    public final long l1, l2, l3;
 
-    public TwoLongs(long l1, long l2) {
+    public ThreeLongs(long l1, long l2, long l3) {
       this.l1 = l1;
       this.l2 = l2;
+      this.l3 = l3;
     }
 
     @Override
     public String toString() {
-      return l1 + ":" + l2;
+      return Long.toString(l1, 16) + ":" + Long.toString(l2, 16) + ":" + Long.toString(l3,
16);
     }
 
-    public static TwoLongs fromString(String s) {
-      final int i = s.indexOf(':');
-      assert i != -1;
-      return new TwoLongs(Long.parseLong(s.substring(0, i)),
-                          Long.parseLong(s.substring(1+i)));
+    public static ThreeLongs fromString(String s) {
+      String parts[] = s.split(":");
+      assert parts.length == 3;
+      return new ThreeLongs(Long.parseLong(parts[0], 16), Long.parseLong(parts[1], 16), Long.parseLong(parts[2],
16));
     }
   }
 
@@ -349,7 +349,7 @@ public abstract class LuceneTestCase ext
 
   private static void initRandom() {
     assert !random.initialized;
-    staticSeed = "random".equals(TEST_SEED) ? seedRand.nextLong() : TwoLongs.fromString(TEST_SEED).l1;
+    staticSeed = "random".equals(TEST_SEED) ? seedRand.nextLong() : ThreeLongs.fromString(TEST_SEED).l1;
     random.setSeed(staticSeed);
     random.initialized = true;
   }
@@ -359,6 +359,7 @@ public abstract class LuceneTestCase ext
 
   @BeforeClass
   public static void beforeClassLuceneTestCaseJ4() {
+    initRandom();
     state = State.INITIAL;
     tempDirs.clear();
     stores = Collections.synchronizedMap(new IdentityHashMap<MockDirectoryWrapper,StackTraceElement[]>());
@@ -566,7 +567,7 @@ public abstract class LuceneTestCase ext
 
   @Before
   public void setUp() throws Exception {
-    seed = "random".equals(TEST_SEED) ? seedRand.nextLong() : TwoLongs.fromString(TEST_SEED).l2;
+    seed = "random".equals(TEST_SEED) ? seedRand.nextLong() : ThreeLongs.fromString(TEST_SEED).l2;
     random.setSeed(seed);
     if (!testsFailed) {
       assertTrue("ensure your tearDown() calls super.tearDown()!!!", (state == State.INITIAL
|| state == State.TEARDOWN));
@@ -1344,7 +1345,7 @@ public abstract class LuceneTestCase ext
   // We get here from InterceptTestCaseEvents on the 'failed' event....
   public void reportAdditionalFailureInfo() {
     System.err.println("NOTE: reproduce with: ant test -Dtestcase=" + getClass().getSimpleName()
-        + " -Dtestmethod=" + getName() + " -Dtests.seed=" + new TwoLongs(staticSeed, seed)
+        + " -Dtestmethod=" + getName() + " -Dtests.seed=" + new ThreeLongs(staticSeed, seed,
LuceneTestCaseRunner.runnerSeed)
         + reproduceWithExtraParams());
   }
 
@@ -1426,14 +1427,17 @@ public abstract class LuceneTestCase ext
   /** optionally filters the tests to be run by TEST_METHOD */
   public static class LuceneTestCaseRunner extends BlockJUnit4ClassRunner {
     private List<FrameworkMethod> testMethods;
+    private static final long runnerSeed;
+    static {
+      runnerSeed = "random".equals(TEST_SEED) ? seedRand.nextLong() : ThreeLongs.fromString(TEST_SEED).l3;
+    }
 
     @Override
     protected List<FrameworkMethod> computeTestMethods() {
       if (testMethods != null)
         return testMethods;
       
-      initRandom();
-      Random r = new Random(random.nextLong());
+      Random r = new Random(runnerSeed);
 
       testClassesRun.add(getTestClass().getJavaClass().getSimpleName());
       testMethods = new ArrayList<FrameworkMethod>();



Mime
View raw message