Index: lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java (revision 996278) +++ lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java (working copy) @@ -25,9 +25,16 @@ import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; + import java.io.IOException; import java.text.Collator; import java.util.Locale; +import java.util.Random; import junit.framework.Assert; @@ -36,36 +43,37 @@ /** threshold for comparing floats */ public static final float SCORE_COMP_THRESH = 1e-6f; - Directory small; - IndexReader reader; + static Directory small; + static IndexReader reader; void assertEquals(String m, float e, float a) { - assertEquals(m, e, a, SCORE_COMP_THRESH); + Assert.assertEquals(m, e, a, SCORE_COMP_THRESH); } static public void assertEquals(String m, int e, int a) { Assert.assertEquals(m, e, a); } - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeClass + public static void beforeClass() throws Exception { String[] data = new String[] { "A 1 2 3 4 5 6", "Z 4 5 6", null, "B 2 4 5 6", "Y 3 5 6", null, "C 3 6", "X 4 5 6" }; - small = newDirectory(); + Random random = newStaticRandom(TestMultiTermConstantScore.class); + + small = newDirectory(random); RandomIndexWriter writer = new RandomIndexWriter(random, small, new MockAnalyzer(MockTokenizer.WHITESPACE, false)); for (int i = 0; i < data.length; i++) { Document doc = new Document(); - doc.add(newField("id", String.valueOf(i), Field.Store.YES, + doc.add(newField(random, "id", String.valueOf(i), Field.Store.YES, Field.Index.NOT_ANALYZED));// Field.Keyword("id",String.valueOf(i))); doc - .add(newField("all", "all", Field.Store.YES, + .add(newField(random, "all", "all", Field.Store.YES, Field.Index.NOT_ANALYZED));// Field.Keyword("all","all")); if (null != data[i]) { - doc.add(newField("data", data[i], Field.Store.YES, + doc.add(newField(random, "data", data[i], Field.Store.YES, Field.Index.ANALYZED));// Field.Text("data",data[i])); } writer.addDocument(doc); @@ -75,11 +83,12 @@ writer.close(); } - @Override - protected void tearDown() throws Exception { + @AfterClass + public static void afterClass() throws Exception { reader.close(); small.close(); - super.tearDown(); + reader = null; + small = null; } /** macro for readability */ @@ -117,6 +126,7 @@ return query; } + @Test public void testBasics() throws IOException { QueryUtils.check(csrq("data", "1", "6", T, T)); QueryUtils.check(csrq("data", "A", "Z", T, T)); @@ -132,6 +142,7 @@ "data", "pr*t?j"))); } + @Test public void testBasicsRngCollating() throws IOException { Collator c = Collator.getInstance(Locale.ENGLISH); QueryUtils.check(csrq("data", "1", "6", T, T, c)); @@ -140,6 +151,7 @@ "Z", T, T, c)); } + @Test public void testEqualScores() throws IOException { // NOTE: uses index build in *this* setUp @@ -168,6 +180,7 @@ } + @Test public void testBoost() throws IOException { // NOTE: uses index build in *this* setUp @@ -210,8 +223,8 @@ bq.add(q2, BooleanClause.Occur.SHOULD); ScoreDoc[] hits = search.search(bq, null, 1000).scoreDocs; - assertEquals(1, hits[0].doc); - assertEquals(0, hits[1].doc); + Assert.assertEquals(1, hits[0].doc); + Assert.assertEquals(0, hits[1].doc); assertTrue(hits[0].score > hits[1].score); q1 = csrq("data", "A", "A", T, T, MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE); // matches document #0 @@ -222,8 +235,8 @@ bq.add(q2, BooleanClause.Occur.SHOULD); hits = search.search(bq, null, 1000).scoreDocs; - assertEquals(1, hits[0].doc); - assertEquals(0, hits[1].doc); + Assert.assertEquals(1, hits[0].doc); + Assert.assertEquals(0, hits[1].doc); assertTrue(hits[0].score > hits[1].score); q1 = csrq("data", "A", "A", T, T); // matches document #0 @@ -234,11 +247,12 @@ bq.add(q2, BooleanClause.Occur.SHOULD); hits = search.search(bq, null, 1000).scoreDocs; - assertEquals(0, hits[0].doc); - assertEquals(1, hits[1].doc); + Assert.assertEquals(0, hits[0].doc); + Assert.assertEquals(1, hits[1].doc); assertTrue(hits[0].score > hits[1].score); } + @Test public void testBooleanOrderUnAffected() throws IOException { // NOTE: uses index build in *this* setUp @@ -269,6 +283,7 @@ } + @Test public void testRangeQueryId() throws IOException { // NOTE: uses index build in *super* setUp @@ -396,6 +411,7 @@ assertEquals("med,med,T,T", 1, result.length); } + @Test public void testRangeQueryIdCollating() throws IOException { // NOTE: uses index build in *super* setUp @@ -479,6 +495,7 @@ assertEquals("med,med,T,T,c", 1, result.length); } + @Test public void testRangeQueryRand() throws IOException { // NOTE: uses index build in *super* setUp @@ -541,6 +558,7 @@ } + @Test public void testRangeQueryRandCollating() throws IOException { // NOTE: uses index build in *super* setUp @@ -605,6 +623,7 @@ assertEquals("max,nul,T,T,c", 1, result.length); } + @Test public void testFarsi() throws Exception { /* build an index */ @@ -645,6 +664,7 @@ farsiIndex.close(); } + @Test public void testDanish() throws Exception { /* build an index */ Index: lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java (revision 996278) +++ lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java (working copy) @@ -22,6 +22,7 @@ import java.text.NumberFormat; import java.util.Locale; +import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexReader; @@ -29,6 +30,7 @@ import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; /** * Create an index with terms from 0000-9999. @@ -44,7 +46,9 @@ protected void setUp() throws Exception { super.setUp(); dir = newDirectory(); - RandomIndexWriter writer = new RandomIndexWriter(random, dir); + RandomIndexWriter writer = new RandomIndexWriter(random, dir, + newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()) + .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); Document doc = new Document(); Field field = newField("field", "", Field.Store.NO, Field.Index.ANALYZED); Index: lucene/src/test/org/apache/lucene/search/spans/TestBasics.java =================================================================== --- lucene/src/test/org/apache/lucene/search/spans/TestBasics.java (revision 996278) +++ lucene/src/test/org/apache/lucene/search/spans/TestBasics.java (working copy) @@ -18,6 +18,7 @@ */ import java.io.IOException; +import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; @@ -37,8 +38,14 @@ import org.apache.lucene.search.TermQuery; import org.apache.lucene.store.Directory; import org.apache.lucene.util.English; -import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.LuceneTestCaseJ4; +import org.apache.lucene.util._TestUtil; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + /** * Tests basic search capabilities. * @@ -51,21 +58,22 @@ * testing of the indexing and search code. * */ -public class TestBasics extends LuceneTestCase { - private IndexSearcher searcher; - private IndexReader reader; - private Directory directory; +public class TestBasics extends LuceneTestCaseJ4 { + private static IndexSearcher searcher; + private static IndexReader reader; + private static Directory directory; - @Override - protected void setUp() throws Exception { - super.setUp(); - directory = newDirectory(); + @BeforeClass + public static void beforeClass() throws Exception { + Random random = newStaticRandom(TestBasics.class); + directory = newDirectory(random); RandomIndexWriter writer = new RandomIndexWriter(random, directory, - new MockAnalyzer(MockTokenizer.SIMPLE, true)); + newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true)) + .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); //writer.infoStream = System.out; for (int i = 0; i < 1000; i++) { Document doc = new Document(); - doc.add(newField("field", English.intToEnglish(i), Field.Store.YES, Field.Index.ANALYZED)); + doc.add(newField(random, "field", English.intToEnglish(i), Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(doc); } reader = writer.getReader(); @@ -73,15 +81,17 @@ writer.close(); } - @Override - protected void tearDown() throws Exception { + @AfterClass + public static void afterClass() throws Exception { searcher.close(); reader.close(); directory.close(); - super.tearDown(); + searcher = null; + reader = null; + directory = null; } - + @Test public void testTerm() throws Exception { Query query = new TermQuery(new Term("field", "seventy")); checkHits(query, new int[] @@ -94,11 +104,13 @@ 876, 877, 878, 879, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979}); } + @Test public void testTerm2() throws Exception { Query query = new TermQuery(new Term("field", "seventish")); checkHits(query, new int[] {}); } + @Test public void testPhrase() throws Exception { PhraseQuery query = new PhraseQuery(); query.add(new Term("field", "seventy")); @@ -107,6 +119,7 @@ {77, 177, 277, 377, 477, 577, 677, 777, 877, 977}); } + @Test public void testPhrase2() throws Exception { PhraseQuery query = new PhraseQuery(); query.add(new Term("field", "seventish")); @@ -114,6 +127,7 @@ checkHits(query, new int[] {}); } + @Test public void testBoolean() throws Exception { BooleanQuery query = new BooleanQuery(); query.add(new TermQuery(new Term("field", "seventy")), BooleanClause.Occur.MUST); @@ -123,6 +137,7 @@ 776, 778, 779, 877, 977}); } + @Test public void testBoolean2() throws Exception { BooleanQuery query = new BooleanQuery(); query.add(new TermQuery(new Term("field", "sevento")), BooleanClause.Occur.MUST); @@ -130,6 +145,7 @@ checkHits(query, new int[] {}); } + @Test public void testSpanNearExact() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "seventy")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "seven")); @@ -146,6 +162,7 @@ QueryUtils.checkUnequal(term1,term2); } + @Test public void testSpanNearUnordered() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "nine")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "six")); @@ -157,6 +174,7 @@ 906, 926, 936, 946, 956, 966, 976, 986, 996}); } + @Test public void testSpanNearOrdered() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "nine")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "six")); @@ -166,6 +184,7 @@ {906, 926, 936, 946, 956, 966, 976, 986, 996}); } + @Test public void testSpanNot() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one")); @@ -181,6 +200,7 @@ assertTrue(searcher.explain(query, 891).getValue() > 0.0f); } + @Test public void testSpanWithMultipleNotSingle() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one")); @@ -199,6 +219,7 @@ assertTrue(searcher.explain(query, 891).getValue() > 0.0f); } + @Test public void testSpanWithMultipleNotMany() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one")); @@ -218,7 +239,8 @@ assertTrue(searcher.explain(query, 801).getValue() > 0.0f); assertTrue(searcher.explain(query, 891).getValue() > 0.0f); } - + + @Test public void testNpeInSpanNearWithSpanNot() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one")); @@ -238,7 +260,7 @@ assertTrue(searcher.explain(query, 891).getValue() > 0.0f); } - + @Test public void testNpeInSpanNearInSpanFirstInSpanNot() throws Exception { int n = 5; SpanTermQuery hun = new SpanTermQuery(new Term("field", "hundred")); @@ -255,6 +277,7 @@ } + @Test public void testSpanFirst() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "five")); SpanFirstQuery query = new SpanFirstQuery(term1, 1); @@ -274,6 +297,7 @@ } + @Test public void testSpanOr() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "thirty")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "three")); @@ -294,6 +318,7 @@ assertTrue(searcher.explain(query, 947).getValue() > 0.0f); } + @Test public void testSpanExactNested() throws Exception { SpanTermQuery term1 = new SpanTermQuery(new Term("field", "three")); SpanTermQuery term2 = new SpanTermQuery(new Term("field", "hundred")); @@ -312,6 +337,7 @@ assertTrue(searcher.explain(query, 333).getValue() > 0.0f); } + @Test public void testSpanNearOr() throws Exception { SpanTermQuery t1 = new SpanTermQuery(new Term("field","six")); @@ -333,6 +359,7 @@ 756, 757, 766, 767, 776, 777, 786, 787, 796, 797}); } + @Test public void testSpanComplex1() throws Exception { SpanTermQuery t1 = new SpanTermQuery(new Term("field","six")); @@ -359,6 +386,7 @@ 756, 757, 766, 767, 776, 777, 786, 787, 796, 797}); } + @Test public void testSpansSkipTo() throws Exception { SpanTermQuery t1 = new SpanTermQuery(new Term("field", "seventy")); SpanTermQuery t2 = new SpanTermQuery(new Term("field", "seventy")); Index: lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java (revision 996278) +++ lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java (working copy) @@ -21,6 +21,7 @@ import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; +import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.NumericField; @@ -28,6 +29,7 @@ import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.store.Directory; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; public class TestMultiValuedNumericRangeQuery extends LuceneTestCase { @@ -38,7 +40,9 @@ */ public void testMultiValuedNRQ() throws Exception { Directory directory = newDirectory(); - RandomIndexWriter writer = new RandomIndexWriter(random, directory); + RandomIndexWriter writer = new RandomIndexWriter(random, directory, + newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()) + .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); DecimalFormat format = new DecimalFormat("00000000000", new DecimalFormatSymbols(Locale.US)); Index: lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java =================================================================== --- lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java (revision 996278) +++ lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java (working copy) @@ -20,7 +20,8 @@ import java.io.IOException; import java.util.Random; -import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.LuceneTestCaseJ4; +import org.apache.lucene.util._TestUtil; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -28,8 +29,12 @@ import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.store.Directory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; -public class BaseTestRangeFilter extends LuceneTestCase { +public class BaseTestRangeFilter extends LuceneTestCaseJ4 { public static final boolean F = false; public static final boolean T = true; @@ -40,7 +45,7 @@ * one which can't have negative random integers, for testing collated ranges, * and the other which can have negative random integers, for all other tests. */ - class TestIndex { + static class TestIndex { int maxR; int minR; boolean allowNegativeRandomInts; @@ -51,19 +56,19 @@ this.maxR = maxR; this.allowNegativeRandomInts = allowNegativeRandomInts; try { - index = newDirectory(); + index = newDirectory(random); } catch (IOException e) { throw new RuntimeException(e); } } } - IndexReader signedIndexReader; - IndexReader unsignedIndexReader; + static IndexReader signedIndexReader; + static IndexReader unsignedIndexReader; - TestIndex signedIndexDir; - TestIndex unsignedIndexDir; + static TestIndex signedIndexDir; + static TestIndex unsignedIndexDir; - int minId = 0; - int maxId = 10000; + static int minId = 0; + static int maxId = 10000; static final int intLength = Integer.toString(Integer.MAX_VALUE).length(); @@ -86,33 +91,44 @@ return b.toString(); } - - protected void setUp() throws Exception { - super.setUp(); + + @BeforeClass + public static void beforeClassBaseTestRangeFilter() throws Exception { + Random random = newStaticRandom(BaseTestRangeFilter.class); signedIndexDir = new TestIndex(random, Integer.MAX_VALUE, Integer.MIN_VALUE, true); unsignedIndexDir = new TestIndex(random, Integer.MAX_VALUE, 0, false); signedIndexReader = build(random, signedIndexDir); unsignedIndexReader = build(random, unsignedIndexDir); } - protected void tearDown() throws Exception { + @AfterClass + public static void afterClassBaseTestRangeFilter() throws Exception { signedIndexReader.close(); unsignedIndexReader.close(); signedIndexDir.index.close(); unsignedIndexDir.index.close(); - super.tearDown(); + signedIndexReader = null; + unsignedIndexReader = null; + signedIndexDir = null; + unsignedIndexDir = null; } - private IndexReader build(Random random, TestIndex index) throws IOException { + private static IndexReader build(Random random, TestIndex index) throws IOException { /* build an index */ RandomIndexWriter writer = new RandomIndexWriter(random, index.index, - newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer()) - .setOpenMode(OpenMode.CREATE)); + newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()) + .setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); + Document doc = new Document(); + Field idField = newField(random, "id", "", Field.Store.YES, Field.Index.NOT_ANALYZED); + Field randField = newField(random, "rand", "", Field.Store.YES, Field.Index.NOT_ANALYZED); + Field bodyField = newField(random, "body", "", Field.Store.YES, Field.Index.NOT_ANALYZED); + doc.add(idField); + doc.add(randField); + doc.add(bodyField); + for (int d = minId; d <= maxId; d++) { - Document doc = new Document(); - doc.add(newField("id", pad(d), Field.Store.YES, - Field.Index.NOT_ANALYZED)); + idField.setValue(pad(d)); int r = index.allowNegativeRandomInts ? random.nextInt() : random .nextInt(Integer.MAX_VALUE); if (index.maxR < r) { @@ -121,10 +137,8 @@ if (r < index.minR) { index.minR = r; } - doc.add(newField("rand", pad(r), Field.Store.YES, - Field.Index.NOT_ANALYZED)); - doc.add(newField("body", "body", Field.Store.YES, - Field.Index.NOT_ANALYZED)); + randField.setValue(pad(r)); + bodyField.setValue("body"); writer.addDocument(doc); } @@ -133,6 +147,7 @@ return ir; } + @Test public void testPad() { int[] tests = new int[] {-9999999, -99560, -100, -3, -1, 0, 3, 9, 10, 1000, Index: lucene/src/test/org/apache/lucene/search/TestBoolean2.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestBoolean2.java (revision 996278) +++ lucene/src/test/org/apache/lucene/search/TestBoolean2.java (working copy) @@ -31,30 +31,36 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.store.RAMDirectory; -import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.LuceneTestCaseJ4; +import org.apache.lucene.util._TestUtil; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + /** Test BooleanQuery2 against BooleanQuery by overriding the standard query parser. * This also tests the scoring order of BooleanQuery. */ -public class TestBoolean2 extends LuceneTestCase { - private IndexSearcher searcher; - private IndexSearcher bigSearcher; - private IndexReader reader; +public class TestBoolean2 extends LuceneTestCaseJ4 { + private static IndexSearcher searcher; + private static IndexSearcher bigSearcher; + private static IndexReader reader; private static int NUM_EXTRA_DOCS = 6000; public static final String field = "field"; - private Directory directory; - private Directory dir2; - private int mulFactor; + private static Directory directory; + private static Directory dir2; + private static int mulFactor; - @Override - protected void setUp() throws Exception { - super.setUp(); - directory = newDirectory(); + @BeforeClass + public static void beforeClass() throws Exception { + Random random = newStaticRandom(TestBoolean2.class); + directory = newDirectory(random); RandomIndexWriter writer= new RandomIndexWriter(random, directory); for (int i = 0; i < docFields.length; i++) { Document doc = new Document(); - doc.add(newField(field, docFields[i], Field.Store.NO, Field.Index.ANALYZED)); + doc.add(newField(random, field, docFields[i], Field.Store.NO, Field.Index.ANALYZED)); writer.addDocument(doc); } writer.close(); @@ -75,14 +81,16 @@ mulFactor *= 2; } while(docCount < 3000); - RandomIndexWriter w = new RandomIndexWriter(random, dir2); + RandomIndexWriter w = new RandomIndexWriter(random, dir2, + newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()) + .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000))); Document doc = new Document(); - doc.add(newField("field2", "xxx", Field.Store.NO, Field.Index.ANALYZED)); + doc.add(newField(random, "field2", "xxx", Field.Store.NO, Field.Index.ANALYZED)); for(int i=0;i