improve the random handling in these tests

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1049144 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2010-12-14 16:24:16 +00:00
parent 1d1c5ec67d
commit 94848afc65
5 changed files with 14 additions and 15 deletions

View File

@ -50,7 +50,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
IndexWriter writer;
final Random r = new java.util.Random(47);
final Random r = new Random(random.nextLong());
volatile Throwable failure;
public IndexerThread(int i, IndexWriter writer) {
@ -128,7 +128,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
ThreadLocal<Thread> doFail = new ThreadLocal<Thread>();
private class MockIndexWriter extends IndexWriter {
Random r = new java.util.Random(17);
Random r = new Random(random.nextLong());
public MockIndexWriter(Directory dir, IndexWriterConfig conf) throws IOException {
super(dir, conf);

View File

@ -837,10 +837,11 @@ public class TestIndexWriterReader extends LuceneTestCase {
final Thread[] threads = new Thread[NUM_THREAD];
for(int i=0;i<NUM_THREAD;i++) {
threads[i] = new Thread() {
final Random r = new Random(random.nextLong());
@Override
public void run() {
int count = 0;
final Random r = new Random();
do {
try {
for(int docUpto=0;docUpto<10;docUpto++) {

View File

@ -26,7 +26,6 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
public class TestNRTReaderWithThreads extends LuceneTestCase {
Random random = new Random();
AtomicInteger seq = new AtomicInteger(1);
public void testIndexing() throws Exception {
@ -77,7 +76,8 @@ public class TestNRTReaderWithThreads extends LuceneTestCase {
int delCount = 0;
int addCount = 0;
int type;
final Random r = new Random(random.nextLong());
public RunThread(int type, IndexWriter writer) {
this.type = type;
this.writer = writer;
@ -97,7 +97,7 @@ public class TestNRTReaderWithThreads extends LuceneTestCase {
// we may or may not delete because the term may not exist,
// however we're opening and closing the reader rapidly
IndexReader reader = writer.getReader();
int id = random.nextInt(seq.intValue());
int id = r.nextInt(seq.intValue());
Term term = new Term("id", Integer.toString(id));
int count = TestIndexWriterReader.count(term, reader);
writer.deleteDocuments(term);

View File

@ -38,7 +38,7 @@ import org.apache.lucene.util.Version;
public class TestPerSegmentDeletes extends LuceneTestCase {
public void testDeletes1() throws Exception {
//IndexWriter.debug2 = System.out;
Directory dir = new MockDirectoryWrapper(new Random(), new RAMDirectory());
Directory dir = new MockDirectoryWrapper(new Random(random.nextLong()), new RAMDirectory());
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_CURRENT,
new MockAnalyzer());
iwc.setMergeScheduler(new SerialMergeScheduler());

View File

@ -29,6 +29,11 @@ public class TestSetOnce extends LuceneTestCase {
private static final class SetOnceThread extends Thread {
SetOnce<Integer> set;
boolean success = false;
final Random RAND;
public SetOnceThread(Random random) {
RAND = new Random(random.nextLong());
}
@Override
public void run() {
@ -46,8 +51,6 @@ public class TestSetOnce extends LuceneTestCase {
}
}
private static final Random RAND = new Random();
@Test
public void testEmptyCtor() throws Exception {
SetOnce<Integer> set = new SetOnce<Integer>();
@ -71,15 +74,10 @@ public class TestSetOnce extends LuceneTestCase {
@Test
public void testSetMultiThreaded() throws Exception {
long seed = RAND.nextLong();
RAND.setSeed(seed);
if (VERBOSE) {
System.out.println("testSetMultiThreaded: seed=" + seed);
}
final SetOnce<Integer> set = new SetOnce<Integer>();
SetOnceThread[] threads = new SetOnceThread[10];
for (int i = 0; i < threads.length; i++) {
threads[i] = new SetOnceThread();
threads[i] = new SetOnceThread(random);
threads[i].setName("t-" + (i+1));
threads[i].set = set;
}