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/07/12 20:19:56 UTC
svn commit: r1145702 - 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/
solr/src/common/
Author: rmuir
Date: Tue Jul 12 18:19:56 2011
New Revision: 1145702
URL: http://svn.apache.org/viewvc?rev=1145702&view=rev
Log:
add warnings to tests that arent really randomized
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)
lucene/dev/branches/branch_3x/solr/src/common/ (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=1145702&r1=1145701&r2=1145702&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 Tue Jul 12 18:19:56 2011
@@ -229,6 +229,7 @@ public abstract class LuceneTestCase ext
state = State.INITIAL;
staticSeed = "random".equals(TEST_SEED) ? seedRand.nextLong() : TwoLongs.fromString(TEST_SEED).l1;
random.setSeed(staticSeed);
+ random.initialized = true;
tempDirs.clear();
stores = Collections.synchronizedMap(new IdentityHashMap<MockDirectoryWrapper,StackTraceElement[]>());
// enable this by default, for IDE consistency with ant tests (as its the default from ant)
@@ -329,6 +330,8 @@ public abstract class LuceneTestCase ext
}
}
}
+ random.setSeed(0L);
+ random.initialized = false;
}
private static boolean testsFailed; /* true if any tests failed */
@@ -1179,7 +1182,26 @@ public abstract class LuceneTestCase ext
private long seed;
private static final Random seedRand = new Random();
- protected static final Random random = new Random(0);
+ protected static final SmartRandom random = new SmartRandom(0);
+
+ public static class SmartRandom extends Random {
+ boolean initialized;
+
+ SmartRandom(long seed) {
+ super(seed);
+ }
+
+ @Override
+ protected int next(int bits) {
+ if (!initialized) {
+ System.err.println("!!! WARNING: test is using random from static initializer !!!");
+ Thread.dumpStack();
+ // I wish, but it causes JRE crashes
+ // throw new IllegalStateException("you cannot use this random from a static initializer in your test");
+ }
+ return super.next(bits);
+ }
+ }
private String name = "<unknown>";