LUCENE-3175: @nightly OnJRECrash, and optimize some slower tests

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1140848 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2011-06-28 21:08:53 +00:00
parent 5327a55ff7
commit 2745612a4c
8 changed files with 67 additions and 46 deletions

View File

@ -106,6 +106,7 @@ public class CheckHits {
Assert.assertEquals("Wrap Reader " + i + ": " +
query.toString(defaultFieldName),
correct, actual);
FieldCache.DEFAULT.purge(s.getIndexReader()); // our wrapping can create insanity otherwise
s.close();
}
}

View File

@ -114,10 +114,13 @@ public class QueryUtils {
if (wrap) {
IndexSearcher wrapped;
check(random, q1, wrapped = wrapUnderlyingReader(random, s, -1), false);
FieldCache.DEFAULT.purge(wrapped.getIndexReader()); // // our wrapping can create insanity otherwise
wrapped.close();
check(random, q1, wrapped = wrapUnderlyingReader(random, s, 0), false);
FieldCache.DEFAULT.purge(wrapped.getIndexReader()); // // our wrapping can create insanity otherwise
wrapped.close();
check(random, q1, wrapped = wrapUnderlyingReader(random, s, +1), false);
FieldCache.DEFAULT.purge(wrapped.getIndexReader()); // // our wrapping can create insanity otherwise
wrapped.close();
}
checkExplanations(q1,s);
@ -148,23 +151,35 @@ public class QueryUtils {
// we can't put deleted docs before the nested reader, because
// it will throw off the docIds
IndexReader[] readers = new IndexReader[] {
edge < 0 ? r : IndexReader.open(makeEmptyIndex(random, 0), true),
IndexReader.open(makeEmptyIndex(random, 0), true),
new MultiReader(IndexReader.open(makeEmptyIndex(random, edge < 0 ? 4 : 0), true),
IndexReader.open(makeEmptyIndex(random, 0), true),
0 == edge ? r : IndexReader.open(makeEmptyIndex(random, 0), true)),
IndexReader.open(makeEmptyIndex(random, 0 < edge ? 0 : 7), true),
IndexReader.open(makeEmptyIndex(random, 0), true),
new MultiReader(IndexReader.open(makeEmptyIndex(random, 0 < edge ? 0 : 5), true),
IndexReader.open(makeEmptyIndex(random, 0), true),
0 < edge ? r : IndexReader.open(makeEmptyIndex(random, 0), true))
edge < 0 ? r : emptyReaders[0],
emptyReaders[0],
new MultiReader(edge < 0 ? emptyReaders[4] : emptyReaders[0],
emptyReaders[0],
0 == edge ? r : emptyReaders[0]),
0 < edge ? emptyReaders[0] : emptyReaders[7],
emptyReaders[0],
new MultiReader(0 < edge ? emptyReaders[0] : emptyReaders[5],
emptyReaders[0],
0 < edge ? r : emptyReaders[0])
};
IndexSearcher out = LuceneTestCase.newSearcher(new MultiReader(readers));
IndexSearcher out = LuceneTestCase.newSearcher(new MultiReader(readers), false);
out.setSimilarityProvider(s.getSimilarityProvider());
return out;
}
private static Directory makeEmptyIndex(Random random, final int numDeletedDocs)
static final IndexReader[] emptyReaders = new IndexReader[8];
static {
try {
emptyReaders[0] = makeEmptyIndex(new Random(0), 0);
emptyReaders[4] = makeEmptyIndex(new Random(0), 4);
emptyReaders[5] = makeEmptyIndex(new Random(0), 5);
emptyReaders[7] = makeEmptyIndex(new Random(0), 7);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
private static IndexReader makeEmptyIndex(Random random, final int numDeletedDocs)
throws IOException {
Directory d = new MockDirectoryWrapper(random, new RAMDirectory());
IndexWriter w = new IndexWriter(d, new IndexWriterConfig(
@ -188,8 +203,7 @@ public class QueryUtils {
IndexReader r = IndexReader.open(d, true);
Assert.assertEquals("reader has wrong number of deleted docs",
numDeletedDocs, r.numDeletedDocs());
r.close();
return d;
return r;
}
/** alternate scorer skipTo(),skipTo(),next(),next(),skipTo(),skipTo(), etc

View File

@ -47,7 +47,7 @@ public class TestIndexWriterOnJRECrash extends TestNRTThreads {
tempDir.mkdir();
}
@Override
@Override @Nightly
public void testNRTThreads() throws Exception {
String vendor = Constants.JAVA_VENDOR;
assumeTrue(vendor + " JRE not supported.",

View File

@ -39,7 +39,7 @@ public class TestComplexExplanations extends TestExplanations {
@Override
public void tearDown() throws Exception {
searcher.close();
searcher.setSimilarityProvider(IndexSearcher.getDefaultSimilarityProvider());
super.tearDown();
}

View File

@ -33,6 +33,8 @@ import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.spans.SpanTermQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
import org.junit.AfterClass;
import org.junit.BeforeClass;
/**
* Tests primitive queries (ie: that rewrite to themselves) to
@ -47,9 +49,9 @@ import org.apache.lucene.util.LuceneTestCase;
* @see "Subclasses for actual tests"
*/
public class TestExplanations extends LuceneTestCase {
protected IndexSearcher searcher;
protected IndexReader reader;
protected Directory directory;
protected static IndexSearcher searcher;
protected static IndexReader reader;
protected static Directory directory;
public static final String KEY = "KEY";
// boost on this field is the same as the iterator for the doc
@ -59,17 +61,18 @@ public class TestExplanations extends LuceneTestCase {
public static final QueryParser qp =
new QueryParser(TEST_VERSION_CURRENT, FIELD, new MockAnalyzer(random));
@Override
public void tearDown() throws Exception {
@AfterClass
public static void afterClassTestExplanations() throws Exception {
searcher.close();
searcher = null;
reader.close();
reader = null;
directory.close();
super.tearDown();
directory = null;
}
@Override
public void setUp() throws Exception {
super.setUp();
@BeforeClass
public static void beforeClassTestExplanations() throws Exception {
directory = newDirectory();
RandomIndexWriter writer= new RandomIndexWriter(random, directory, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setMergePolicy(newLogMergePolicy()));
for (int i = 0; i < docFields.length; i++) {
@ -86,7 +89,7 @@ public class TestExplanations extends LuceneTestCase {
searcher = newSearcher(reader);
}
protected String[] docFields = {
protected static final String[] docFields = {
"w1 w2 w3 w4 w5",
"w1 w3 w2 w3 zz",
"w1 xx w2 yy w3",

View File

@ -44,7 +44,7 @@ public class TestNumericRangeQuery32 extends LuceneTestCase {
// shift the starting of the values to the left, to also have negative values:
private static final int startOffset = - 1 << 15;
// number of docs to generate for testing
private static final int noDocs = atLeast(5000);
private static final int noDocs = atLeast(4096);
private static Directory directory = null;
private static IndexReader reader = null;
@ -62,7 +62,7 @@ public class TestNumericRangeQuery32 extends LuceneTestCase {
field8 = new NumericField("field8", 8, Field.Store.YES, true),
field4 = new NumericField("field4", 4, Field.Store.YES, true),
field2 = new NumericField("field2", 2, Field.Store.YES, true),
fieldNoTrie = new NumericField("field"+Integer.MAX_VALUE, Integer.MAX_VALUE, Field.Store.YES, true),
fieldNoTrie = new NumericField("field"+Integer.MAX_VALUE, Integer.MAX_VALUE, rarely() ? Field.Store.YES : Field.Store.NO, true),
ascfield8 = new NumericField("ascfield8", 8, Field.Store.NO, true),
ascfield4 = new NumericField("ascfield4", 4, Field.Store.NO, true),
ascfield2 = new NumericField("ascfield2", 2, Field.Store.NO, true);

View File

@ -41,7 +41,7 @@ public class TestNumericRangeQuery64 extends LuceneTestCase {
// shift the starting of the values to the left, to also have negative values:
private static final long startOffset = - 1L << 31;
// number of docs to generate for testing
private static final int noDocs = atLeast(5000);
private static final int noDocs = atLeast(4096);
private static Directory directory = null;
private static IndexReader reader = null;
@ -60,7 +60,7 @@ public class TestNumericRangeQuery64 extends LuceneTestCase {
field6 = new NumericField("field6", 6, Field.Store.YES, true),
field4 = new NumericField("field4", 4, Field.Store.YES, true),
field2 = new NumericField("field2", 2, Field.Store.YES, true),
fieldNoTrie = new NumericField("field"+Integer.MAX_VALUE, Integer.MAX_VALUE, Field.Store.YES, true),
fieldNoTrie = new NumericField("field"+Integer.MAX_VALUE, Integer.MAX_VALUE, rarely() ? Field.Store.YES : Field.Store.NO, true),
ascfield8 = new NumericField("ascfield8", 8, Field.Store.NO, true),
ascfield6 = new NumericField("ascfield6", 6, Field.Store.NO, true),
ascfield4 = new NumericField("ascfield4", 4, Field.Store.NO, true),

View File

@ -45,6 +45,8 @@ import org.apache.lucene.index.Term;
import org.apache.lucene.store.Directory;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import java.io.Reader;
import java.io.IOException;
@ -55,15 +57,15 @@ import java.io.IOException;
*
**/
public class TestPayloadTermQuery extends LuceneTestCase {
private IndexSearcher searcher;
private IndexReader reader;
private SimilarityProvider similarityProvider = new BoostingSimilarityProvider();
private byte[] payloadField = new byte[]{1};
private byte[] payloadMultiField1 = new byte[]{2};
private byte[] payloadMultiField2 = new byte[]{4};
protected Directory directory;
private static IndexSearcher searcher;
private static IndexReader reader;
private static SimilarityProvider similarityProvider = new BoostingSimilarityProvider();
private static final byte[] payloadField = new byte[]{1};
private static final byte[] payloadMultiField1 = new byte[]{2};
private static final byte[] payloadMultiField2 = new byte[]{4};
protected static Directory directory;
private class PayloadAnalyzer extends Analyzer {
private static class PayloadAnalyzer extends Analyzer {
@Override
@ -74,7 +76,7 @@ public class TestPayloadTermQuery extends LuceneTestCase {
}
}
private class PayloadFilter extends TokenFilter {
private static class PayloadFilter extends TokenFilter {
String fieldName;
int numSeen = 0;
@ -107,9 +109,8 @@ public class TestPayloadTermQuery extends LuceneTestCase {
}
}
@Override
public void setUp() throws Exception {
super.setUp();
@BeforeClass
public static void beforeClass() throws Exception {
directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, directory,
newIndexWriterConfig(TEST_VERSION_CURRENT, new PayloadAnalyzer())
@ -131,12 +132,14 @@ public class TestPayloadTermQuery extends LuceneTestCase {
searcher.setSimilarityProvider(similarityProvider);
}
@Override
public void tearDown() throws Exception {
@AfterClass
public static void afterClass() throws Exception {
searcher.close();
searcher = null;
reader.close();
reader = null;
directory.close();
super.tearDown();
directory = null;
}
public void test() throws IOException {