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 2011/08/08 13:37:02 UTC

svn commit: r1154927 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/backwards/ lucene/backwards/src/test-framework/ lucene/backwards/src/test/ lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java solr/

Author: rmuir
Date: Mon Aug  8 11:37:01 2011
New Revision: 1154927

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

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test-framework/   (props changed)
    lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
    lucene/dev/branches/branch_3x/solr/   (props changed)

Modified: lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java?rev=1154927&r1=1154926&r2=1154927&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java Mon Aug  8 11:37:01 2011
@@ -199,24 +199,24 @@ public abstract class LuceneTestCase ext
   
   protected static Map<MockDirectoryWrapper,StackTraceElement[]> stores;
   
-  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));
     }
   }
 
@@ -226,7 +226,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;
   }
@@ -236,6 +236,7 @@ public abstract class LuceneTestCase ext
 
   @BeforeClass
   public static void beforeClassLuceneTestCaseJ4() {
+    initRandom();
     state = State.INITIAL;
     tempDirs.clear();
     stores = Collections.synchronizedMap(new IdentityHashMap<MockDirectoryWrapper,StackTraceElement[]>());
@@ -401,7 +402,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));
@@ -1184,7 +1185,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());
   }
   
@@ -1239,14 +1240,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>();