From 2fe80c49e6f50f2cd0d43a5318cbe5482441424d Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 23 Jul 2010 12:47:25 +0000 Subject: [PATCH] warn if you fix a random seed (so we dont leave the test de-randomized) git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@967080 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/test/org/apache/lucene/util/LuceneTestCase.java | 4 +++- .../test/org/apache/lucene/util/LuceneTestCaseJ4.java | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java index 8a7bfff97cb..e214f388663 100644 --- a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java +++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java @@ -247,7 +247,8 @@ public abstract class LuceneTestCase extends TestCase { if (seed != null) { throw new IllegalStateException("please call LuceneTestCase.newRandom only once per test"); } - return newRandom(seedRnd.nextLong()); + this.seed = Long.valueOf(seedRnd.nextLong()); + return new Random(seed); } /** @@ -259,6 +260,7 @@ public abstract class LuceneTestCase extends TestCase { if (this.seed != null) { throw new IllegalStateException("please call LuceneTestCase.newRandom only once per test"); } + System.out.println("WARNING: random seed of testcase '" + getName() + "' is fixed to: " + seed); this.seed = Long.valueOf(seed); return new Random(seed); } diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java index dedc0de579d..3fa12efd2cb 100644 --- a/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java +++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java @@ -323,7 +323,8 @@ public class LuceneTestCaseJ4 { if (seed != null) { throw new IllegalStateException("please call LuceneTestCaseJ4.newRandom only once per test"); } - return newRandom(seedRnd.nextLong()); + this.seed = Long.valueOf(seedRnd.nextLong()); + return new Random(seed); } /** @@ -335,6 +336,7 @@ public class LuceneTestCaseJ4 { if (this.seed != null) { throw new IllegalStateException("please call LuceneTestCaseJ4.newRandom only once per test"); } + System.out.println("WARNING: random seed of testcase '" + getName() + "' is fixed to: " + seed); this.seed = Long.valueOf(seed); return new Random(seed); } @@ -350,7 +352,9 @@ public class LuceneTestCaseJ4 { * . */ public static Random newStaticRandom(Class clazz) { - return newStaticRandom(clazz, seedRnd.nextLong()); + Long seed = seedRnd.nextLong(); + staticSeeds.put(clazz, seed); + return new Random(seed); } /** @@ -361,6 +365,7 @@ public class LuceneTestCaseJ4 { */ public static Random newStaticRandom(Class clazz, long seed) { staticSeeds.put(clazz, Long.valueOf(seed)); + System.out.println("WARNING: random static seed of testclass '" + clazz + "' is fixed to: " + seed); return new Random(seed); }