From 3d7ebb0627049d329877f5cca4988d523176b3b7 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 20 Jun 2011 07:17:24 +0000 Subject: [PATCH] speed up some tests git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1137529 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/index/RandomIndexWriter.java | 2 +- .../org/apache/lucene/search/QueryUtils.java | 37 ++++++++++++------- .../index/TestIndexWriterOnJRECrash.java | 4 +- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/lucene/src/test-framework/org/apache/lucene/index/RandomIndexWriter.java b/lucene/src/test-framework/org/apache/lucene/index/RandomIndexWriter.java index 3bdbc369807..acf3585e0aa 100644 --- a/lucene/src/test-framework/org/apache/lucene/index/RandomIndexWriter.java +++ b/lucene/src/test-framework/org/apache/lucene/index/RandomIndexWriter.java @@ -114,7 +114,7 @@ public class RandomIndexWriter implements Closeable { private void switchDoDocValues() { // randomly enable / disable docValues - doDocValues = r.nextInt(10) != 0; + doDocValues = LuceneTestCase.rarely(r); } /** diff --git a/lucene/src/test-framework/org/apache/lucene/search/QueryUtils.java b/lucene/src/test-framework/org/apache/lucene/search/QueryUtils.java index 699af49f51c..4b13c62112f 100644 --- a/lucene/src/test-framework/org/apache/lucene/search/QueryUtils.java +++ b/lucene/src/test-framework/org/apache/lucene/search/QueryUtils.java @@ -148,23 +148,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)); out.setSimilarityProvider(s.getSimilarityProvider()); return out; } + + 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 Directory makeEmptyIndex(Random random, final int numDeletedDocs) + 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 +200,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 diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java index 6a62d05841e..e09cf3f9cf3 100644 --- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java +++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterOnJRECrash.java @@ -64,7 +64,7 @@ public class TestIndexWriterOnJRECrash extends TestNRTThreads { } } else { // we are the fork, setup a crashing thread - final int crashTime = TEST_NIGHTLY ? _TestUtil.nextInt(random, 500, 4000) : _TestUtil.nextInt(random, 300, 1000); + final int crashTime = _TestUtil.nextInt(random, 3000, 4000); Thread t = new Thread() { @Override public void run() { @@ -93,6 +93,8 @@ public class TestIndexWriterOnJRECrash extends TestNRTThreads { + "java"); cmd.add("-Xmx512m"); cmd.add("-Dtests.crashmode=true"); + // passing NIGHTLY to this test makes it run for much longer, easier to catch it in the act... + cmd.add("-Dtests.nightly=true"); cmd.add("-DtempDir=" + tempDir.getPath()); cmd.add("-Dtests.seed=" + random.nextLong() + ":" + random.nextLong()); cmd.add("-ea");