From 1cfb93664998fb3f4b22fc66d749a6e1d7648824 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Mon, 13 Dec 2010 19:12:03 +0000 Subject: [PATCH] make test more evil git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1045315 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/index/TestIndexReaderReopen.java | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java b/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java index 176d1be57b6..ad9b3b30686 100644 --- a/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java +++ b/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java @@ -22,28 +22,28 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; - -import java.util.List; -import java.util.Random; -import java.util.Map; import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Random; import java.util.Set; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; import org.apache.lucene.document.Field.Index; import org.apache.lucene.document.Field.Store; +import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TermQuery; -import org.apache.lucene.store.Directory; import org.apache.lucene.store.AlreadyClosedException; -import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.store.Directory; import org.apache.lucene.util.BitVector; import org.apache.lucene.util.Bits; +import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; public class TestIndexReaderReopen extends LuceneTestCase { @@ -750,7 +750,7 @@ public class TestIndexReaderReopen extends LuceneTestCase { ReaderThreadTask task; - if (i < 4 ||( i >=10 && i < 14) || i > 18) { + if (i < 4 || (i >=10 && i < 14) || i > 18) { task = new ReaderThreadTask() { @Override @@ -768,7 +768,6 @@ public class TestIndexReaderReopen extends LuceneTestCase { // not synchronized IndexReader refreshed = r.reopen(); - IndexSearcher searcher = new IndexSearcher(refreshed); ScoreDoc[] hits = searcher.search( new TermQuery(new Term("field1", "a" + rnd.nextInt(refreshed.maxDoc()))), @@ -777,19 +776,12 @@ public class TestIndexReaderReopen extends LuceneTestCase { searcher.doc(hits[0].doc); } - // r might have changed because this is not a - // synchronized method. However we don't want - // to make it synchronized to test - // thread-safety of IndexReader.close(). - // That's why we add refreshed also to - // readersToClose, because double closing is fine if (refreshed != r) { refreshed.close(); } - readersToClose.add(refreshed); } synchronized(this) { - wait(1000); + wait(_TestUtil.nextInt(random, 1, 100)); } } } @@ -807,12 +799,10 @@ public class TestIndexReaderReopen extends LuceneTestCase { } synchronized(this) { - wait(100); + wait(_TestUtil.nextInt(random, 1, 100)); } } - } - }; } @@ -869,7 +859,7 @@ public class TestIndexReaderReopen extends LuceneTestCase { } private abstract static class ReaderThreadTask { - protected boolean stopped; + protected volatile boolean stopped; public void stop() { this.stopped = true; }