Apache Lucene open-source search software
LUCENE-2598: add newDirectory and track that resources are closed correctly by tests
Robert Muirfaed4b4cd026
diff --git a/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterPhraseTest.java b/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterPhraseTest.javaindex 8269bfe284a..a5d9243987c 100644--- a/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterPhraseTest.java+++ b/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterPhraseTest.java@@ -18,6 +18,7 @@ package org.apache.lucene.search.highlight;*/import java.io.IOException;+import java.util.Random;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.analysis.MockTokenizer;@@ -54,13 +55,13 @@ import org.apache.lucene.util.OpenBitSet;public class HighlighterPhraseTest extends LuceneTestCase {private static final String FIELD = "text";-+ private Random random = newRandom();public void testConcurrentPhrase() throws CorruptIndexException,LockObtainFailedException, IOException, InvalidTokenOffsetsException {final String TEXT = "the fox jumped";- final Directory directory = new MockRAMDirectory();+ final Directory directory = newDirectory(random);final IndexWriter indexWriter = new IndexWriter(directory,- new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));+ newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));try {final Document document = new Document();document.add(new Field(FIELD, new TokenStreamConcurrent(),@@ -95,15 +96,16 @@ public class HighlighterPhraseTest extends LuceneTestCase {}} finally {indexReader.close();+ directory.close();}}public void testConcurrentSpan() throws CorruptIndexException,LockObtainFailedException, IOException, InvalidTokenOffsetsException {final String TEXT = "the fox jumped";- final Directory directory = new MockRAMDirectory();+ final Directory directory = newDirectory(random);final IndexWriter indexWriter = new IndexWriter(directory,- new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));+ newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));try {final Document document = new Document();document.add(new Field(FIELD, new TokenStreamConcurrent(),@@ -164,15 +166,16 @@ public class HighlighterPhraseTest extends LuceneTestCase {}} finally {indexReader.close();+ directory.close();}}public void testSparsePhrase() throws CorruptIndexException,LockObtainFailedException, IOException, InvalidTokenOffsetsException {final String TEXT = "the fox did not jump";- final Directory directory = new MockRAMDirectory();+ final Directory directory = newDirectory(random);final IndexWriter indexWriter = new IndexWriter(directory,- new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));+ newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));try {final Document document = new Document();document.add(new Field(FIELD, new TokenStreamSparse(),@@ -206,15 +209,16 @@ public class HighlighterPhraseTest extends LuceneTestCase {}} finally {indexReader.close();+ directory.close();}}public void testSparsePhraseWithNoPositions() throws CorruptIndexException,LockObtainFailedException, IOException, InvalidTokenOffsetsException {final String TEXT = "the fox did not jump";- final Directory directory = new MockRAMDirectory();+ final Directory directory = newDirectory(random);final IndexWriter indexWriter = new IndexWriter(directory,- new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));+ newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));try {final Document document = new Document();document.add(new Field(FIELD, TEXT, Store.YES, Index.ANALYZED,@@ -246,15 +250,16 @@ public class HighlighterPhraseTest extends LuceneTestCase {}} finally {indexReader.close();+ directory.close();}}public void testSparseSpan() throws CorruptIndexException,LockObtainFailedException, IOException, InvalidTokenOffsetsException {final String TEXT = "the fox did not jump";- final Directory directory = new MockRAMDirectory();+ final Directory directory = newDirectory(random);final IndexWriter indexWriter = new IndexWriter(directory,- new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));+ newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));try {final Document document = new Document();document.add(new Field(FIELD, new TokenStreamSparse(),@@ -288,6 +293,7 @@ public class HighlighterPhraseTest extends LuceneTestCase {}} finally {indexReader.close();+ directory.close();}}diff --git a/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java b/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.javaindex bd8400b58f1..0c734e38cb4 100644--- a/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java+++ b/lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java@@ -26,6 +26,7 @@ import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;+import java.util.Random;import java.util.StringTokenizer;import javax.xml.parsers.DocumentBuilder;@@ -99,6 +100,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatteint numHighlights = 0;final Analyzer analyzer = new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true);TopDocs hits;+ private Random random;String[] texts = {"Hello this is a piece of text that is very long and contains too much preamble and the meat is really here which says kennedy has been shot",@@ -142,6 +144,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatteif (VERBOSE) System.out.println(fragment);}+ searcher.close();}public void testHighlightingWithDefaultField() throws Exception {@@ -432,7 +435,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements FormatteQueryScorer scorer = new QueryScorer(query, FIELD_NAME);Highlighter highlighter = new Highlighter(this, scorer);-+for (int i = 0; i < hits.totalHits; i++) {String text = searcher.doc(hits.scoreDocs[i].doc).get(FIELD_NAME);TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, new StringReader(text));@@ -1206,6 +1209,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formattepublic void run() throws Exception {numHighlights = 0;// test to show how rewritten query can still be used+ if (searcher != null) searcher.close();searcher = new IndexSearcher(ramDir, true);Analyzer analyzer = new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true);@@ -1319,8 +1323,8 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formattepublic void testMultiSearcher() throws Exception {// setup index 1- MockRAMDirectory ramDir1 = new MockRAMDirectory();- IndexWriter writer1 = new IndexWriter(ramDir1, new IndexWriterConfig(+ MockRAMDirectory ramDir1 = newDirectory(random);+ IndexWriter writer1 = new IndexWriter(ramDir1, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true)));Document d = new Document();Field f = new Field(FIELD_NAME, "multiOne", Field.Store.YES, Field.Index.ANALYZED);@@ -1331,8 +1335,8 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements FormatteIndexReader reader1 = IndexReader.open(ramDir1, true);// setup index 2- MockRAMDirectory ramDir2 = new MockRAMDirectory();- IndexWriter writer2 = new IndexWriter(ramDir2, new IndexWriterConfig(+ MockRAMDirectory ramDir2 = newDirectory(random);+ IndexWriter writer2 = new IndexWriter(ramDir2, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true)));d = new Document();f = new Field(FIELD_NAME, "multiTwo", Field.Store.YES, Field.Index.ANALYZED);@@ -1371,7 +1375,12 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte}assertTrue("Failed to find correct number of highlights " + numHighlights + " found",numHighlights == 2);-+ reader1.close();+ reader2.close();+ searchers[0].close();+ searchers[1].close();+ ramDir1.close();+ ramDir2.close();}public void testFieldSpecificHighlighting() throws Exception {@@ -1587,7 +1596,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formattehelper.start();}- private Directory dir = new MockRAMDirectory();+ private Directory dir;private Analyzer a = new MockAnalyzer(MockTokenizer.WHITESPACE, false);public void testWeightedTermsWithDeletes() throws IOException, ParseException, InvalidTokenOffsetsException {@@ -1684,6 +1693,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte}public void doSearching(Query unReWrittenQuery) throws Exception {+ if (searcher != null) searcher.close();searcher = new IndexSearcher(ramDir, true);// for any multi-term queries to work (prefix, wildcard, range,fuzzy etc)// you must use a rewritten query!@@ -1714,8 +1724,10 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements Formatte@Overrideprotected void setUp() throws Exception {super.setUp();- ramDir = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(ramDir, new IndexWriterConfig(+ random = newRandom();+ dir = newDirectory(random);+ ramDir = newDirectory(random);+ IndexWriter writer = new IndexWriter(ramDir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true)));for (int i = 0; i < texts.length; i++) {addDoc(writer, texts[i]);@@ -1746,6 +1758,14 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements FormattenumHighlights = 0;}+ @Override+ protected void tearDown() throws Exception {+ if (searcher != null) searcher.close();+ reader.close();+ dir.close();+ ramDir.close();+ super.tearDown();+ }private void addDoc(IndexWriter writer, String text) throws IOException {Document d = new Document();Field f = new Field(FIELD_NAME, text, Field.Store.YES, Field.Index.ANALYZED);diff --git a/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/AbstractTestCase.java b/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/AbstractTestCase.javaindex efd946ffe05..c66796c0d74 100644--- a/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/AbstractTestCase.java+++ b/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/AbstractTestCase.java@@ -91,7 +91,7 @@ public abstract class AbstractTestCase extends LuceneTestCase {analyzerK = new MockAnalyzer(MockTokenizer.KEYWORD, false);paW = new QueryParser(TEST_VERSION_CURRENT, F, analyzerW );paB = new QueryParser(TEST_VERSION_CURRENT, F, analyzerB );- dir = new MockRAMDirectory();+ dir = newDirectory(newRandom());}@Override@@ -100,6 +100,7 @@ public abstract class AbstractTestCase extends LuceneTestCase {reader.close();reader = null;}+ dir.close();super.tearDown();}@@ -334,7 +335,7 @@ public abstract class AbstractTestCase extends LuceneTestCase {doc.add( new Field( F, value, Store.YES, Index.ANALYZED, TermVector.WITH_POSITIONS_OFFSETS ) );writer.addDocument( doc );writer.close();-+ if (reader != null) reader.close();reader = IndexReader.open( dir, true );}@@ -347,7 +348,7 @@ public abstract class AbstractTestCase extends LuceneTestCase {doc.add( new Field( F, value, Store.YES, Index.NOT_ANALYZED, TermVector.WITH_POSITIONS_OFFSETS ) );writer.addDocument( doc );writer.close();-+ if (reader != null) reader.close();reader = IndexReader.open( dir, true );}diff --git a/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilderTest.java b/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilderTest.javaindex 59f7aba8bc6..f756ffbef46 100644--- a/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilderTest.java+++ b/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilderTest.java@@ -64,11 +64,11 @@ public class SimpleFragListBuilderTest extends AbstractTestCase {FieldFragList ffl = sflb.createFieldFragList( fpl( "a", "a a" ), 100 );assertEquals( 1, ffl.fragInfos.size() );assertEquals( "subInfos=(a((0,1))a((2,3)))/2.0(0,100)", ffl.fragInfos.get( 0 ).toString() );-+ffl = sflb.createFieldFragList( fpl( "a", "a b b b b b b b b a" ), 20 );assertEquals( 1, ffl.fragInfos.size() );assertEquals( "subInfos=(a((0,1))a((18,19)))/2.0(0,20)", ffl.fragInfos.get( 0 ).toString() );-+ffl = sflb.createFieldFragList( fpl( "a", "b b b b a b b b b a" ), 20 );assertEquals( 1, ffl.fragInfos.size() );assertEquals( "subInfos=(a((8,9))a((18,19)))/2.0(2,22)", ffl.fragInfos.get( 0 ).toString() );diff --git a/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragmentsBuilderTest.java b/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragmentsBuilderTest.javaindex 4ff2ab6c665..73d0c9c736b 100644--- a/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragmentsBuilderTest.java+++ b/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragmentsBuilderTest.java@@ -135,7 +135,7 @@ public class SimpleFragmentsBuilderTest extends AbstractTestCase {doc.add( new Field( F, "aaa", Store.NO, Index.ANALYZED, TermVector.WITH_POSITIONS_OFFSETS ) );writer.addDocument( doc );writer.close();-+ if (reader != null) reader.close();reader = IndexReader.open( dir, true );}diff --git a/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestEmptyIndex.java b/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestEmptyIndex.javaindex 65faaf1bcd7..89ecfdb0309 100644--- a/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestEmptyIndex.java+++ b/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestEmptyIndex.java@@ -18,6 +18,7 @@ package org.apache.lucene.store.instantiated;import java.io.IOException;import java.util.Arrays;+import java.util.Random;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.index.IndexReader;@@ -60,9 +61,9 @@ public class TestEmptyIndex extends LuceneTestCase {ii.close();// make sure a Directory acts the same-- Directory d = new MockRAMDirectory();- new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())).close();+ Random random = newRandom();+ Directory d = newDirectory(random);+ new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())).close();r = IndexReader.open(d, false);testNorms(r);r.close();@@ -93,9 +94,9 @@ public class TestEmptyIndex extends LuceneTestCase {ii.close();// make sure a Directory acts the same-- Directory d = new MockRAMDirectory();- new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())).close();+ Random random = newRandom();+ Directory d = newDirectory(random);+ new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())).close();r = IndexReader.open(d, false);termsEnumTest(r);r.close();diff --git a/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java b/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.javaindex 230f2ac0c73..32a49051426 100644--- a/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java+++ b/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java@@ -21,6 +21,7 @@ import java.util.Arrays;import java.util.Comparator;import java.util.Iterator;import java.util.List;+import java.util.Random;import org.apache.lucene.analysis.Token;import org.apache.lucene.analysis.TokenStream;@@ -61,10 +62,11 @@ public class TestIndicesEquals extends LuceneTestCase {public void testLoadIndexReader() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();+ Random random = newRandom();+ MockRAMDirectory dir = newDirectory(random);// create dir data- IndexWriter indexWriter = new IndexWriter(dir, new IndexWriterConfig(+ IndexWriter indexWriter = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));for (int i = 0; i < 20; i++) {Document document = new Document();@@ -79,17 +81,18 @@ public class TestIndicesEquals extends LuceneTestCase {ir.close();testEqualBehaviour(dir, ii);+ dir.close();}public void testInstantiatedIndexWriter() throws Exception {-- MockRAMDirectory dir = new MockRAMDirectory();+ Random random = newRandom();+ MockRAMDirectory dir = newDirectory(random);InstantiatedIndex ii = new InstantiatedIndex();// create dir data- IndexWriter indexWriter = new IndexWriter(dir, new IndexWriterConfig(+ IndexWriter indexWriter = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));for (int i = 0; i < 500; i++) {Document document = new Document();@@ -110,7 +113,7 @@ public class TestIndicesEquals extends LuceneTestCase {testEqualBehaviour(dir, ii);-+ dir.close();}diff --git a/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestSerialization.java b/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestSerialization.javaindex cdf8f10e550..fa495287b9b 100644--- a/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestSerialization.java+++ b/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestSerialization.java@@ -17,26 +17,25 @@ package org.apache.lucene.store.instantiated;*/-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.store.Directory;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.IndexReader;-import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import java.io.ByteArrayOutputStream;import java.io.ObjectOutputStream;+import java.util.Random;public class TestSerialization extends LuceneTestCase {public void test() throws Exception {+ Random random = newRandom();+ Directory dir = newDirectory(random);- Directory dir = new MockRAMDirectory();-- IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new Field("foo", "bar rab abr bra rba", Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));doc.add(new Field("moo", "bar rab abr bra rba", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));@@ -52,7 +51,7 @@ public class TestSerialization extends LuceneTestCase {oos.writeObject(ii);oos.close();baos.close();-+ dir.close();}diff --git a/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestUnoptimizedReaderOnConstructor.java b/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestUnoptimizedReaderOnConstructor.javaindex 7f388d20352..6fc55c922c9 100644--- a/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestUnoptimizedReaderOnConstructor.java+++ b/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestUnoptimizedReaderOnConstructor.java@@ -16,6 +16,8 @@ package org.apache.lucene.store.instantiated;*/import java.io.IOException;+import java.util.Random;+import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.IndexWriterConfig;@@ -33,7 +35,8 @@ import org.apache.lucene.document.Field;public class TestUnoptimizedReaderOnConstructor extends LuceneTestCase {public void test() throws Exception {- Directory dir = new MockRAMDirectory();+ Random random = newRandom();+ Directory dir = newDirectory(random);IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));addDocument(iw, "Hello, world!");addDocument(iw, "All work and no play makes jack a dull boy");@@ -59,7 +62,8 @@ public class TestUnoptimizedReaderOnConstructor extends LuceneTestCase {}// todo some assertations.-+ unoptimizedReader.close();+ dir.close();}private void addDocument(IndexWriter iw, String text) throws IOException {diff --git a/lucene/contrib/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java b/lucene/contrib/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.javaindex 23b2de979ce..a948d659606 100644--- a/lucene/contrib/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java+++ b/lucene/contrib/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java@@ -106,7 +106,7 @@ public class MemoryIndexTest extends BaseTokenStreamTestCase {termField.append(randomTerm());}- MockRAMDirectory ramdir = new MockRAMDirectory();+ MockRAMDirectory ramdir = newDirectory(random);Analyzer analyzer = randomAnalyzer();IndexWriter writer = new IndexWriter(ramdir,new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer).setCodecProvider(_TestUtil.alwaysCodec("Standard")));@@ -122,6 +122,7 @@ public class MemoryIndexTest extends BaseTokenStreamTestCase {memory.addField("foo", fooField.toString(), analyzer);memory.addField("term", termField.toString(), analyzer);assertAllQueries(memory, ramdir, analyzer);+ ramdir.close();}/**@@ -136,6 +137,8 @@ public class MemoryIndexTest extends BaseTokenStreamTestCase {TopDocs memDocs = mem.search(qp.parse(query), 1);assertEquals(ramDocs.totalHits, memDocs.totalHits);}+ ram.close();+ mem.close();}/**diff --git a/lucene/contrib/misc/src/test/org/apache/lucene/index/TestFieldNormModifier.java b/lucene/contrib/misc/src/test/org/apache/lucene/index/TestFieldNormModifier.javaindex 6bc8048ad82..6eaaa2b1b4d 100644--- a/lucene/contrib/misc/src/test/org/apache/lucene/index/TestFieldNormModifier.java+++ b/lucene/contrib/misc/src/test/org/apache/lucene/index/TestFieldNormModifier.java@@ -19,6 +19,7 @@ package org.apache.lucene.index;import java.io.IOException;import java.util.Arrays;+import java.util.Random;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;@@ -44,7 +45,7 @@ public class TestFieldNormModifier extends LuceneTestCase {public static int NUM_DOCS = 5;- public Directory store = new MockRAMDirectory();+ public Directory store;/** inverts the normal notion of lengthNorm */public static Similarity s = new DefaultSimilarity() {@@ -57,7 +58,9 @@ public class TestFieldNormModifier extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- IndexWriter writer = new IndexWriter(store, new IndexWriterConfig(+ Random random = newRandom();+ store = newDirectory(random);+ IndexWriter writer = new IndexWriter(store, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));for (int i = 0; i < NUM_DOCS; i++) {@@ -75,6 +78,12 @@ public class TestFieldNormModifier extends LuceneTestCase {writer.close();}+ @Override+ protected void tearDown() throws Exception {+ store.close();+ super.tearDown();+ }+public void testMissingField() throws Exception {FieldNormModifier fnm = new FieldNormModifier(store, s);fnm.reSetNorms("nobodyherebutuschickens");diff --git a/lucene/contrib/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java b/lucene/contrib/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.javaindex a05e37bf898..18f2749cf02 100644--- a/lucene/contrib/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java+++ b/lucene/contrib/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java@@ -16,6 +16,8 @@ package org.apache.lucene.index;* limitations under the License.*/+import java.util.Random;+import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;@@ -27,12 +29,15 @@ import org.apache.lucene.util.BytesRef;public class TestMultiPassIndexSplitter extends LuceneTestCase {IndexReader input;int NUM_DOCS = 11;-+ private Random random;+ MockRAMDirectory dir;+@Overrideprotected void setUp() throws Exception {super.setUp();- MockRAMDirectory dir = new MockRAMDirectory();- IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ random = newRandom();+ dir = newDirectory(random);+ IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc;for (int i = 0; i < NUM_DOCS; i++) {doc = new Document();@@ -44,7 +49,16 @@ public class TestMultiPassIndexSplitter extends LuceneTestCase {input = IndexReader.open(dir, false);// delete the last docinput.deleteDocument(input.maxDoc() - 1);+ IndexReader inputOld = input;input = input.reopen(true);+ inputOld.close();+ }++ @Override+ protected void tearDown() throws Exception {+ input.close();+ dir.close();+ super.tearDown();}/**@@ -53,9 +67,9 @@ public class TestMultiPassIndexSplitter extends LuceneTestCase {public void testSplitRR() throws Exception {MultiPassIndexSplitter splitter = new MultiPassIndexSplitter();Directory[] dirs = new Directory[]{- new MockRAMDirectory(),- new MockRAMDirectory(),- new MockRAMDirectory()+ newDirectory(random),+ newDirectory(random),+ newDirectory(random)};splitter.split(input, dirs, false);IndexReader ir;@@ -86,7 +100,10 @@ public class TestMultiPassIndexSplitter extends LuceneTestCase {assertNotSame("1", te.term());assertEquals(TermsEnum.SeekStatus.NOT_FOUND, te.seek(new BytesRef("0")));- assertNotSame("0", te.term().utf8ToString());+ assertNotSame("0", te.term().utf8ToString());+ ir.close();+ for (Directory d : dirs)+ d.close();}/**@@ -95,9 +112,9 @@ public class TestMultiPassIndexSplitter extends LuceneTestCase {public void testSplitSeq() throws Exception {MultiPassIndexSplitter splitter = new MultiPassIndexSplitter();Directory[] dirs = new Directory[]{- new MockRAMDirectory(),- new MockRAMDirectory(),- new MockRAMDirectory()+ newDirectory(random),+ newDirectory(random),+ newDirectory(random)};splitter.split(input, dirs, true);IndexReader ir;@@ -122,5 +139,8 @@ public class TestMultiPassIndexSplitter extends LuceneTestCase {Term t = new Term("id", (NUM_DOCS - 1) + "");assertEquals(TermsEnum.SeekStatus.NOT_FOUND, te.seek(new BytesRef(t.text())));assertNotSame(t.text(), te.term().utf8ToString());+ ir.close();+ for (Directory d : dirs)+ d.close();}}diff --git a/lucene/contrib/misc/src/test/org/apache/lucene/index/TestTermVectorAccessor.java b/lucene/contrib/misc/src/test/org/apache/lucene/index/TestTermVectorAccessor.javaindex 39b6349cb92..59dc97e1e86 100644--- a/lucene/contrib/misc/src/test/org/apache/lucene/index/TestTermVectorAccessor.java+++ b/lucene/contrib/misc/src/test/org/apache/lucene/index/TestTermVectorAccessor.java@@ -8,6 +8,7 @@ import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;import java.util.Collections;+import java.util.Random;/** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -26,9 +27,9 @@ import java.util.Collections;public class TestTermVectorAccessor extends LuceneTestCase {public void test() throws Exception {-- Directory dir = new MockRAMDirectory();- IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ Random random = newRandom();+ Directory dir = newDirectory(random);+ IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc;diff --git a/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.java b/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.javaindex 59cb0a0485c..dafc0559238 100644--- a/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.java+++ b/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.java@@ -17,6 +17,8 @@ package org.apache.lucene.misc;* limitations under the License.*/+import java.util.Random;+import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.IndexWriterConfig;@@ -36,17 +38,19 @@ public class TestHighFreqTerms extends LuceneTestCase {public void setUp() throws Exception {super.setUp();- dir= new MockRAMDirectory();- writer = new IndexWriter(dir, new IndexWriterConfig(+ Random random = newRandom();+ dir= newDirectory(random);+ writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDocs(2));indexDocs(writer);reader = IndexReader.open(dir, true);}- public void tearDown()throws Exception{- super.tearDown();+ public void tearDown() throws Exception{reader.close();+ dir.close();+ super.tearDown();}/******************** Tests for getHighFreqTerms **********************************/diff --git a/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestLengthNormModifier.java b/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestLengthNormModifier.javaindex 121492199a6..0470a90de37 100644--- a/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestLengthNormModifier.java+++ b/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestLengthNormModifier.java@@ -18,6 +18,7 @@ package org.apache.lucene.misc;*/import java.io.IOException;+import java.util.Random;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;@@ -48,7 +49,7 @@ public class TestLengthNormModifier extends LuceneTestCase {public static int NUM_DOCS = 5;- public Directory store = new MockRAMDirectory();+ public Directory store;/** inverts the normal notion of lengthNorm */public static Similarity s = new DefaultSimilarity() {@@ -61,7 +62,9 @@ public class TestLengthNormModifier extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- IndexWriter writer = new IndexWriter(store, new IndexWriterConfig(+ Random random = newRandom();+ store = newDirectory(random);+ IndexWriter writer = new IndexWriter(store, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));for (int i = 0; i < NUM_DOCS; i++) {@@ -82,6 +85,12 @@ public class TestLengthNormModifier extends LuceneTestCase {writer.close();}+ @Override+ protected void tearDown() throws Exception {+ store.close();+ super.tearDown();+ }+public void testMissingField() {FieldNormModifier fnm = new FieldNormModifier(store, s);try {diff --git a/lucene/contrib/queries/src/test/org/apache/lucene/search/BooleanFilterTest.java b/lucene/contrib/queries/src/test/org/apache/lucene/search/BooleanFilterTest.javaindex 7aaf1c60509..6720e568dfb 100644--- a/lucene/contrib/queries/src/test/org/apache/lucene/search/BooleanFilterTest.java+++ b/lucene/contrib/queries/src/test/org/apache/lucene/search/BooleanFilterTest.java@@ -18,6 +18,7 @@ package org.apache.lucene.search;*/import java.io.IOException;+import java.util.Random;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.analysis.MockTokenizer;@@ -38,8 +39,9 @@ public class BooleanFilterTest extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory, new MockAnalyzer(MockTokenizer.WHITESPACE, false));+ Random random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory, new MockAnalyzer(MockTokenizer.WHITESPACE, false));//Add series of docs with filterable fields : acces rights, prices, dates and "in-stock" flagsaddDoc(writer, "admin guest", "010", "20040101","Y");diff --git a/lucene/contrib/queries/src/test/org/apache/lucene/search/ChainedFilterTest.java b/lucene/contrib/queries/src/test/org/apache/lucene/search/ChainedFilterTest.javaindex 0de905e20a2..6bd31084448 100644--- a/lucene/contrib/queries/src/test/org/apache/lucene/search/ChainedFilterTest.java+++ b/lucene/contrib/queries/src/test/org/apache/lucene/search/ChainedFilterTest.java@@ -60,7 +60,7 @@ public class ChainedFilterTest extends LuceneTestCase {protected void setUp() throws Exception {super.setUp();random = newRandom();- directory = new MockRAMDirectory();+ directory = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, directory);Calendar cal = new GregorianCalendar();cal.clear();@@ -195,7 +195,7 @@ public class ChainedFilterTest extends LuceneTestCase {*/public void testWithCachingFilter() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, dir);IndexReader reader = writer.getReader();writer.close();diff --git a/lucene/contrib/queries/src/test/org/apache/lucene/search/DuplicateFilterTest.java b/lucene/contrib/queries/src/test/org/apache/lucene/search/DuplicateFilterTest.javaindex 2b6b85ae9ae..11f918b24dd 100644--- a/lucene/contrib/queries/src/test/org/apache/lucene/search/DuplicateFilterTest.java+++ b/lucene/contrib/queries/src/test/org/apache/lucene/search/DuplicateFilterTest.java@@ -19,6 +19,7 @@ package org.apache.lucene.search;import java.io.IOException;import java.util.HashSet;+import java.util.Random;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;@@ -41,8 +42,9 @@ public class DuplicateFilterTest extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ Random random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);//Add series of docs with filterable fields : url, text and dates flagsaddDoc(writer, "http://lucene.apache.org", "lucene 1.4.3 available", "20040101");diff --git a/lucene/contrib/queries/src/test/org/apache/lucene/search/FuzzyLikeThisQueryTest.java b/lucene/contrib/queries/src/test/org/apache/lucene/search/FuzzyLikeThisQueryTest.javaindex c64a1161076..b23bedda473 100644--- a/lucene/contrib/queries/src/test/org/apache/lucene/search/FuzzyLikeThisQueryTest.java+++ b/lucene/contrib/queries/src/test/org/apache/lucene/search/FuzzyLikeThisQueryTest.java@@ -19,6 +19,7 @@ package org.apache.lucene.search;import java.io.IOException;import java.util.HashSet;+import java.util.Random;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.MockAnalyzer;@@ -39,8 +40,9 @@ public class FuzzyLikeThisQueryTest extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ Random random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);//Add series of docs with misspelt namesaddDoc(writer, "jonathon smythe","1");diff --git a/lucene/contrib/queries/src/test/org/apache/lucene/search/TermsFilterTest.java b/lucene/contrib/queries/src/test/org/apache/lucene/search/TermsFilterTest.javaindex dbccd25b8a5..dc2edf16cf5 100644--- a/lucene/contrib/queries/src/test/org/apache/lucene/search/TermsFilterTest.java+++ b/lucene/contrib/queries/src/test/org/apache/lucene/search/TermsFilterTest.java@@ -18,6 +18,7 @@ package org.apache.lucene.search;*/import java.util.HashSet;+import java.util.Random;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;@@ -51,8 +52,9 @@ public class TermsFilterTest extends LuceneTestCase {public void testMissingTerms() throws Exception {String fieldName="field1";- MockRAMDirectory rd=new MockRAMDirectory();- RandomIndexWriter w = new RandomIndexWriter(newRandom(), rd);+ Random random = newRandom();+ MockRAMDirectory rd=newDirectory(random);+ RandomIndexWriter w = new RandomIndexWriter(random, rd);for (int i = 0; i < 100; i++) {Document doc=new Document();int term=i*10; //terms are units of 10;diff --git a/lucene/contrib/queries/src/test/org/apache/lucene/search/regex/TestRegexQuery.java b/lucene/contrib/queries/src/test/org/apache/lucene/search/regex/TestRegexQuery.javaindex a0e0dc67972..daacf506aba 100644--- a/lucene/contrib/queries/src/test/org/apache/lucene/search/regex/TestRegexQuery.java+++ b/lucene/contrib/queries/src/test/org/apache/lucene/search/regex/TestRegexQuery.java@@ -17,6 +17,8 @@ package org.apache.lucene.search.regex;* limitations under the License.*/+import java.util.Random;+import org.apache.lucene.store.Directory;import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.index.IndexReader;@@ -41,8 +43,9 @@ public class TestRegexQuery extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ Random random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);Document doc = new Document();doc.add(new Field(FN, "the quick brown fox jumps over the lazy dog", Field.Store.NO, Field.Index.ANALYZED));writer.addDocument(doc);diff --git a/lucene/contrib/queries/src/test/org/apache/lucene/search/regex/TestSpanRegexQuery.java b/lucene/contrib/queries/src/test/org/apache/lucene/search/regex/TestSpanRegexQuery.javaindex 9b0ccb8ce43..99998228c4f 100644--- a/lucene/contrib/queries/src/test/org/apache/lucene/search/regex/TestSpanRegexQuery.java+++ b/lucene/contrib/queries/src/test/org/apache/lucene/search/regex/TestSpanRegexQuery.java@@ -18,6 +18,7 @@ package org.apache.lucene.search.regex;*/import java.io.IOException;+import java.util.Random;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;@@ -39,13 +40,28 @@ import org.apache.lucene.util.LuceneTestCase;public class TestSpanRegexQuery extends LuceneTestCase {- Directory indexStoreA = new MockRAMDirectory();-- Directory indexStoreB = new MockRAMDirectory();-+ Directory indexStoreA;+ Directory indexStoreB;+ Random random;++ @Override+ public void setUp() throws Exception {+ super.setUp();+ random = newRandom();+ indexStoreA = newDirectory(random);+ indexStoreB = newDirectory(random);+ }++ @Override+ public void tearDown() throws Exception {+ indexStoreA.close();+ indexStoreB.close();+ super.tearDown();+ }+public void testSpanRegex() throws Exception {- MockRAMDirectory directory = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(+ MockRAMDirectory directory = newDirectory(random);+ IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();// doc.add(new Field("field", "the quick brown fox jumps over the lazy dog",@@ -69,6 +85,8 @@ public class TestSpanRegexQuery extends LuceneTestCase {// true);int numHits = searcher.search(sfq, null, 1000).totalHits;assertEquals(1, numHits);+ searcher.close();+ directory.close();}public void testSpanRegexBug() throws CorruptIndexException, IOException {@@ -111,14 +129,14 @@ public class TestSpanRegexQuery extends LuceneTestCase {Field.Index.ANALYZED_NO_NORMS));// creating first index writer- IndexWriter writerA = new IndexWriter(indexStoreA, new IndexWriterConfig(+ IndexWriter writerA = new IndexWriter(indexStoreA, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));writerA.addDocument(lDoc);writerA.optimize();writerA.close();// creating second index writer- IndexWriter writerB = new IndexWriter(indexStoreB, new IndexWriterConfig(+ IndexWriter writerB = new IndexWriter(indexStoreB, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));writerB.addDocument(lDoc2);writerB.optimize();diff --git a/lucene/contrib/queries/src/test/org/apache/lucene/search/similar/TestMoreLikeThis.java b/lucene/contrib/queries/src/test/org/apache/lucene/search/similar/TestMoreLikeThis.javaindex 233a1898f30..2d7f6b7ee0e 100644--- a/lucene/contrib/queries/src/test/org/apache/lucene/search/similar/TestMoreLikeThis.java+++ b/lucene/contrib/queries/src/test/org/apache/lucene/search/similar/TestMoreLikeThis.java@@ -22,6 +22,7 @@ import java.io.StringReader;import java.util.HashMap;import java.util.List;import java.util.Map;+import java.util.Random;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.analysis.MockTokenizer;@@ -44,8 +45,9 @@ public class TestMoreLikeThis extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ Random random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);// Add series of docs with specific information for MoreLikeThisaddDoc(writer, "lucene");diff --git a/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/complexPhrase/TestComplexPhraseQuery.java b/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/complexPhrase/TestComplexPhraseQuery.javaindex 28024e2d837..d12b2cd2d39 100644--- a/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/complexPhrase/TestComplexPhraseQuery.java+++ b/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/complexPhrase/TestComplexPhraseQuery.java@@ -18,6 +18,7 @@ package org.apache.lucene.queryParser.complexPhrase;*/import java.util.HashSet;+import java.util.Random;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.MockAnalyzer;@@ -34,7 +35,7 @@ import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;public class TestComplexPhraseQuery extends LuceneTestCase {-+ MockRAMDirectory rd;Analyzer analyzer = new MockAnalyzer();DocData docsContent[] = { new DocData("john smith", "1"),@@ -112,8 +113,9 @@ public class TestComplexPhraseQuery extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- MockRAMDirectory rd = new MockRAMDirectory();- IndexWriter w = new IndexWriter(rd, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));+ Random random = newRandom();+ rd = newDirectory(random);+ IndexWriter w = new IndexWriter(rd, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));for (int i = 0; i < docsContent.length; i++) {Document doc = new Document();doc.add(new Field("name", docsContent[i].name, Field.Store.YES,@@ -129,6 +131,7 @@ public class TestComplexPhraseQuery extends LuceneTestCase {@Overrideprotected void tearDown() throws Exception {searcher.close();+ rd.close();super.tearDown();}diff --git a/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.java b/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.javaindex 0265551fa75..4d6a8f46eb7 100644--- a/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.java+++ b/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQPHelper.java@@ -20,6 +20,7 @@ package org.apache.lucene.queryParser.standard;import java.io.Reader;import java.util.HashMap;import java.util.Map;+import java.util.Random;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.TokenStream;@@ -319,8 +320,9 @@ public class TestMultiFieldQPHelper extends LuceneTestCase {public void testStopWordSearching() throws Exception {Analyzer analyzer = new MockAnalyzer();- Directory ramDir = new MockRAMDirectory();- IndexWriter iw = new IndexWriter(ramDir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));+ Random random = newRandom();+ Directory ramDir = newDirectory(random);+ IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));Document doc = new Document();doc.add(new Field("body", "blah the footest blah", Field.Store.NO,Field.Index.ANALYZED));@@ -337,6 +339,7 @@ public class TestMultiFieldQPHelper extends LuceneTestCase {ScoreDoc[] hits = is.search(q, null, 1000).scoreDocs;assertEquals(1, hits.length);is.close();+ ramDir.close();}/**diff --git a/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQueryParserWrapper.java b/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQueryParserWrapper.javaindex 8c7891567c2..2196a770b62 100644--- a/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQueryParserWrapper.java+++ b/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestMultiFieldQueryParserWrapper.java@@ -321,7 +321,7 @@ public class TestMultiFieldQueryParserWrapper extends LuceneTestCase {public void testStopWordSearching() throws Exception {Analyzer analyzer = new MockAnalyzer();- Directory ramDir = new MockRAMDirectory();+ Directory ramDir = newDirectory(newRandom());IndexWriter iw = new IndexWriter(ramDir, analyzer, true,IndexWriter.MaxFieldLength.LIMITED);Document doc = new Document();@@ -338,6 +338,7 @@ public class TestMultiFieldQueryParserWrapper extends LuceneTestCase {ScoreDoc[] hits = is.search(q, null, 1000).scoreDocs;assertEquals(1, hits.length);is.close();+ ramDir.close();}/**diff --git a/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java b/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.javaindex b1e54eb3967..43643436cd8 100644--- a/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java+++ b/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQPHelper.java@@ -30,6 +30,7 @@ import java.util.Arrays;import java.util.List;import java.util.Locale;import java.util.Map;+import java.util.Random;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.MockAnalyzer;@@ -653,9 +654,9 @@ public class TestQPHelper extends LocalizedTestCase {}public void testFarsiRangeCollating() throws Exception {-- MockRAMDirectory ramDir = new MockRAMDirectory();- IndexWriter iw = new IndexWriter(ramDir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));+ Random random = newRandom();+ MockRAMDirectory ramDir = newDirectory(random);+ IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));Document doc = new Document();doc.add(new Field("content", "\u0633\u0627\u0628", Field.Store.YES,Field.Index.NOT_ANALYZED));@@ -699,6 +700,7 @@ public class TestQPHelper extends LocalizedTestCase {assertEquals("The index Term should be included.", 1, result.length);is.close();+ ramDir.close();}/** for testing legacy DateField support */@@ -1076,9 +1078,9 @@ public class TestQPHelper extends LocalizedTestCase {}public void testLocalDateFormat() throws IOException, QueryNodeException {-- MockRAMDirectory ramDir = new MockRAMDirectory();- IndexWriter iw = new IndexWriter(ramDir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));+ Random random = newRandom();+ MockRAMDirectory ramDir = newDirectory(random);+ IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));addDateDoc("a", 2005, 12, 2, 10, 15, 33, iw);addDateDoc("b", 2005, 12, 4, 22, 15, 00, iw);iw.close();@@ -1090,6 +1092,7 @@ public class TestQPHelper extends LocalizedTestCase {assertHits(1, "{12/1/2005 TO 12/4/2005}", is);assertHits(0, "{12/3/2005 TO 12/4/2005}", is);is.close();+ ramDir.close();}public void testStarParsing() throws Exception {@@ -1275,8 +1278,9 @@ public class TestQPHelper extends LocalizedTestCase {}public void testMultiPhraseQuery() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();- IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new CannedAnalyzer()));+ Random random = newRandom();+ MockRAMDirectory dir = newDirectory(random);+ IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new CannedAnalyzer()));Document doc = new Document();doc.add(new Field("field", "", Field.Store.NO, Field.Index.ANALYZED));w.addDocument(doc);@@ -1288,6 +1292,7 @@ public class TestQPHelper extends LocalizedTestCase {assertEquals(1, s.search(q, 10).totalHits);r.close();w.close();+ dir.close();}}diff --git a/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java b/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.javaindex 34ee1998983..725a3e93bfb 100644--- a/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java+++ b/lucene/contrib/queryparser/src/test/org/apache/lucene/queryParser/standard/TestQueryParserWrapper.java@@ -654,7 +654,7 @@ public class TestQueryParserWrapper extends LocalizedTestCase {public void testFarsiRangeCollating() throws Exception {- MockRAMDirectory ramDir = new MockRAMDirectory();+ MockRAMDirectory ramDir = newDirectory(newRandom());IndexWriter iw = new IndexWriter(ramDir, new MockAnalyzer(MockTokenizer.WHITESPACE, false), true,IndexWriter.MaxFieldLength.LIMITED);Document doc = new Document();@@ -696,6 +696,7 @@ public class TestQueryParserWrapper extends LocalizedTestCase {assertEquals("The index Term should be included.", 1, result.length);is.close();+ ramDir.close();}private String escapeDateString(String s) {@@ -1062,7 +1063,7 @@ public class TestQueryParserWrapper extends LocalizedTestCase {public void testLocalDateFormat() throws IOException, ParseException {- MockRAMDirectory ramDir = new MockRAMDirectory();+ MockRAMDirectory ramDir = newDirectory(newRandom());IndexWriter iw = new IndexWriter(ramDir, new MockAnalyzer(MockTokenizer.WHITESPACE, false), true,IndexWriter.MaxFieldLength.LIMITED);addDateDoc("a", 2005, 12, 2, 10, 15, 33, iw);@@ -1076,6 +1077,7 @@ public class TestQueryParserWrapper extends LocalizedTestCase {assertHits(1, "{12/1/2005 TO 12/4/2005}", is);assertHits(0, "{12/3/2005 TO 12/4/2005}", is);is.close();+ ramDir.close();}public void testStarParsing() throws Exception {diff --git a/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java b/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.javaindex ff75cd18d48..fa9893cc658 100644--- a/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java+++ b/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java@@ -17,13 +17,15 @@ package org.apache.lucene.search;* limitations under the License.*/+import java.util.Random;+import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.index.IndexWriter;-import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.Term;import org.apache.lucene.store.MockRAMDirectory;+import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;@@ -33,11 +35,15 @@ import static org.junit.Assert.*;* Tests that the index is cached on the searcher side of things.*/public class TestRemoteCachingWrapperFilter extends RemoteTestCaseJ4 {+ private static MockRAMDirectory indexStore;+ private static Searchable local;+@BeforeClasspublic static void beforeClass() throws Exception {// construct an index- MockRAMDirectory indexStore = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(indexStore, new IndexWriterConfig(+ Random random = newStaticRandom(TestRemoteCachingWrapperFilter.class);+ indexStore = newDirectory(random);+ IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new Field("test", "test text", Field.Store.YES, Field.Index.ANALYZED));@@ -52,10 +58,17 @@ public class TestRemoteCachingWrapperFilter extends RemoteTestCaseJ4 {writer.addDocument(doc);writer.optimize();writer.close();- Searchable local = new IndexSearcher(indexStore, true);+ local = new IndexSearcher(indexStore, true);startServer(local);}+ @AfterClass+ public static void afterClass() throws Exception {+ local.close();+ indexStore.close();+ indexStore = null;+ }+private static void search(Query query, Filter filter, int hitNumber, String typeValue) throws Exception {Searchable[] searchables = { lookupRemote() };Searcher searcher = new MultiSearcher(searchables);diff --git a/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.java b/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.javaindex fd302840e02..18eda716291 100644--- a/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.java+++ b/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.java@@ -20,25 +20,29 @@ package org.apache.lucene.search;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.*;import org.apache.lucene.index.IndexWriter;-import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.Term;import org.apache.lucene.store.MockRAMDirectory;+import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;import static org.junit.Assert.*;import java.util.Collections;+import java.util.Random;import java.util.Set;import java.util.HashSet;public class TestRemoteSearchable extends RemoteTestCaseJ4 {-+ private static MockRAMDirectory indexStore;+ private static Searchable local;+@BeforeClasspublic static void beforeClass() throws Exception {// construct an index- MockRAMDirectory indexStore = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(indexStore, new IndexWriterConfig(+ Random random = newStaticRandom(TestRemoteSearchable.class);+ indexStore = newDirectory(random);+ IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new Field("test", "test text", Field.Store.YES, Field.Index.ANALYZED));@@ -46,10 +50,17 @@ public class TestRemoteSearchable extends RemoteTestCaseJ4 {writer.addDocument(doc);writer.optimize();writer.close();- Searchable local = new IndexSearcher(indexStore, true);+ local = new IndexSearcher(indexStore, true);startServer(local);}-++ @AfterClass+ public static void afterClass() throws Exception {+ local.close();+ indexStore.close();+ indexStore = null;+ }+private static void search(Query query) throws Exception {// try to search the published indexSearchable[] searchables = { lookupRemote() };diff --git a/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java b/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.javaindex 02791ae6e86..fc3a4cc2111 100644--- a/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java+++ b/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java@@ -35,6 +35,7 @@ import org.apache.lucene.index.LogMergePolicy;import org.apache.lucene.index.Term;import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.BytesRef;+import org.junit.AfterClass;import org.junit.Before;import org.junit.BeforeClass;import org.junit.Test;@@ -48,6 +49,7 @@ import org.junit.Test;public class TestRemoteSort extends RemoteTestCaseJ4 {private static IndexSearcher full;+ private static MockRAMDirectory indexStore;private Query queryX;private Query queryY;private Query queryA;@@ -82,8 +84,9 @@ public class TestRemoteSort extends RemoteTestCaseJ4 {// create an index of all the documents, or just the x, or just the y documents@BeforeClasspublic static void beforeClass() throws Exception {- MockRAMDirectory indexStore = new MockRAMDirectory ();- IndexWriter writer = new IndexWriter(indexStore, new IndexWriterConfig(+ Random random = newStaticRandom(TestRemoteSort.class);+ indexStore = newDirectory(random);+ IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(1000);@@ -111,6 +114,14 @@ public class TestRemoteSort extends RemoteTestCaseJ4 {startServer(full);}+ @AfterClass+ public static void afterClass() throws Exception {+ full.close();+ full = null;+ indexStore.close();+ indexStore = null;+ }+public String getRandomNumberString(int num, int low, int high) {StringBuilder sb = new StringBuilder();for (int i = 0; i < num; i++) {diff --git a/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java b/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.javaindex f69c10ec7a1..a62449857a6 100644--- a/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java+++ b/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java@@ -20,6 +20,7 @@ import java.io.IOException;import java.util.LinkedList;import java.util.List;import java.util.Map;+import java.util.Random;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;@@ -27,7 +28,6 @@ import org.apache.lucene.document.Field;import org.apache.lucene.document.NumericField;import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.IndexReader;-import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.Term;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.Query;@@ -49,7 +49,6 @@ import org.apache.lucene.spatial.tier.projections.CartesianTierPlotter;import org.apache.lucene.spatial.tier.projections.IProjector;import org.apache.lucene.spatial.tier.projections.SinusoidalProjector;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;public class TestCartesian extends LuceneTestCase {@@ -71,9 +70,10 @@ public class TestCartesian extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();+ Random random = newRandom();+ directory = newDirectory(random);- IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));setUpPlotter( 2, 15);@@ -81,6 +81,12 @@ public class TestCartesian extends LuceneTestCase {}+ @Override+ protected void tearDown() throws Exception {+ directory.close();+ super.tearDown();+ }+private void setUpPlotter(int base, int top) {@@ -287,6 +293,7 @@ public class TestCartesian extends LuceneTestCase {assertTrue(geo_distance >= lastDistance);lastDistance = geo_distance;}+ searcher.close();}public void testPoleFlipping() throws IOException, InvalidGeoException {@@ -383,6 +390,7 @@ public class TestCartesian extends LuceneTestCase {assertTrue(geo_distance >= lastDistance);lastDistance = geo_distance;}+ searcher.close();}public void testRange() throws IOException, InvalidGeoException {@@ -477,6 +485,7 @@ public class TestCartesian extends LuceneTestCase {lastDistance = geo_distance;}}+ searcher.close();}@@ -570,5 +579,6 @@ public class TestCartesian extends LuceneTestCase {}}+ searcher.close();}}diff --git a/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java b/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.javaindex a6dfeb27a3e..6703aaf9e45 100644--- a/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java+++ b/lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java@@ -17,13 +17,13 @@package org.apache.lucene.spatial.tier;import java.io.IOException;+import java.util.Random;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.document.NumericField;import org.apache.lucene.index.IndexWriter;-import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.Term;import org.apache.lucene.index.IndexReader;import org.apache.lucene.search.QueryWrapperFilter;@@ -44,8 +44,9 @@ public class TestDistance extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();- writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ Random random = newRandom();+ directory = newDirectory(random);+ writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));addData(writer);}@@ -53,6 +54,7 @@ public class TestDistance extends LuceneTestCase {@Overrideprotected void tearDown() throws Exception {writer.close();+ directory.close();super.tearDown();}@@ -104,6 +106,7 @@ public class TestDistance extends LuceneTestCase {for(int i=0;i<readers.length;i++) {f.getDocIdSet(readers[i]);}+ r.close();}/* these tests do not test anything, as no assertions:diff --git a/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestLuceneDictionary.java b/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestLuceneDictionary.javaindex d5af6db3b69..05058116aa8 100644--- a/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestLuceneDictionary.java+++ b/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestLuceneDictionary.java@@ -19,6 +19,7 @@ package org.apache.lucene.search.spell;import java.io.IOException;import java.util.Iterator;+import java.util.Random;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.analysis.MockTokenizer;@@ -39,17 +40,19 @@ import org.apache.lucene.util.LuceneTestCase;*/public class TestLuceneDictionary extends LuceneTestCase {- private Directory store = new MockRAMDirectory();+ private Directory store;private IndexReader indexReader = null;-+ private Random random;private LuceneDictionary ld;private Iterator<String> it;@Overrideprotected void setUp() throws Exception {super.setUp();- IndexWriter writer = new IndexWriter(store, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));+ random = newRandom();+ store = newDirectory(random);+ IndexWriter writer = new IndexWriter(store, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));Document doc;@@ -77,6 +80,14 @@ public class TestLuceneDictionary extends LuceneTestCase {writer.close();}+ @Override+ protected void tearDown() throws Exception {+ if (indexReader != null)+ indexReader.close();+ store.close();+ super.tearDown();+ }+public void testFieldNonExistent() throws IOException {try {indexReader = IndexReader.open(store, true);@@ -187,7 +198,8 @@ public class TestLuceneDictionary extends LuceneTestCase {}public void testSpellchecker() throws IOException {- SpellChecker sc = new SpellChecker(new MockRAMDirectory());+ Directory dir = newDirectory(random);+ SpellChecker sc = new SpellChecker(dir);indexReader = IndexReader.open(store, true);sc.indexDictionary(new LuceneDictionary(indexReader, "contents"));String[] suggestions = sc.suggestSimilar("Tam", 1);@@ -197,6 +209,8 @@ public class TestLuceneDictionary extends LuceneTestCase {assertEquals(1, suggestions.length);assertEquals("Jerry", suggestions[0]);indexReader.close();+ sc.close();+ dir.close();}}diff --git a/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestPlainTextDictionary.java b/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestPlainTextDictionary.javaindex fb3b081ae7c..259e91b65af 100644--- a/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestPlainTextDictionary.java+++ b/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestPlainTextDictionary.java@@ -33,13 +33,15 @@ public class TestPlainTextDictionary extends LuceneTestCase {final String LF = System.getProperty("line.separator");String input = "oneword" + LF + "twoword" + LF + "threeword";PlainTextDictionary ptd = new PlainTextDictionary(new StringReader(input));- MockRAMDirectory ramDir = new MockRAMDirectory();+ MockRAMDirectory ramDir = newDirectory(newRandom());SpellChecker spellChecker = new SpellChecker(ramDir);spellChecker.indexDictionary(ptd);String[] similar = spellChecker.suggestSimilar("treeword", 2);assertEquals(2, similar.length);assertEquals(similar[0], "threeword");assertEquals(similar[1], "twoword");+ spellChecker.close();+ ramDir.close();}}diff --git a/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestSpellChecker.java b/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestSpellChecker.javaindex e03794c1999..53268244ea6 100755--- a/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestSpellChecker.java+++ b/lucene/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestSpellChecker.java@@ -36,7 +36,6 @@ import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.store.AlreadyClosedException;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.English;import org.apache.lucene.util.LuceneTestCase;@@ -54,7 +53,7 @@ public class TestSpellChecker extends LuceneTestCase {super.setUp();//create a user index- userindex = new MockRAMDirectory();+ userindex = newDirectory(random);IndexWriter writer = new IndexWriter(userindex, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));@@ -67,9 +66,18 @@ public class TestSpellChecker extends LuceneTestCase {writer.close();searchers = Collections.synchronizedList(new ArrayList<IndexSearcher>());// create the spellChecker- spellindex = new MockRAMDirectory();+ spellindex = newDirectory(random);spellChecker = new SpellCheckerMock(spellindex);}++ @Override+ protected void tearDown() throws Exception {+ userindex.close();+ if (!spellChecker.isClosed())+ spellChecker.close();+ spellindex.close();+ super.tearDown();+ }public void testBuild() throws CorruptIndexException, IOException {@@ -99,7 +107,7 @@ public class TestSpellChecker extends LuceneTestCase {spellChecker.setAccuracy(0.5f);checkCommonSuggestions(r);checkNGramSuggestions();-+ r.close();}private void checkCommonSuggestions(IndexReader r) throws IOException {@@ -260,6 +268,7 @@ public class TestSpellChecker extends LuceneTestCase {}assertEquals(4, searchers.size());assertSearchersClosed();+ r.close();}/*@@ -311,7 +320,7 @@ public class TestSpellChecker extends LuceneTestCase {// 2. and 3. during addwordsassertEquals(iterations + 4, searchers.size());assertSearchersClosed();-+ r.close();}private void assertLastSearcherOpen(int numSearchers) {diff --git a/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java b/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.javaindex 77ee3c043e3..27fbab73815 100644--- a/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java+++ b/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java@@ -4,6 +4,7 @@ import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;+import java.util.Random;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.MockAnalyzer;@@ -58,12 +59,10 @@ public class TestParser extends LuceneTestCase {//initialize the parserbuilder=new CorePlusExtensionsParser("contents",analyzer);- //initialize the index (done once, then cached in static data for use with ALL tests)- if(dir==null)- {+ Random random = newRandom();BufferedReader d = new BufferedReader(new InputStreamReader(TestParser.class.getResourceAsStream("reuters21578.txt")));- dir=new MockRAMDirectory();- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(Version.LUCENE_24, analyzer));+ dir=newDirectory(random);+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, Version.LUCENE_24, analyzer));String line = d.readLine();while(line!=null){@@ -81,7 +80,6 @@ public class TestParser extends LuceneTestCase {}d.close();writer.close();- }reader=IndexReader.open(dir, true);searcher=new IndexSearcher(reader);@@ -94,7 +92,7 @@ public class TestParser extends LuceneTestCase {protected void tearDown() throws Exception {reader.close();searcher.close();-// dir.close();+ dir.close();super.tearDown();}public void testSimpleXML() throws ParserException, IOExceptiondiff --git a/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java b/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.javaindex d1c0c0bfe0f..0cc03346f18 100644--- a/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java+++ b/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java@@ -2,6 +2,7 @@ package org.apache.lucene.xmlparser;import java.io.IOException;import java.util.Properties;+import java.util.Random;import java.util.StringTokenizer;import javax.xml.parsers.ParserConfigurationException;@@ -44,6 +45,7 @@ public class TestQueryTemplateManager extends LuceneTestCase {CoreParser builder;Analyzer analyzer=new MockAnalyzer();private IndexSearcher searcher;+ private MockRAMDirectory dir;//A collection of documents' field values for use in our testsString docFieldValues []=@@ -141,8 +143,9 @@ public class TestQueryTemplateManager extends LuceneTestCase {//Create an index- MockRAMDirectory dir=new MockRAMDirectory();- IndexWriter w=new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));+ Random random = newRandom();+ dir=newDirectory(random);+ IndexWriter w=new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));for (int i = 0; i < docFieldValues.length; i++){w.addDocument(getDocumentFromString(docFieldValues[i]));@@ -160,6 +163,7 @@ public class TestQueryTemplateManager extends LuceneTestCase {@Overrideprotected void tearDown() throws Exception {searcher.close();+ dir.close();super.tearDown();}}diff --git a/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/builders/TestNumericRangeFilterBuilder.java b/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/builders/TestNumericRangeFilterBuilder.javaindex f3214533df3..0dba08bf690 100644--- a/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/builders/TestNumericRangeFilterBuilder.java+++ b/lucene/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/builders/TestNumericRangeFilterBuilder.java@@ -20,6 +20,7 @@ package org.apache.lucene.xmlparser.builders;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;+import java.util.Random;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;@@ -61,9 +62,9 @@ public class TestNumericRangeFilterBuilder extends LuceneTestCase {String xml = "<NumericRangeFilter fieldName='AGE' type='int' lowerTerm='-1' upperTerm='NaN'/>";Document doc = getDocumentFromString(xml);Filter filter = filterBuilder.getFilter(doc.getDocumentElement());-- MockRAMDirectory ramDir = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(ramDir, new IndexWriterConfig(TEST_VERSION_CURRENT, null));+ Random random = newRandom();+ MockRAMDirectory ramDir = newDirectory(random);+ IndexWriter writer = new IndexWriter(ramDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, null));writer.commit();try{@@ -81,6 +82,7 @@ public class TestNumericRangeFilterBuilder extends LuceneTestCase {{writer.commit();writer.close();+ ramDir.close();}}diff --git a/lucene/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java b/lucene/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.javaindex 2d5498ad42b..e4f1c66718f 100644--- a/lucene/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java+++ b/lucene/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java@@ -99,6 +99,7 @@ public class PersistentSnapshotDeletionPolicy extends SnapshotDeletionPolicy {Document doc = r.document(r.maxDoc() - 1);Field sid = doc.getField(SNAPSHOTS_ID);if (sid == null) {+ writer.close();throw new IllegalStateException("directory is not a valid snapshots store!");}doc.removeField(SNAPSHOTS_ID);@@ -106,6 +107,7 @@ public class PersistentSnapshotDeletionPolicy extends SnapshotDeletionPolicy {registerSnapshotInfo(f.name(), f.stringValue(), null);}} else if (numDocs != 0) {+ writer.close();throw new IllegalStateException("should be at most 1 document in the snapshots directory: " + numDocs);}diff --git a/lucene/src/test/org/apache/lucene/TestExternalCodecs.java b/lucene/src/test/org/apache/lucene/TestExternalCodecs.javaindex aa62754cb73..38e15e5b8f1 100644--- a/lucene/src/test/org/apache/lucene/TestExternalCodecs.java+++ b/lucene/src/test/org/apache/lucene/TestExternalCodecs.java@@ -600,10 +600,10 @@ public class TestExternalCodecs extends LuceneTestCase {public void testPerFieldCodec() throws Exception {final int NUM_DOCS = 173;-- Directory dir = new MockRAMDirectory();+ Random random = newRandom();+ Directory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir,- new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(new MyCodecs()));+ newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(new MyCodecs()));w.setMergeFactor(3);Document doc = new Document();diff --git a/lucene/src/test/org/apache/lucene/TestMergeSchedulerExternal.java b/lucene/src/test/org/apache/lucene/TestMergeSchedulerExternal.javaindex d65015837e5..bd52d9743da 100644--- a/lucene/src/test/org/apache/lucene/TestMergeSchedulerExternal.java+++ b/lucene/src/test/org/apache/lucene/TestMergeSchedulerExternal.java@@ -17,10 +17,13 @@ package org.apache.lucene;* limitations under the License.*/import java.io.IOException;+import java.util.Random;+import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.IndexWriterConfig;+import org.apache.lucene.index.LogMergePolicy;import org.apache.lucene.index.MergePolicy;import org.apache.lucene.index.ConcurrentMergeScheduler;import org.apache.lucene.analysis.MockAnalyzer;@@ -80,17 +83,20 @@ public class TestMergeSchedulerExternal extends LuceneTestCase {}public void testSubclassConcurrentMergeScheduler() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ Random random = newRandom();+ MockRAMDirectory dir = newDirectory(random);dir.failOn(new FailOnlyOnMerge());Document doc = new Document();Field idField = new Field("id", "", Field.Store.YES, Field.Index.NOT_ANALYZED);doc.add(idField);- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMergeScheduler(new MyMergeScheduler()).setMaxBufferedDocs(2).setRAMBufferSizeMB(IndexWriterConfig.DISABLE_AUTO_FLUSH));+ LogMergePolicy logMP = (LogMergePolicy) writer.getConfig().getMergePolicy();+ logMP.setMergeFactor(10);for(int i=0;i<20;i++)writer.addDocument(doc);diff --git a/lucene/src/test/org/apache/lucene/TestSearch.java b/lucene/src/test/org/apache/lucene/TestSearch.javaindex 30d0f278a95..0b8a41e8ad5 100644--- a/lucene/src/test/org/apache/lucene/TestSearch.java+++ b/lucene/src/test/org/apache/lucene/TestSearch.java@@ -18,6 +18,7 @@ package org.apache.lucene;*/import java.util.GregorianCalendar;+import java.util.Random;import java.io.PrintWriter;import java.io.StringWriter;@@ -50,9 +51,10 @@ public class TestSearch extends LuceneTestCase {* single-file formats, even if the results are wrong.*/public void testSearch() throws Exception {+ Random random = newRandom();StringWriter sw = new StringWriter();PrintWriter pw = new PrintWriter(sw, true);- doTestSearch(pw, false);+ doTestSearch(random, pw, false);pw.close();sw.close();String multiFileOutput = sw.getBuffer().toString();@@ -60,7 +62,7 @@ public class TestSearch extends LuceneTestCase {sw = new StringWriter();pw = new PrintWriter(sw, true);- doTestSearch(pw, true);+ doTestSearch(random, pw, true);pw.close();sw.close();String singleFileOutput = sw.getBuffer().toString();@@ -69,11 +71,11 @@ public class TestSearch extends LuceneTestCase {}- private void doTestSearch(PrintWriter out, boolean useCompoundFile)+ private void doTestSearch(Random random, PrintWriter out, boolean useCompoundFile)throws Exception {- Directory directory = new MockRAMDirectory();+ Directory directory = newDirectory(random);Analyzer analyzer = new MockAnalyzer();- IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer);+ IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer);LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();lmp.setUseCompoundFile(useCompoundFile);lmp.setUseCompoundDocStore(useCompoundFile);@@ -129,6 +131,7 @@ public class TestSearch extends LuceneTestCase {}}searcher.close();+ directory.close();}static long Time(int year, int month, int day) {diff --git a/lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java b/lucene/src/test/org/apache/lucene/TestSearchForDuplicates.javaindex b57dcc659cb..8c88ea1f365 100644--- a/lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java+++ b/lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java@@ -20,6 +20,7 @@ package org.apache.lucene;import java.io.IOException;import java.io.PrintWriter;import java.io.StringWriter;+import java.util.Random;import org.apache.lucene.store.*;import org.apache.lucene.document.*;@@ -58,7 +59,8 @@ public class TestSearchForDuplicates extends LuceneTestCase {public void testRun() throws Exception {StringWriter sw = new StringWriter();PrintWriter pw = new PrintWriter(sw, true);- doTest(pw, false);+ Random random = newRandom();+ doTest(random, pw, false);pw.close();sw.close();String multiFileOutput = sw.getBuffer().toString();@@ -66,7 +68,7 @@ public class TestSearchForDuplicates extends LuceneTestCase {sw = new StringWriter();pw = new PrintWriter(sw, true);- doTest(pw, true);+ doTest(random, pw, true);pw.close();sw.close();String singleFileOutput = sw.getBuffer().toString();@@ -75,10 +77,10 @@ public class TestSearchForDuplicates extends LuceneTestCase {}- private void doTest(PrintWriter out, boolean useCompoundFiles) throws Exception {- Directory directory = new MockRAMDirectory();+ private void doTest(Random random, PrintWriter out, boolean useCompoundFiles) throws Exception {+ Directory directory = newDirectory(random);Analyzer analyzer = new MockAnalyzer();- IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer);+ IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer);LogMergePolicy lmp = (LogMergePolicy) conf.getMergePolicy();lmp.setUseCompoundFile(useCompoundFiles);lmp.setUseCompoundDocStore(useCompoundFiles);@@ -125,6 +127,7 @@ public class TestSearchForDuplicates extends LuceneTestCase {checkHits(hits, MAX_DOCS, searcher);searcher.close();+ directory.close();}diff --git a/lucene/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.java b/lucene/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.javaindex b021f939b2f..217b3e166b2 100644--- a/lucene/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.java+++ b/lucene/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis;import java.io.IOException;+import java.util.Random;import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;@@ -26,20 +27,19 @@ import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.document.Field.TermVector;import org.apache.lucene.index.IndexReader;-import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.MultiFields;import org.apache.lucene.index.DocsAndPositionsEnum;import org.apache.lucene.index.RandomIndexWriter;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.BytesRef;public class TestCachingTokenFilter extends BaseTokenStreamTestCase {private String[] tokens = new String[] {"term1", "term2", "term3", "term2"};public void testCaching() throws IOException {- Directory dir = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), dir);+ Random random = newRandom();+ Directory dir = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, dir);Document doc = new Document();TokenStream stream = new TokenStream() {private int index = 0;@@ -103,6 +103,7 @@ public class TestCachingTokenFilter extends BaseTokenStreamTestCase {// 3) reset stream and consume tokens againstream.reset();checkTokens(stream);+ dir.close();}private void checkTokens(TokenStream stream) throws IOException {diff --git a/lucene/src/test/org/apache/lucene/document/TestBinaryDocument.java b/lucene/src/test/org/apache/lucene/document/TestBinaryDocument.javaindex fd1c4737273..8588f612c04 100644--- a/lucene/src/test/org/apache/lucene/document/TestBinaryDocument.java+++ b/lucene/src/test/org/apache/lucene/document/TestBinaryDocument.java@@ -1,5 +1,7 @@package org.apache.lucene.document;+import java.util.Random;+import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.index.IndexReader;@@ -55,8 +57,9 @@ public class TestBinaryDocument extends LuceneTestCase {assertEquals(2, doc.fields.size());/** add the doc to a ram index */- MockRAMDirectory dir = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), dir);+ Random random = newRandom();+ MockRAMDirectory dir = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, dir);writer.addDocument(doc);/** open a reader and fetch the document */@@ -94,8 +97,9 @@ public class TestBinaryDocument extends LuceneTestCase {doc.add(stringFldCompressed);/** add the doc to a ram index */- MockRAMDirectory dir = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), dir);+ Random random = newRandom();+ MockRAMDirectory dir = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, dir);writer.addDocument(doc);/** open a reader and fetch the document */diff --git a/lucene/src/test/org/apache/lucene/document/TestDocument.java b/lucene/src/test/org/apache/lucene/document/TestDocument.javaindex 799e18ed135..d9e7632fb72 100644--- a/lucene/src/test/org/apache/lucene/document/TestDocument.java+++ b/lucene/src/test/org/apache/lucene/document/TestDocument.java@@ -1,5 +1,7 @@package org.apache.lucene.document;+import java.util.Random;+import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.RandomIndexWriter;import org.apache.lucene.index.Term;@@ -152,8 +154,9 @@ public class TestDocument extends LuceneTestCase {* @throws Exception on error*/public void testGetValuesForIndexedDocument() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), dir);+ Random random = newRandom();+ MockRAMDirectory dir = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, dir);writer.addDocument(makeDocumentWithFields());IndexReader reader = writer.getReader();@@ -230,8 +233,9 @@ public class TestDocument extends LuceneTestCase {doc.add(new Field("keyword", "test", Field.Store.YES,Field.Index.NOT_ANALYZED));- MockRAMDirectory dir = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), dir);+ Random random = newRandom();+ MockRAMDirectory dir = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, dir);writer.addDocument(doc);field.setValue("id2");writer.addDocument(doc);diff --git a/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java b/lucene/src/test/org/apache/lucene/index/TestAddIndexes.javaindex bc0e5ee7018..c476232cff3 100755--- a/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java+++ b/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java@@ -44,10 +44,10 @@ public class TestAddIndexes extends LuceneTestCase {public void testSimpleCase() throws IOException {// main directory- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);// two auxiliary directories- Directory aux = new MockRAMDirectory();- Directory aux2 = new MockRAMDirectory();+ Directory aux = newDirectory(random);+ Directory aux2 = newDirectory(random);IndexWriter writer = null;@@ -89,7 +89,7 @@ public class TestAddIndexes extends LuceneTestCase {verifyNumDocs(dir, 190);// now add another set in.- Directory aux3 = new MockRAMDirectory();+ Directory aux3 = newDirectory(random);writer = newWriter(aux3, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));// add 40 documentsaddDocs(writer, 40);@@ -123,7 +123,7 @@ public class TestAddIndexes extends LuceneTestCase {verifyTermDocs(dir, new Term("content", "bbb"), 50);// now add a single document- Directory aux4 = new MockRAMDirectory();+ Directory aux4 = newDirectory(random);writer = newWriter(aux4, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));addDocs2(writer, 1);writer.close();@@ -137,13 +137,18 @@ public class TestAddIndexes extends LuceneTestCase {verifyNumDocs(dir, 231);verifyTermDocs(dir, new Term("content", "bbb"), 51);+ dir.close();+ aux.close();+ aux2.close();+ aux3.close();+ aux4.close();}public void testWithPendingDeletes() throws IOException {// main directory- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);// auxiliary directory- Directory aux = new MockRAMDirectory();+ Directory aux = newDirectory(random);setUpDirs(dir, aux);IndexWriter writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));@@ -178,9 +183,9 @@ public class TestAddIndexes extends LuceneTestCase {public void testWithPendingDeletes2() throws IOException {// main directory- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);// auxiliary directory- Directory aux = new MockRAMDirectory();+ Directory aux = newDirectory(random);setUpDirs(dir, aux);IndexWriter writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));@@ -216,9 +221,9 @@ public class TestAddIndexes extends LuceneTestCase {public void testWithPendingDeletes3() throws IOException {// main directory- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);// auxiliary directory- Directory aux = new MockRAMDirectory();+ Directory aux = newDirectory(random);setUpDirs(dir, aux);IndexWriter writer = newWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.APPEND));@@ -256,9 +261,9 @@ public class TestAddIndexes extends LuceneTestCase {// case 0: add self or exceed maxMergeDocs, expect exceptionpublic void testAddSelf() throws IOException {// main directory- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);// auxiliary directory- Directory aux = new MockRAMDirectory();+ Directory aux = newDirectory(random);IndexWriter writer = null;@@ -293,6 +298,8 @@ public class TestAddIndexes extends LuceneTestCase {// make sure the index is correctverifyNumDocs(dir, 100);+ dir.close();+ aux.close();}// in all the remaining tests, make the doc count of the oldest segment@@ -300,9 +307,9 @@ public class TestAddIndexes extends LuceneTestCase {// case 1: no tail segmentspublic void testNoTailSegments() throws IOException {// main directory- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);// auxiliary directory- Directory aux = new MockRAMDirectory();+ Directory aux = newDirectory(random);setUpDirs(dir, aux);@@ -319,14 +326,16 @@ public class TestAddIndexes extends LuceneTestCase {// make sure the index is correctverifyNumDocs(dir, 1040);+ dir.close();+ aux.close();}// case 2: tail segments, invariants hold, no copypublic void testNoCopySegments() throws IOException {// main directory- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);// auxiliary directory- Directory aux = new MockRAMDirectory();+ Directory aux = newDirectory(random);setUpDirs(dir, aux);@@ -341,14 +350,16 @@ public class TestAddIndexes extends LuceneTestCase {// make sure the index is correctverifyNumDocs(dir, 1032);+ dir.close();+ aux.close();}// case 3: tail segments, invariants hold, copy, invariants holdpublic void testNoMergeAfterCopy() throws IOException {// main directory- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);// auxiliary directory- Directory aux = new MockRAMDirectory();+ Directory aux = newDirectory(random);setUpDirs(dir, aux);@@ -364,14 +375,16 @@ public class TestAddIndexes extends LuceneTestCase {// make sure the index is correctverifyNumDocs(dir, 1060);+ dir.close();+ aux.close();}// case 4: tail segments, invariants hold, copy, invariants not holdpublic void testMergeAfterCopy() throws IOException {// main directory- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);// auxiliary directory- Directory aux = new MockRAMDirectory();+ Directory aux = newDirectory(random);setUpDirs(dir, aux);@@ -391,15 +404,17 @@ public class TestAddIndexes extends LuceneTestCase {assertEquals(1060, writer.maxDoc());assertEquals(1000, writer.getDocCount(0));writer.close();+ dir.close();+ aux.close();}// case 5: tail segments, invariants not holdpublic void testMoreMerges() throws IOException {// main directory- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);// auxiliary directory- Directory aux = new MockRAMDirectory();- Directory aux2 = new MockRAMDirectory();+ Directory aux = newDirectory(random);+ Directory aux2 = newDirectory(random);setUpDirs(dir, aux);@@ -434,6 +449,9 @@ public class TestAddIndexes extends LuceneTestCase {assertEquals(1060, writer.maxDoc());assertEquals(1000, writer.getDocCount(0));writer.close();+ dir.close();+ aux.close();+ aux2.close();}private IndexWriter newWriter(Directory dir, IndexWriterConfig conf)@@ -510,7 +528,7 @@ public class TestAddIndexes extends LuceneTestCase {// LUCENE-1270public void testHangOnClose() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);LogByteSizeMergePolicy lmp = new LogByteSizeMergePolicy();lmp.setUseCompoundFile(false);lmp.setUseCompoundDocStore(false);@@ -538,7 +556,7 @@ public class TestAddIndexes extends LuceneTestCase {writer.addDocument(doc2);writer.close();- Directory dir2 = new MockRAMDirectory();+ Directory dir2 = newDirectory(random);lmp = new LogByteSizeMergePolicy();lmp.setMinMergeMB(0.0001);lmp.setUseCompoundFile(false);diff --git a/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java b/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.javaindex 72f396d2e25..0d414de6096 100644--- a/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java+++ b/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java@@ -226,7 +226,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {String fullPath = fullDir(name);Directory dir = FSDirectory.open(new File(fullPath));- Directory targetDir = new MockRAMDirectory();+ Directory targetDir = newDirectory(random);IndexWriter w = new IndexWriter(targetDir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));w.addIndexes(new Directory[] { dir });@@ -235,6 +235,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {_TestUtil.checkIndex(targetDir);dir.close();+ targetDir.close();rmDir(name);}}@@ -247,7 +248,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {Directory dir = FSDirectory.open(new File(fullPath));IndexReader reader = IndexReader.open(dir);- Directory targetDir = new MockRAMDirectory();+ Directory targetDir = newDirectory(random);IndexWriter w = new IndexWriter(targetDir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));w.addIndexes(new IndexReader[] { reader });@@ -257,6 +258,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {_TestUtil.checkIndex(targetDir);dir.close();+ targetDir.close();rmDir(name);}}diff --git a/lucene/src/test/org/apache/lucene/index/TestCheckIndex.java b/lucene/src/test/org/apache/lucene/index/TestCheckIndex.javaindex ca0c6a983aa..9e41074d51c 100644--- a/lucene/src/test/org/apache/lucene/index/TestCheckIndex.java+++ b/lucene/src/test/org/apache/lucene/index/TestCheckIndex.java@@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream;import java.io.PrintStream;import java.util.List;import java.util.ArrayList;+import java.util.Random;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.store.MockRAMDirectory;@@ -33,8 +34,9 @@ import org.apache.lucene.util.Constants;public class TestCheckIndex extends LuceneTestCase {public void testDeletedDocs() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));+ Random random = newRandom();+ MockRAMDirectory dir = newDirectory(random);+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));Document doc = new Document();doc.add(new Field("field", "aaa", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));for(int i=0;i<19;i++) {@@ -87,6 +89,7 @@ public class TestCheckIndex extends LuceneTestCase {onlySegments.add("_0");assertTrue(checker.checkIndex(onlySegments).clean == true);+ dir.close();}public void testLuceneConstantVersion() throws IOException {diff --git a/lucene/src/test/org/apache/lucene/index/TestCodecs.java b/lucene/src/test/org/apache/lucene/index/TestCodecs.javaindex 30a2270c9cc..426e8939805 100644--- a/lucene/src/test/org/apache/lucene/index/TestCodecs.java+++ b/lucene/src/test/org/apache/lucene/index/TestCodecs.java@@ -278,7 +278,7 @@ public class TestCodecs extends MultiCodecTestCase {final FieldData field = new FieldData("field", fieldInfos, terms, true, false);final FieldData[] fields = new FieldData[] {field};- final Directory dir = new MockRAMDirectory();+ final Directory dir = newDirectory(RANDOM);this.write(fieldInfos, dir, fields);final SegmentInfo si = new SegmentInfo(SEGMENT, 10000, dir, false, -1, SEGMENT, false, true, CodecProvider.getDefault().getWriter(null));si.setHasProx(false);@@ -311,6 +311,8 @@ public class TestCodecs extends MultiCodecTestCase {}assertNull(fieldsEnum.next());+ reader.close();+ dir.close();}public void testRandomPostings() throws Throwable {@@ -326,7 +328,7 @@ public class TestCodecs extends MultiCodecTestCase {fields[i] = new FieldData(fieldNames[i], fieldInfos, this.makeRandomTerms(omitTF, storePayloads), omitTF, storePayloads);}- final Directory dir = new MockRAMDirectory();+ final Directory dir = newDirectory(RANDOM);this.write(fieldInfos, dir, fields);final SegmentInfo si = new SegmentInfo(SEGMENT, 10000, dir, false, -1, SEGMENT, false, true, CodecProvider.getDefault().getWriter(null));@@ -352,8 +354,9 @@ public class TestCodecs extends MultiCodecTestCase {}public void testSepPositionAfterMerge() throws IOException {- final Directory dir = new MockRAMDirectory();- final IndexWriterConfig config = newIndexWriterConfig(newRandom(), Version.LUCENE_31,+ Random random = newRandom();+ final Directory dir = newDirectory(random);+ final IndexWriterConfig config = newIndexWriterConfig(random, Version.LUCENE_31,new MockAnalyzer());config.setCodecProvider(new MockSepCodecs());final IndexWriter writer = new IndexWriter(dir, config);diff --git a/lucene/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java b/lucene/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.javaindex 8fbe81ecd09..f07a494dbbf 100644--- a/lucene/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java+++ b/lucene/src/test/org/apache/lucene/index/TestConcurrentMergeScheduler.java@@ -61,12 +61,12 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {// Make sure running BG merges still work fine even when// we are hitting exceptions during flushing.public void testFlushExceptions() throws IOException {-- MockRAMDirectory directory = new MockRAMDirectory();+ Random random = newRandom();+ MockRAMDirectory directory = newDirectory(random);FailOnlyOnFlush failure = new FailOnlyOnFlush();directory.failOn(failure);- IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));+ IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));Document doc = new Document();Field idField = new Field("id", "", Field.Store.YES, Field.Index.NOT_ANALYZED);doc.add(idField);@@ -107,15 +107,15 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {// Test that deletes committed after a merge started and// before it finishes, are correctly merged back:public void testDeleteMerging() throws IOException {-- MockRAMDirectory directory = new MockRAMDirectory();+ Random random = newRandom();+ MockRAMDirectory directory = newDirectory(random);LogDocMergePolicy mp = new LogDocMergePolicy();// Force degenerate merging so we can get a mix of// merging of segments with and without deletes at the// start:mp.setMinMergeDocs(1000);- IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(newRandom(),+ IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMergePolicy(mp));@@ -146,9 +146,8 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {}public void testNoExtraFiles() throws IOException {-- MockRAMDirectory directory = new MockRAMDirectory();Random random = newRandom();+ MockRAMDirectory directory = newDirectory(random);IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));@@ -176,8 +175,8 @@ public class TestConcurrentMergeScheduler extends LuceneTestCase {}public void testNoWaitClose() throws IOException {- MockRAMDirectory directory = new MockRAMDirectory();Random random = newRandom();+ MockRAMDirectory directory = newDirectory(random);Document doc = new Document();Field idField = new Field("id", "", Field.Store.YES, Field.Index.NOT_ANALYZED);doc.add(idField);diff --git a/lucene/src/test/org/apache/lucene/index/TestCrash.java b/lucene/src/test/org/apache/lucene/index/TestCrash.javaindex 421d86d277f..654267435d9 100644--- a/lucene/src/test/org/apache/lucene/index/TestCrash.java+++ b/lucene/src/test/org/apache/lucene/index/TestCrash.java@@ -30,7 +30,7 @@ import org.apache.lucene.document.Field;public class TestCrash extends LuceneTestCase {private IndexWriter initIndex(Random random, boolean initialCommit) throws IOException {- return initIndex(random, new MockRAMDirectory(), initialCommit);+ return initIndex(random, newDirectory(random), initialCommit);}private IndexWriter initIndex(Random random, MockRAMDirectory dir, boolean initialCommit) throws IOException {@@ -70,6 +70,8 @@ public class TestCrash extends LuceneTestCase {crash(writer);IndexReader reader = IndexReader.open(dir, false);assertTrue(reader.numDocs() < 157);+ reader.close();+ dir.close();}public void testWriterAfterCrash() throws IOException {@@ -86,6 +88,8 @@ public class TestCrash extends LuceneTestCase {IndexReader reader = IndexReader.open(dir, false);assertTrue(reader.numDocs() < 314);+ reader.close();+ dir.close();}public void testCrashAfterReopen() throws IOException {@@ -108,6 +112,8 @@ public class TestCrash extends LuceneTestCase {IndexReader reader = IndexReader.open(dir, false);assertTrue(reader.numDocs() >= 157);+ reader.close();+ dir.close();}public void testCrashAfterClose() throws IOException {@@ -127,6 +133,8 @@ public class TestCrash extends LuceneTestCase {IndexReader reader = IndexReader.open(dir, false);assertEquals(157, reader.numDocs());+ reader.close();+ dir.close();}public void testCrashAfterCloseNoWait() throws IOException {@@ -146,6 +154,8 @@ public class TestCrash extends LuceneTestCase {*/IndexReader reader = IndexReader.open(dir, false);assertEquals(157, reader.numDocs());+ reader.close();+ dir.close();}public void testCrashReaderDeletes() throws IOException {@@ -167,6 +177,8 @@ public class TestCrash extends LuceneTestCase {*/reader = IndexReader.open(dir, false);assertEquals(157, reader.numDocs());+ reader.close();+ dir.close();}public void testCrashReaderDeletesAfterClose() throws IOException {@@ -189,5 +201,7 @@ public class TestCrash extends LuceneTestCase {*/reader = IndexReader.open(dir, false);assertEquals(156, reader.numDocs());+ reader.close();+ dir.close();}}diff --git a/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java b/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.javaindex b413e5c70dd..a614c5cb0ea 100644--- a/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java+++ b/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java@@ -202,7 +202,7 @@ public class TestDeletionPolicy extends LuceneTestCase {boolean useCompoundFile = true;Random random = newRandom();- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);ExpirationTimeDeletionPolicy policy = new ExpirationTimeDeletionPolicy(dir, SECONDS);IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT,new MockAnalyzer())@@ -282,7 +282,7 @@ public class TestDeletionPolicy extends LuceneTestCase {// Never deletes a commitKeepAllDeletionPolicy policy = new KeepAllDeletionPolicy();- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);policy.dir = dir;IndexWriterConfig conf = newIndexWriterConfig(random,@@ -365,7 +365,7 @@ public class TestDeletionPolicy extends LuceneTestCase {// Never deletes a commitKeepAllDeletionPolicy policy = new KeepAllDeletionPolicy();- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);policy.dir = dir;IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,@@ -474,7 +474,7 @@ public class TestDeletionPolicy extends LuceneTestCase {KeepNoneOnInitDeletionPolicy policy = new KeepNoneOnInitDeletionPolicy();- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriterConfig conf = newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer())@@ -523,7 +523,7 @@ public class TestDeletionPolicy extends LuceneTestCase {boolean useCompoundFile = (pass % 2) != 0;- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(N);@@ -588,7 +588,7 @@ public class TestDeletionPolicy extends LuceneTestCase {KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(N);- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriterConfig conf = newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy);@@ -697,7 +697,7 @@ public class TestDeletionPolicy extends LuceneTestCase {KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(N);- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriterConfig conf = newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE).setIndexDeletionPolicy(policy)diff --git a/lucene/src/test/org/apache/lucene/index/TestDirectoryReader.java b/lucene/src/test/org/apache/lucene/index/TestDirectoryReader.javaindex 84cb8c9401d..a5d49f81029 100644--- a/lucene/src/test/org/apache/lucene/index/TestDirectoryReader.java+++ b/lucene/src/test/org/apache/lucene/index/TestDirectoryReader.java@@ -36,6 +36,7 @@ public class TestDirectoryReader extends LuceneTestCase {private Document doc2;protected SegmentReader [] readers = new SegmentReader[2];protected SegmentInfos sis;+ private Random random;public TestDirectoryReader(String s) {@@ -45,7 +46,8 @@ public class TestDirectoryReader extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- dir = new MockRAMDirectory();+ random = newRandom();+ dir = newDirectory(random);doc1 = new Document();doc2 = new Document();DocHelper.setupDoc(doc1);@@ -55,6 +57,14 @@ public class TestDirectoryReader extends LuceneTestCase {sis = new SegmentInfos();sis.read(dir);}++ @Override+ protected void tearDown() throws Exception {+ if (readers[0] != null) readers[0].close();+ if (readers[1] != null) readers[1].close();+ dir.close();+ super.tearDown();+ }protected IndexReader openReader() throws IOException {IndexReader reader;@@ -86,6 +96,7 @@ public class TestDirectoryReader extends LuceneTestCase {TermFreqVector vector = reader.getTermFreqVector(0, DocHelper.TEXT_FIELD_2_KEY);assertTrue(vector != null);TestSegmentReader.checkNorms(reader);+ reader.close();}public void doTestUndeleteAll() throws IOException {@@ -122,13 +133,13 @@ public class TestDirectoryReader extends LuceneTestCase {sis.read(dir);reader = openReader();assertEquals( 1, reader.numDocs() );+ reader.close();}public void testIsCurrent() throws IOException {- Random random = newRandom();- MockRAMDirectory ramDir1=new MockRAMDirectory();+ MockRAMDirectory ramDir1=newDirectory(random);addDoc(random, ramDir1, "test foo", true);- MockRAMDirectory ramDir2=new MockRAMDirectory();+ MockRAMDirectory ramDir2=newDirectory(random);addDoc(random, ramDir2, "test blah", true);IndexReader[] readers = new IndexReader[]{IndexReader.open(ramDir1, false), IndexReader.open(ramDir2, false)};MultiReader mr = new MultiReader(readers);@@ -144,15 +155,16 @@ public class TestDirectoryReader extends LuceneTestCase {// expected exception}mr.close();+ ramDir1.close();+ ramDir2.close();}public void testMultiTermDocs() throws IOException {- Random random = newRandom();- MockRAMDirectory ramDir1=new MockRAMDirectory();+ MockRAMDirectory ramDir1=newDirectory(random);addDoc(random, ramDir1, "test foo", true);- MockRAMDirectory ramDir2=new MockRAMDirectory();+ MockRAMDirectory ramDir2=newDirectory(random);addDoc(random, ramDir2, "test blah", true);- MockRAMDirectory ramDir3=new MockRAMDirectory();+ MockRAMDirectory ramDir3=newDirectory(random);addDoc(random, ramDir3, "test wow", true);IndexReader[] readers1 = new IndexReader[]{IndexReader.open(ramDir1, false), IndexReader.open(ramDir3, false)};@@ -182,6 +194,14 @@ public class TestDirectoryReader extends LuceneTestCase {// really a dummy assert to ensure that we got some docs and to ensure that// nothing is optimized out.assertTrue(ret > 0);+ readers1[0].close();+ readers1[1].close();+ readers2[0].close();+ readers2[1].close();+ readers2[2].close();+ ramDir1.close();+ ramDir2.close();+ ramDir3.close();}private void addDoc(Random random, MockRAMDirectory ramDir1, String s, boolean create) throws IOException {diff --git a/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java b/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.javaindex c4eaa109555..b5d8b330d07 100644--- a/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java+++ b/lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java@@ -19,6 +19,7 @@ package org.apache.lucene.index;import java.io.IOException;import java.io.Reader;+import java.util.Random;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.MockAnalyzer;@@ -42,7 +43,8 @@ import org.apache.lucene.util.BytesRef;public class TestDocumentWriter extends LuceneTestCase {private MockRAMDirectory dir;-+ private Random random;+public TestDocumentWriter(String s) {super(s);}@@ -50,7 +52,14 @@ public class TestDocumentWriter extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- dir = new MockRAMDirectory();+ random = newRandom();+ dir = newDirectory(random);+ }++ @Override+ protected void tearDown() throws Exception {+ dir.close();+ super.tearDown();}public void test() {@@ -60,7 +69,7 @@ public class TestDocumentWriter extends LuceneTestCase {public void testAddDocument() throws Exception {Document testDoc = new Document();DocHelper.setupDoc(testDoc);- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT, new MockAnalyzer()));+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));writer.addDocument(testDoc);writer.commit();SegmentInfo info = writer.newestSegment();@@ -102,6 +111,7 @@ public class TestDocumentWriter extends LuceneTestCase {assertTrue(fi.omitNorms == !reader.hasNorms(fi.name));}}+ reader.close();}public void testPositionIncrementGap() throws IOException {@@ -117,7 +127,7 @@ public class TestDocumentWriter extends LuceneTestCase {}};- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT, analyzer));+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));Document doc = new Document();doc.add(new Field("repeated", "repeated one", Field.Store.YES, Field.Index.ANALYZED));@@ -136,6 +146,7 @@ public class TestDocumentWriter extends LuceneTestCase {assertEquals(2, freq);assertEquals(0, termPositions.nextPosition());assertEquals(502, termPositions.nextPosition());+ reader.close();}public void testTokenReuse() throws IOException {@@ -181,7 +192,7 @@ public class TestDocumentWriter extends LuceneTestCase {}};- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT, analyzer));+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));Document doc = new Document();doc.add(new Field("f1", "a 5 a a", Field.Store.YES, Field.Index.ANALYZED));@@ -202,11 +213,12 @@ public class TestDocumentWriter extends LuceneTestCase {assertEquals(false, termPositions.hasPayload());assertEquals(7, termPositions.nextPosition());assertEquals(false, termPositions.hasPayload());+ reader.close();}public void testPreAnalyzedField() throws IOException {- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(),+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();@@ -250,7 +262,7 @@ public class TestDocumentWriter extends LuceneTestCase {assertTrue(termPositions.nextDoc() != termPositions.NO_MORE_DOCS);assertEquals(1, termPositions.freq());assertEquals(2, termPositions.nextPosition());-+ reader.close();}/**@@ -266,7 +278,7 @@ public class TestDocumentWriter extends LuceneTestCase {doc.add(new Field("f2", "v1", Store.YES, Index.NOT_ANALYZED, TermVector.WITH_POSITIONS_OFFSETS));doc.add(new Field("f2", "v2", Store.YES, Index.NOT_ANALYZED, TermVector.NO));- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(),+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));writer.addDocument(doc);writer.close();@@ -282,6 +294,7 @@ public class TestDocumentWriter extends LuceneTestCase {TermFreqVector tfv2 = reader.getTermFreqVector(0, "f2");assertNotNull(tfv2);assertEquals("the 'with_tv' setting should rule!",2,tfv2.getTerms().length);+ reader.close();}/**@@ -300,7 +313,7 @@ public class TestDocumentWriter extends LuceneTestCase {doc.add(f);doc.add(new Field("f2", "v2", Store.YES, Index.NO));- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(),+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));writer.addDocument(doc);writer.optimize(); // be sure to have a single segment@@ -316,5 +329,6 @@ public class TestDocumentWriter extends LuceneTestCase {// f2assertTrue("f2 should have norms", reader.hasNorms("f2"));assertTrue("omitTermFreqAndPositions field bit should be set for f2", fi.fieldInfo("f2").omitTermFreqAndPositions);+ reader.close();}}diff --git a/lucene/src/test/org/apache/lucene/index/TestFieldInfos.java b/lucene/src/test/org/apache/lucene/index/TestFieldInfos.javaindex 088a8519777..7b6e5e40b22 100644--- a/lucene/src/test/org/apache/lucene/index/TestFieldInfos.java+++ b/lucene/src/test/org/apache/lucene/index/TestFieldInfos.java@@ -47,7 +47,7 @@ public class TestFieldInfos extends LuceneTestCase {fieldInfos.add(testDoc);//Since the complement is stored as well in the fields mapassertTrue(fieldInfos.size() == DocHelper.all.size()); //this is all b/c we are using the no-arg constructor- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(newRandom());String name = "testFile";IndexOutput output = dir.createOutput(name);assertTrue(output != null);diff --git a/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java b/lucene/src/test/org/apache/lucene/index/TestFieldsReader.javaindex 6f4ac43a44c..dfd7635d611 100644--- a/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java+++ b/lucene/src/test/org/apache/lucene/index/TestFieldsReader.java@@ -45,7 +45,7 @@ import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util._TestUtil;public class TestFieldsReader extends LuceneTestCase {- private MockRAMDirectory dir = new MockRAMDirectory();+ private MockRAMDirectory dir;private Document testDoc = new Document();private FieldInfos fieldInfos = null;private Random random;@@ -62,6 +62,7 @@ public class TestFieldsReader extends LuceneTestCase {DocHelper.setupDoc(testDoc);fieldInfos.add(testDoc);random = newRandom();+ dir = newDirectory(random);IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer());((LogMergePolicy) conf.getMergePolicy()).setUseCompoundFile(false);((LogMergePolicy) conf.getMergePolicy()).setUseCompoundDocStore(false);@@ -70,6 +71,11 @@ public class TestFieldsReader extends LuceneTestCase {writer.close();}+ @Override+ protected void tearDown() throws Exception {+ dir.close();+ super.tearDown();+ }public void test() throws IOException {assertTrue(dir != null);assertTrue(fieldInfos != null);@@ -157,6 +163,7 @@ public class TestFieldsReader extends LuceneTestCase {assertTrue("byte[" + i + "] is mismatched", bytes[i] == DocHelper.LAZY_FIELD_BINARY_BYTES[i]);}+ reader.close();}public void testLatentFields() throws Exception {@@ -226,6 +233,7 @@ public class TestFieldsReader extends LuceneTestCase {assertTrue("byte[" + i + "] is mismatched", bytes[i] == DocHelper.LAZY_FIELD_BINARY_BYTES[i]);}+ reader.close();}@@ -278,6 +286,7 @@ public class TestFieldsReader extends LuceneTestCase {count++;}assertTrue(count + " does not equal: " + 1, count == 1);+ reader.close();}/**diff --git a/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java b/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.javaindex b6e597e101a..9f8b67edb33 100644--- a/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java+++ b/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java@@ -132,7 +132,7 @@ public class TestFilterIndexReader extends LuceneTestCase {*/public void testFilterIndexReader() throws Exception {Random random = newRandom();- MockRAMDirectory directory = new MockRAMDirectory();+ MockRAMDirectory directory = newDirectory(random);IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document d1 = new Document();@@ -150,7 +150,7 @@ public class TestFilterIndexReader extends LuceneTestCase {writer.close();//IndexReader reader = new TestReader(IndexReader.open(directory, true));- MockRAMDirectory target = new MockRAMDirectory();+ MockRAMDirectory target = newDirectory(random);writer = new IndexWriter(target, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));IndexReader reader = new TestReader(IndexReader.open(directory, true));writer.addIndexes(reader);@@ -176,5 +176,6 @@ public class TestFilterIndexReader extends LuceneTestCase {reader.close();directory.close();+ target.close();}}diff --git a/lucene/src/test/org/apache/lucene/index/TestFlex.java b/lucene/src/test/org/apache/lucene/index/TestFlex.javaindex 26073cdb055..ef8047fef2e 100644--- a/lucene/src/test/org/apache/lucene/index/TestFlex.java+++ b/lucene/src/test/org/apache/lucene/index/TestFlex.java@@ -31,7 +31,7 @@ public class TestFlex extends LuceneTestCase {// Test non-flex API emulated on flex indexpublic void testNonFlex() throws Exception {- Directory d = new MockRAMDirectory();+ Directory d = newDirectory(newRandom());final int DOC_COUNT = 177;@@ -65,8 +65,9 @@ public class TestFlex extends LuceneTestCase {}public void testTermOrd() throws Exception {- Directory d = new MockRAMDirectory();- IndexWriter w = new IndexWriter(d, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT,+ Random random = newRandom();+ Directory d = newDirectory(random);+ IndexWriter w = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT,new MockAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));Document doc = new Document();doc.add(new Field("f", "a b c", Field.Store.NO, Field.Index.ANALYZED));diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexCommit.java b/lucene/src/test/org/apache/lucene/index/TestIndexCommit.javaindex c920e99f5e9..1354bbd37c0 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexCommit.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexCommit.java@@ -24,7 +24,6 @@ import java.util.Collection;import java.util.Map;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCaseJ4;import org.junit.Test;@@ -33,7 +32,7 @@ public class TestIndexCommit extends LuceneTestCaseJ4 {@Testpublic void testEqualsHashCode() throws Exception {// LUCENE-2417: equals and hashCode() impl was inconsistent- final Directory dir = new MockRAMDirectory();+ final Directory dir = newDirectory(newRandom());IndexCommit ic1 = new IndexCommit() {@Override public String getSegmentsFileName() { return "a"; }@@ -63,5 +62,6 @@ public class TestIndexCommit extends LuceneTestCaseJ4 {assertEquals(ic1, ic2);assertEquals("hash codes are not equals", ic1.hashCode(), ic2.hashCode());+ dir.close();}}diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java b/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.javaindex 326f633028f..31474b42e8c 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexFileDeleter.java@@ -39,7 +39,7 @@ public class TestIndexFileDeleter extends LuceneTestCase {public void testDeleteLeftoverFiles() throws IOException {Random random = newRandom();- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);dir.setPreventDoubleWrite(false);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer())diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexReader.java b/lucene/src/test/org/apache/lucene/index/TestIndexReader.javaindex d5eb9837b78..bd1f987a6cb 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexReader.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexReader.java@@ -53,7 +53,6 @@ import org.apache.lucene.store.FSDirectory;import org.apache.lucene.store.LockObtainFailedException;import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.store.NoSuchDirectoryException;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util._TestUtil;import org.apache.lucene.util.BytesRef;@@ -83,7 +82,7 @@ public class TestIndexReader extends LuceneTestCase}public void testCommitUserData() throws Exception {- MockRAMDirectory d = new MockRAMDirectory();+ MockRAMDirectory d = newDirectory(random);Map<String,String> commitUserData = new HashMap<String,String>();commitUserData.put("foo", "fighters");@@ -138,7 +137,7 @@ public class TestIndexReader extends LuceneTestCase}public void testIsCurrent() throws Exception {- MockRAMDirectory d = new MockRAMDirectory();+ MockRAMDirectory d = newDirectory(random);IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));addDocumentWithFields(writer);@@ -167,7 +166,7 @@ public class TestIndexReader extends LuceneTestCase* @throws Exception on error*/public void testGetFieldNames() throws Exception {- MockRAMDirectory d = new MockRAMDirectory();+ MockRAMDirectory d = newDirectory(random);// set up writerIndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));@@ -259,7 +258,7 @@ public class TestIndexReader extends LuceneTestCase}public void testTermVectors() throws Exception {- MockRAMDirectory d = new MockRAMDirectory();+ MockRAMDirectory d = newDirectory(random);// set up writerIndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));@@ -289,7 +288,8 @@ public class TestIndexReader extends LuceneTestCaseassertTrue("entry is null and it shouldn't be", entry != null);if (VERBOSE) System.out.println("Entry: " + entry);}-+ reader.close();+ d.close();}private void assertTermDocsCount(String msg,@@ -312,7 +312,7 @@ public class TestIndexReader extends LuceneTestCase}public void testBasicDelete() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = null;IndexReader reader = null;@@ -356,7 +356,7 @@ public class TestIndexReader extends LuceneTestCase}public void testBinaryFields() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);byte[] bin = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));@@ -421,12 +421,13 @@ public class TestIndexReader extends LuceneTestCaseassertEquals(bin[i], data1[i + b1.getBinaryOffset()]);}reader.close();+ dir.close();}// Make sure attempts to make changes after reader is// closed throws IOException:public void testChangesAfterClose() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = null;IndexReader reader = null;@@ -465,11 +466,12 @@ public class TestIndexReader extends LuceneTestCase} catch (AlreadyClosedException e) {// expected}+ dir.close();}// Make sure we get lock obtain failed exception with 2 writers:public void testLockObtainFailed() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);Term searchTerm = new Term("content", "aaa");@@ -506,6 +508,7 @@ public class TestIndexReader extends LuceneTestCase}writer.close();reader.close();+ dir.close();}// Make sure you can set norms & commit even if a reader@@ -556,7 +559,7 @@ public class TestIndexReader extends LuceneTestCase// Make sure you can set norms & commit, and there are// no extra norms files left:public void testWritingNormsNoReader() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = null;IndexReader reader = null;Term searchTerm = new Term("content", "aaa");@@ -728,7 +731,7 @@ public class TestIndexReader extends LuceneTestCasetry {final Directory dir;if (0 == i)- dir = new MockRAMDirectory();+ dir = newDirectory(random);elsedir = getDirectory();assertFalse(IndexReader.indexExists(dir));@@ -764,7 +767,7 @@ public class TestIndexReader extends LuceneTestCase}public void testVersion() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);assertFalse(IndexReader.indexExists(dir));IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));addDocumentWithFields(writer);@@ -787,7 +790,7 @@ public class TestIndexReader extends LuceneTestCase}public void testLock() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));addDocumentWithFields(writer);writer.close();@@ -807,7 +810,7 @@ public class TestIndexReader extends LuceneTestCase}public void testUndeleteAll() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));addDocumentWithFields(writer);addDocumentWithFields(writer);@@ -824,7 +827,7 @@ public class TestIndexReader extends LuceneTestCase}public void testUndeleteAllAfterClose() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));addDocumentWithFields(writer);addDocumentWithFields(writer);@@ -841,7 +844,7 @@ public class TestIndexReader extends LuceneTestCase}public void testUndeleteAllAfterCloseThenReopen() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));addDocumentWithFields(writer);addDocumentWithFields(writer);@@ -878,7 +881,7 @@ public class TestIndexReader extends LuceneTestCaseint END_COUNT = 144;// First build up a starting index:- MockRAMDirectory startDir = new MockRAMDirectory();+ MockRAMDirectory startDir = newDirectory(random);IndexWriter writer = new IndexWriter(startDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));for(int i=0;i<157;i++) {Document d = new Document();@@ -1052,7 +1055,7 @@ public class TestIndexReader extends LuceneTestCase}public void testDocsOutOfOrderJIRA140() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));for(int i=0;i<11;i++) {addDoc(writer, "aaa");@@ -1092,7 +1095,7 @@ public class TestIndexReader extends LuceneTestCasepublic void testExceptionReleaseWriteLockJIRA768() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));addDoc(writer, "aaa");writer.close();@@ -1381,7 +1384,7 @@ public class TestIndexReader extends LuceneTestCasepublic void testGetIndexCommit() throws IOException {- MockRAMDirectory d = new MockRAMDirectory();+ MockRAMDirectory d = newDirectory(random);// set up writerIndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random,@@ -1430,7 +1433,7 @@ public class TestIndexReader extends LuceneTestCase}public void testReadOnly() throws Throwable {- MockRAMDirectory d = new MockRAMDirectory();+ MockRAMDirectory d = newDirectory(random);IndexWriter writer = new IndexWriter(d, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));addDocumentWithFields(writer);@@ -1493,12 +1496,13 @@ public class TestIndexReader extends LuceneTestCasewriter.close();r3.close();+ d.close();}// LUCENE-1474public void testIndexReader() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));writer.addDocument(createDocument("a"));@@ -1511,11 +1515,12 @@ public class TestIndexReader extends LuceneTestCasereader.deleteDocuments(new Term("id", "b"));reader.close();IndexReader.open(dir,true).close();+ dir.close();}// LUCENE-1647public void testIndexReaderUnDeleteAll() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);dir.setPreventDoubleWrite(false);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));@@ -1557,7 +1562,7 @@ public class TestIndexReader extends LuceneTestCase// LUCENE-1509public void testNoDupCommitFileNames() throws Throwable {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer())@@ -1583,7 +1588,7 @@ public class TestIndexReader extends LuceneTestCase// LUCENE-1579: Ensure that on a cloned reader, segments// reuse the doc values arrays in FieldCachepublic void testFieldCacheReuseAfterClone() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new Field("number", "17", Field.Store.NO, Field.Index.NOT_ANALYZED));@@ -1614,7 +1619,7 @@ public class TestIndexReader extends LuceneTestCase// shared segments reuse the doc values arrays in// FieldCachepublic void testFieldCacheReuseAfterReopen() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new Field("number", "17", Field.Store.NO, Field.Index.NOT_ANALYZED));@@ -1647,7 +1652,7 @@ public class TestIndexReader extends LuceneTestCase// LUCENE-1579: Make sure all SegmentReaders are new when// reopen switches readOnlypublic void testReopenChangeReadonly() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(-1));((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(10);Document doc = new Document();@@ -1689,7 +1694,7 @@ public class TestIndexReader extends LuceneTestCase// LUCENE-1586: getUniqueTermCountpublic void testUniqueTermCount() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));Document doc = new Document();doc.add(new Field("field", "a b c d e f g h i j k l m n o p q r s t u v w x y z", Field.Store.NO, Field.Index.ANALYZED));@@ -1722,7 +1727,7 @@ public class TestIndexReader extends LuceneTestCase// LUCENE-1609: don't load terms indexpublic void testNoTermsIndex() throws Throwable {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));Document doc = new Document();doc.add(new Field("field", "a b c d e f g h i j k l m n o p q r s t u v w x y z", Field.Store.NO, Field.Index.ANALYZED));@@ -1758,11 +1763,13 @@ public class TestIndexReader extends LuceneTestCase// expected}}+ r2.close();+ dir.close();}// LUCENE-2046public void testPrepareCommitIsCurrent() throws Throwable {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));writer.commit();diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java b/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.javaindex f5a8a7cacdb..b2a1f072628 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexReaderClone.java@@ -44,7 +44,7 @@ public class TestIndexReaderClone extends LuceneTestCase {}public void testCloneReadOnlySegmentReader() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, false);IndexReader reader = IndexReader.open(dir1, false);@@ -63,7 +63,7 @@ public class TestIndexReaderClone extends LuceneTestCase {// open non-readOnly reader1, clone to non-readOnly// reader2, make sure we can change reader2public void testCloneNoChangesStillReadOnly() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, true);IndexReader r1 = IndexReader.open(dir1, false);@@ -79,7 +79,7 @@ public class TestIndexReaderClone extends LuceneTestCase {// open non-readOnly reader1, clone to non-readOnly// reader2, make sure we can change reader1public void testCloneWriteToOrig() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, true);IndexReader r1 = IndexReader.open(dir1, false);@@ -95,7 +95,7 @@ public class TestIndexReaderClone extends LuceneTestCase {// open non-readOnly reader1, clone to non-readOnly// reader2, make sure we can change reader2public void testCloneWriteToClone() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, true);IndexReader r1 = IndexReader.open(dir1, false);@@ -118,7 +118,7 @@ public class TestIndexReaderClone extends LuceneTestCase {// SegmentReader, add docs, reopen to multireader, then do// deletepublic void testReopenSegmentReaderToMultiReader() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, false);IndexReader reader1 = IndexReader.open(dir1, false);@@ -136,7 +136,7 @@ public class TestIndexReaderClone extends LuceneTestCase {// open non-readOnly reader1, clone to readOnly reader2public void testCloneWriteableToReadOnly() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, true);IndexReader reader = IndexReader.open(dir1, false);@@ -158,7 +158,7 @@ public class TestIndexReaderClone extends LuceneTestCase {// open non-readOnly reader1, reopen to readOnly reader2public void testReopenWriteableToReadOnly() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, true);IndexReader reader = IndexReader.open(dir1, false);@@ -179,7 +179,7 @@ public class TestIndexReaderClone extends LuceneTestCase {// open readOnly reader1, clone to non-readOnly reader2public void testCloneReadOnlyToWriteable() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, true);IndexReader reader1 = IndexReader.open(dir1, true);@@ -202,7 +202,7 @@ public class TestIndexReaderClone extends LuceneTestCase {// open non-readOnly reader1 on multi-segment index, then// optimize the index, then clone to readOnly reader2public void testReadOnlyCloneAfterOptimize() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, true);IndexReader reader1 = IndexReader.open(dir1, false);@@ -229,7 +229,7 @@ public class TestIndexReaderClone extends LuceneTestCase {}public void testCloneReadOnlyDirectoryReader() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, true);IndexReader reader = IndexReader.open(dir1, false);@@ -250,9 +250,9 @@ public class TestIndexReaderClone extends LuceneTestCase {}public void testParallelReader() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, true);- final Directory dir2 = new MockRAMDirectory();+ final Directory dir2 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir2, true);IndexReader r1 = IndexReader.open(dir1, false);IndexReader r2 = IndexReader.open(dir2, false);@@ -300,9 +300,9 @@ public class TestIndexReaderClone extends LuceneTestCase {}public void testMixedReaders() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, true);- final Directory dir2 = new MockRAMDirectory();+ final Directory dir2 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir2, true);IndexReader r1 = IndexReader.open(dir1, false);IndexReader r2 = IndexReader.open(dir2, false);@@ -315,7 +315,7 @@ public class TestIndexReaderClone extends LuceneTestCase {}public void testSegmentReaderUndeleteall() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, false);SegmentReader origSegmentReader = SegmentReader.getOnlySegmentReader(dir1);origSegmentReader.deleteDocument(10);@@ -328,7 +328,7 @@ public class TestIndexReaderClone extends LuceneTestCase {}public void testSegmentReaderCloseReferencing() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, false);SegmentReader origSegmentReader = SegmentReader.getOnlySegmentReader(dir1);origSegmentReader.deleteDocument(1);@@ -347,7 +347,7 @@ public class TestIndexReaderClone extends LuceneTestCase {}public void testSegmentReaderDelDocsReferenceCounting() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, false);IndexReader origReader = IndexReader.open(dir1, false);@@ -410,7 +410,7 @@ public class TestIndexReaderClone extends LuceneTestCase {// LUCENE-1648public void testCloneWithDeletes() throws Throwable {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, false);IndexReader origReader = IndexReader.open(dir1, false);origReader.deleteDocument(1);@@ -427,7 +427,7 @@ public class TestIndexReaderClone extends LuceneTestCase {// LUCENE-1648public void testCloneWithSetNorm() throws Throwable {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, false);IndexReader orig = IndexReader.open(dir1, false);orig.setNorm(1, "field1", 17.0f);@@ -456,7 +456,7 @@ public class TestIndexReaderClone extends LuceneTestCase {}public void testCloneSubreaders() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, true);IndexReader reader = IndexReader.open(dir1, false);@@ -476,7 +476,7 @@ public class TestIndexReaderClone extends LuceneTestCase {}public void testLucene1516Bug() throws Exception {- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);TestIndexReaderReopen.createIndex(random, dir1, false);IndexReader r1 = IndexReader.open(dir1, false);r1.incRef();@@ -493,7 +493,7 @@ public class TestIndexReaderClone extends LuceneTestCase {}public void testCloseStoredFields() throws Exception {- final Directory dir = new MockRAMDirectory();+ final Directory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));((LogMergePolicy) w.getConfig().getMergePolicy()).setUseCompoundFile(false);diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java b/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.javaindex eff2563a73b..9e2d206aa65 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexReaderCloneNorms.java@@ -35,7 +35,6 @@ import org.apache.lucene.search.DefaultSimilarity;import org.apache.lucene.search.Similarity;import org.apache.lucene.store.Directory;import org.apache.lucene.store.FSDirectory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;/**@@ -166,8 +165,9 @@ public class TestIndexReaderCloneNorms extends LuceneTestCase {}public void testNormsClose() throws IOException {- Directory dir1 = new MockRAMDirectory();- TestIndexReaderReopen.createIndex(newRandom(), dir1, false);+ Random random = newRandom();+ Directory dir1 = newDirectory(random);+ TestIndexReaderReopen.createIndex(random, dir1, false);SegmentReader reader1 = SegmentReader.getOnlySegmentReader(dir1);reader1.norms("field1");Norm r1norm = reader1.norms.get("field1");@@ -182,8 +182,9 @@ public class TestIndexReaderCloneNorms extends LuceneTestCase {}public void testNormsRefCounting() throws IOException {- Directory dir1 = new MockRAMDirectory();- TestIndexReaderReopen.createIndex(newRandom(), dir1, false);+ Random random = newRandom();+ Directory dir1 = newDirectory(random);+ TestIndexReaderReopen.createIndex(random, dir1, false);IndexReader reader1 = IndexReader.open(dir1, false);IndexReader reader2C = (IndexReader) reader1.clone();diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java b/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.javaindex 270269b457d..e7adb6288a1 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexReaderReopen.java@@ -41,7 +41,6 @@ import org.apache.lucene.search.ScoreDoc;import org.apache.lucene.search.TermQuery;import org.apache.lucene.store.Directory;import org.apache.lucene.store.FSDirectory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.store.AlreadyClosedException;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.BitVector;@@ -51,8 +50,8 @@ public class TestIndexReaderReopen extends LuceneTestCase {private File indexDir;public void testReopen() throws Exception {- final Directory dir1 = new MockRAMDirectory();Random random = newRandom();+ final Directory dir1 = newDirectory(random);createIndex(random, dir1, false);performDefaultTests(new TestReopen() {@@ -70,7 +69,7 @@ public class TestIndexReaderReopen extends LuceneTestCase {});dir1.close();- final Directory dir2 = new MockRAMDirectory();+ final Directory dir2 = newDirectory(random);createIndex(random, dir2, true);performDefaultTests(new TestReopen() {@@ -91,9 +90,9 @@ public class TestIndexReaderReopen extends LuceneTestCase {public void testParallelReaderReopen() throws Exception {Random random = newRandom();- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);createIndex(random, dir1, true);- final Directory dir2 = new MockRAMDirectory();+ final Directory dir2 = newDirectory(random);createIndex(random, dir2, true);performDefaultTests(new TestReopen() {@@ -116,9 +115,9 @@ public class TestIndexReaderReopen extends LuceneTestCase {dir1.close();dir2.close();- final Directory dir3 = new MockRAMDirectory();+ final Directory dir3 = newDirectory(random);createIndex(random, dir3, true);- final Directory dir4 = new MockRAMDirectory();+ final Directory dir4 = newDirectory(random);createIndex(random, dir4, true);performTestsWithExceptionInReopen(new TestReopen() {@@ -161,13 +160,16 @@ public class TestIndexReaderReopen extends LuceneTestCase {dir.close();}public void testCommitReopenRAM () throws IOException {- Directory dir = new MockRAMDirectory();- doTestReopenWithCommit(newRandom(), dir, true);+ Random random = newRandom();+ Directory dir = newDirectory(random);+ doTestReopenWithCommit(random, dir, true);dir.close();}public void testCommitRecreateRAM () throws IOException {- Directory dir = new MockRAMDirectory();- doTestReopenWithCommit(newRandom(), dir, false);+ Random random = newRandom();+ Directory dir = newDirectory(random);+ doTestReopenWithCommit(random, dir, false);+ dir.close();}private void doTestReopenWithCommit (Random random, Directory dir, boolean withReopen) throws IOException {@@ -216,10 +218,10 @@ public class TestIndexReaderReopen extends LuceneTestCase {public void testMultiReaderReopen() throws Exception {Random random = newRandom();- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);createIndex(random, dir1, true);- final Directory dir2 = new MockRAMDirectory();+ final Directory dir2 = newDirectory(random);createIndex(random, dir2, true);performDefaultTests(new TestReopen() {@@ -242,10 +244,10 @@ public class TestIndexReaderReopen extends LuceneTestCase {dir1.close();dir2.close();- final Directory dir3 = new MockRAMDirectory();+ final Directory dir3 = newDirectory(random);createIndex(random, dir3, true);- final Directory dir4 = new MockRAMDirectory();+ final Directory dir4 = newDirectory(random);createIndex(random, dir4, true);performTestsWithExceptionInReopen(new TestReopen() {@@ -273,15 +275,15 @@ public class TestIndexReaderReopen extends LuceneTestCase {public void testMixedReaders() throws Exception {Random random = newRandom();- final Directory dir1 = new MockRAMDirectory();+ final Directory dir1 = newDirectory(random);createIndex(random, dir1, true);- final Directory dir2 = new MockRAMDirectory();+ final Directory dir2 = newDirectory(random);createIndex(random, dir2, true);- final Directory dir3 = new MockRAMDirectory();+ final Directory dir3 = newDirectory(random);createIndex(random, dir3, false);- final Directory dir4 = new MockRAMDirectory();+ final Directory dir4 = newDirectory(random);createIndex(random, dir4, true);- final Directory dir5 = new MockRAMDirectory();+ final Directory dir5 = newDirectory(random);createIndex(random, dir5, false);performDefaultTests(new TestReopen() {@@ -362,7 +364,7 @@ public class TestIndexReaderReopen extends LuceneTestCase {public void testReferenceCounting() throws IOException {Random random = newRandom();for (int mode = 0; mode < 4; mode++) {- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(random);createIndex(random, dir1, true);IndexReader reader0 = IndexReader.open(dir1, false);@@ -468,9 +470,9 @@ public class TestIndexReaderReopen extends LuceneTestCase {public void testReferenceCountingMultiReader() throws IOException {Random random = newRandom();for (int mode = 0; mode <=1; mode++) {- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(random);createIndex(random, dir1, false);- Directory dir2 = new MockRAMDirectory();+ Directory dir2 = newDirectory(random);createIndex(random, dir2, true);IndexReader reader1 = IndexReader.open(dir1, false);@@ -540,9 +542,9 @@ public class TestIndexReaderReopen extends LuceneTestCase {public void testReferenceCountingParallelReader() throws IOException {Random random = newRandom();for (int mode = 0; mode <=1; mode++) {- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(random);createIndex(random, dir1, false);- Directory dir2 = new MockRAMDirectory();+ Directory dir2 = newDirectory(random);createIndex(random, dir2, true);IndexReader reader1 = IndexReader.open(dir1, false);@@ -614,8 +616,9 @@ public class TestIndexReaderReopen extends LuceneTestCase {}public void testNormsRefCounting() throws IOException {- Directory dir1 = new MockRAMDirectory();- createIndex(newRandom(), dir1, false);+ Random random = newRandom();+ Directory dir1 = newDirectory(random);+ createIndex(random, dir1, false);IndexReader reader1 = IndexReader.open(dir1, false);SegmentReader segmentReader1 = SegmentReader.getOnlySegmentReader(reader1);@@ -704,9 +707,9 @@ public class TestIndexReaderReopen extends LuceneTestCase {}public void testThreadSafety() throws Exception {- final Directory dir = new MockRAMDirectory();- final int n = 30 * RANDOM_MULTIPLIER;Random random = newRandom();+ final Directory dir = newDirectory(random);+ final int n = 30 * RANDOM_MULTIPLIER;IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));for (int i = 0; i < n; i++) {@@ -1105,8 +1108,9 @@ public class TestIndexReaderReopen extends LuceneTestCase {}public void testCloseOrig() throws Throwable {- Directory dir = new MockRAMDirectory();- createIndex(newRandom(), dir, false);+ Random random = newRandom();+ Directory dir = newDirectory(random);+ createIndex(random, dir, false);IndexReader r1 = IndexReader.open(dir, false);IndexReader r2 = IndexReader.open(dir, false);r2.deleteDocument(0);@@ -1126,8 +1130,9 @@ public class TestIndexReaderReopen extends LuceneTestCase {}public void testDeletes() throws Throwable {- Directory dir = new MockRAMDirectory();- createIndex(newRandom(), dir, false); // Create an index with a bunch of docs (1 segment)+ Random random = newRandom();+ Directory dir = newDirectory(random);+ createIndex(random, dir, false); // Create an index with a bunch of docs (1 segment)modifyIndex(0, dir); // Get delete bitVector on 1st segmentmodifyIndex(5, dir); // Add a doc (2 segments)@@ -1159,8 +1164,9 @@ public class TestIndexReaderReopen extends LuceneTestCase {}public void testDeletes2() throws Throwable {- Directory dir = new MockRAMDirectory();- createIndex(newRandom(), dir, false);+ Random random = newRandom();+ Directory dir = newDirectory(random);+ createIndex(random, dir, false);// Get delete bitVectormodifyIndex(0, dir);IndexReader r1 = IndexReader.open(dir, false);@@ -1195,8 +1201,9 @@ public class TestIndexReaderReopen extends LuceneTestCase {}public void testReopenOnCommit() throws Throwable {- Directory dir = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(),+ Random random = newRandom();+ Directory dir = newDirectory(random);+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setIndexDeletionPolicy(new KeepAllCommits()).setMaxBufferedDocs(-1));((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(10);for(int i=0;i<4;i++) {diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriter.javaindex 2e363925b40..4f81c875f9c 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java@@ -91,7 +91,7 @@ public class TestIndexWriter extends LuceneTestCase {}public void testDocCount() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = null;IndexReader reader = null;@@ -151,6 +151,7 @@ public class TestIndexWriter extends LuceneTestCase {assertEquals(0, writer.maxDoc());assertEquals(0, writer.numDocs());writer.close();+ dir.close();}private static void addDoc(IndexWriter writer) throws IOException@@ -187,7 +188,7 @@ public class TestIndexWriter extends LuceneTestCase {Directory[] dirs = new Directory[NUM_DIR];long inputDiskUsage = 0;for(int i=0;i<NUM_DIR;i++) {- dirs[i] = new MockRAMDirectory();+ dirs[i] = newDirectory(random);IndexWriter writer = new IndexWriter(dirs[i], newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));for(int j=0;j<25;j++) {addDocWithIndex(writer, 25*i+j);@@ -201,7 +202,7 @@ public class TestIndexWriter extends LuceneTestCase {// Now, build a starting index that has START_COUNT docs. We// will then try to addIndexesNoOptimize into a copy of this:- MockRAMDirectory startDir = new MockRAMDirectory();+ MockRAMDirectory startDir = newDirectory(random);IndexWriter writer = new IndexWriter(startDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));for(int j=0;j<START_COUNT;j++) {addDocWithIndex(writer, j);@@ -457,6 +458,8 @@ public class TestIndexWriter extends LuceneTestCase {}startDir.close();+ for (Directory dir : dirs)+ dir.close();}/*@@ -473,7 +476,7 @@ public class TestIndexWriter extends LuceneTestCase {while(true) {if (VERBOSE)System.out.println("TEST: cycle: diskFree=" + diskFree);- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);dir.setMaxSizeInBytes(diskFree);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));MergeScheduler ms = writer.getConfig().getMergeScheduler();@@ -553,7 +556,7 @@ public class TestIndexWriter extends LuceneTestCase {public void testOptimizeMaxNumSegments() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);final Document doc = new Document();doc.add(new Field("content", "aaa", Field.Store.YES, Field.Index.ANALYZED));@@ -590,10 +593,11 @@ public class TestIndexWriter extends LuceneTestCase {elseassertEquals(3, optSegCount);}+ dir.close();}public void testOptimizeMaxNumSegments2() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);final Document doc = new Document();doc.add(new Field("content", "aaa", Field.Store.YES, Field.Index.ANALYZED));@@ -630,6 +634,8 @@ public class TestIndexWriter extends LuceneTestCase {elseassertEquals(7, optSegCount);}+ writer.close();+ dir.close();}/**@@ -639,7 +645,7 @@ public class TestIndexWriter extends LuceneTestCase {*/public void testOptimizeTempSpaceUsage() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10));for(int j=0;j<500;j++) {@@ -714,7 +720,7 @@ public class TestIndexWriter extends LuceneTestCase {// gracefully fallback to the previous segments file),// and that we can add to the index:public void testSimulatedCrashedWriter() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);dir.setPreventDoubleWrite(false);IndexWriter writer = null;@@ -770,13 +776,14 @@ public class TestIndexWriter extends LuceneTestCase {// closewriter.close();+ dir.close();}// Simulate a corrupt index by removing last byte of// latest segments file and make sure we get an// IOException trying to open the index:public void testSimulatedCorruptIndex1() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = null;@@ -816,10 +823,11 @@ public class TestIndexWriter extends LuceneTestCase {if (reader != null) {reader.close();}+ dir.close();}public void testChangesAfterClose() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = null;@@ -834,6 +842,7 @@ public class TestIndexWriter extends LuceneTestCase {} catch (AlreadyClosedException e) {// expected}+ dir.close();}@@ -841,7 +850,7 @@ public class TestIndexWriter extends LuceneTestCase {// files and make sure we get an IOException trying to// open the index:public void testSimulatedCorruptIndex2() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = null;@@ -879,6 +888,7 @@ public class TestIndexWriter extends LuceneTestCase {if (reader != null) {reader.close();}+ dir.close();}/*@@ -887,7 +897,7 @@ public class TestIndexWriter extends LuceneTestCase {* these docs until writer is closed.*/public void testCommitOnClose() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));for (int i = 0; i < 14; i++) {addDoc(writer);@@ -922,6 +932,8 @@ public class TestIndexWriter extends LuceneTestCase {hits = searcher.search(new TermQuery(searchTerm), null, 1000).scoreDocs;assertEquals("reader did not see changes after writer was closed", 47, hits.length);searcher.close();+ reader.close();+ dir.close();}/*@@ -933,7 +945,7 @@ public class TestIndexWriter extends LuceneTestCase {* and add docs to it.*/public void testCommitOnCloseAbort() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10));for (int i = 0; i < 14; i++) {addDoc(writer);@@ -1005,7 +1017,7 @@ public class TestIndexWriter extends LuceneTestCase {* measure max temp disk space used.*/public void testCommitOnCloseDiskUsage() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10));((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);for(int j=0;j<30;j++) {@@ -1041,6 +1053,7 @@ public class TestIndexWriter extends LuceneTestCase {midDiskUsage < 100*startDiskUsage);assertTrue("writer used too much space after close: endDiskUsage=" + endDiskUsage + " startDiskUsage=" + startDiskUsage,endDiskUsage < 100*startDiskUsage);+ dir.close();}@@ -1050,7 +1063,7 @@ public class TestIndexWriter extends LuceneTestCase {* and close().*/public void testCommitOnCloseOptimize() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);// Must disable throwing exc on double-write: this// test uses IW.rollback which easily results in// writing to same file more than once@@ -1095,10 +1108,11 @@ public class TestIndexWriter extends LuceneTestCase {// Reader should still see index as unoptimized:assertTrue("Reader incorrectly sees that the index is unoptimized", reader.isOptimized());reader.close();+ dir.close();}public void testIndexNoDocuments() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));writer.commit();writer.close();@@ -1116,10 +1130,11 @@ public class TestIndexWriter extends LuceneTestCase {assertEquals(0, reader.maxDoc());assertEquals(0, reader.numDocs());reader.close();+ dir.close();}public void testManyFields() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10));for(int j=0;j<100;j++) {Document doc = new Document();@@ -1149,7 +1164,7 @@ public class TestIndexWriter extends LuceneTestCase {}public void testSmallRAMBuffer() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setRAMBufferSizeMB(0.000001));((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);int lastNumFile = dir.listAll().length;@@ -1176,7 +1191,7 @@ public class TestIndexWriter extends LuceneTestCase {* session won't be possible.*/public void testChangingRAMBuffer() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10).setRAMBufferSizeMB(IndexWriterConfig.DISABLE_AUTO_FLUSH));@@ -1234,7 +1249,7 @@ public class TestIndexWriter extends LuceneTestCase {* changing those settings on IW won't be possible.*/public void testChangingRAMBuffer2() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10).setMaxBufferedDeleteTerms(10).setRAMBufferSizeMB(IndexWriterConfig.DISABLE_AUTO_FLUSH));@@ -1293,7 +1308,7 @@ public class TestIndexWriter extends LuceneTestCase {}public void testDiverseDocs() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setRAMBufferSizeMB(0.5));for(int i=0;i<3;i++) {// First, docs where every term is unique (heavy on@@ -1340,7 +1355,7 @@ public class TestIndexWriter extends LuceneTestCase {}public void testEnablingNorms() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10));// Enable norms for only 1 doc, pre flushfor(int j=0;j<10;j++) {@@ -1386,7 +1401,7 @@ public class TestIndexWriter extends LuceneTestCase {}public void testHighFreqTerm() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxFieldLength(100000000).setRAMBufferSizeMB(0.01));// Massive doc that has 128 K a's@@ -1457,7 +1472,7 @@ public class TestIndexWriter extends LuceneTestCase {}public void testFlushWithNoMerging() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));((LogMergePolicy) writer.getMergePolicy()).setMergeFactor(10);@@ -1472,12 +1487,13 @@ public class TestIndexWriter extends LuceneTestCase {// Since we flushed w/o allowing merging we should now// have 10 segmentsassert sis.size() == 10;+ dir.close();}// Make sure we can flush segment w/ norms, then add// empty doc (no norms) and flushpublic void testEmptyDocAfterFlushingRealDoc() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new Field("field", "aaa", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));@@ -1488,6 +1504,8 @@ public class TestIndexWriter extends LuceneTestCase {_TestUtil.checkIndex(dir);IndexReader reader = IndexReader.open(dir, true);assertEquals(2, reader.numDocs());+ reader.close();+ dir.close();}// Test calling optimize(false) whereby optimize is kicked@@ -1495,7 +1513,7 @@ public class TestIndexWriter extends LuceneTestCase {// writer.close()) does waitpublic void testBackgroundOptimize() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);for(int pass=0;pass<2;pass++) {IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer())@@ -1550,7 +1568,7 @@ public class TestIndexWriter extends LuceneTestCase {**/public void testBadSegment() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));@@ -1563,7 +1581,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1008public void testNoTermVectorAfterTermVector() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));Document document = new Document();@@ -1590,7 +1608,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1010public void testNoTermVectorAfterTermVectorMerge() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));Document document = new Document();@@ -1623,7 +1641,7 @@ public class TestIndexWriter extends LuceneTestCase {public void testMaxThreadPriority() throws IOException {int pri = Thread.currentThread().getPriority();try {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriterConfig conf = newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2);@@ -1636,7 +1654,7 @@ public class TestIndexWriter extends LuceneTestCase {for(int i=0;i<4;i++)iw.addDocument(document);iw.close();-+ dir.close();} finally {Thread.currentThread().setPriority(pri);}@@ -1665,7 +1683,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1013public void testSetMaxMergeDocs() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriterConfig conf = newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMergeScheduler(new MyMergeScheduler()).setMaxBufferedDocs(2);@@ -1679,11 +1697,12 @@ public class TestIndexWriter extends LuceneTestCase {for(int i=0;i<177;i++)iw.addDocument(document);iw.close();+ dir.close();}// LUCENE-1072public void testExceptionFromTokenStream() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new Analyzer() {@Override@@ -1786,7 +1805,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1072: make sure an errant exception on flushing// one segment only takes out those docs in that one flushpublic void testDocumentsWriterAbort() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);FailOnlyOnFlush failure = new FailOnlyOnFlush();failure.setDoFail();dir.failOn(failure);@@ -1811,6 +1830,7 @@ public class TestIndexWriter extends LuceneTestCase {IndexReader reader = IndexReader.open(dir, true);assertEquals(198, reader.docFreq(new Term("content", "aa")));reader.close();+ dir.close();}private class CrashingFilter extends TokenFilter {@@ -1845,7 +1865,7 @@ public class TestIndexWriter extends LuceneTestCase {};for(int i=0;i<2;i++) {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));//writer.setInfoStream(System.out);Document doc = new Document();@@ -1931,7 +1951,7 @@ public class TestIndexWriter extends LuceneTestCase {final int NUM_ITER = 100;for(int i=0;i<2;i++) {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);{final IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer).setMaxBufferedDocs(-1));@@ -2034,7 +2054,7 @@ public class TestIndexWriter extends LuceneTestCase {}public void testVariableSchema() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);int delID = 0;for(int i=0;i<20;i++) {IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));@@ -2082,10 +2102,11 @@ public class TestIndexWriter extends LuceneTestCase {writer.close();}}+ dir.close();}public void testNoWaitClose() throws Throwable {- MockRAMDirectory directory = new MockRAMDirectory();+ MockRAMDirectory directory = newDirectory(random);final Document doc = new Document();Field idField = new Field("id", "", Field.Store.YES, Field.Index.NOT_ANALYZED);@@ -2241,7 +2262,7 @@ public class TestIndexWriter extends LuceneTestCase {int NUM_THREADS = 3;for(int iter=0;iter<7;iter++) {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10).setMergeScheduler(new ConcurrentMergeScheduler());// We expect AlreadyClosedException@@ -2300,7 +2321,7 @@ public class TestIndexWriter extends LuceneTestCase {// an IndexWriter (hit during DW.ThreadState.init()) is// OK:public void testImmediateDiskFull() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2).setMergeScheduler(new ConcurrentMergeScheduler()));dir.setMaxSizeInBytes(Math.max(1, dir.getRecomputedActualSizeInBytes()));@@ -2338,7 +2359,7 @@ public class TestIndexWriter extends LuceneTestCase {int NUM_THREADS = 3;for(int iter=0;iter<10;iter++) {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2).setMergeScheduler(new ConcurrentMergeScheduler());// We expect disk full exceptions in the merge threads@@ -2397,7 +2418,7 @@ public class TestIndexWriter extends LuceneTestCase {// Runs test, with one thread, using the specific failure// to trigger an IOExceptionpublic void _testSingleThreadFailure(MockRAMDirectory.Failure failure) throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2).setMergeScheduler(new ConcurrentMergeScheduler()));@@ -2419,6 +2440,7 @@ public class TestIndexWriter extends LuceneTestCase {failure.clearDoFail();writer.addDocument(doc);writer.close(false);+ dir.close();}// Runs test, with multiple threads, using the specific@@ -2428,7 +2450,7 @@ public class TestIndexWriter extends LuceneTestCase {int NUM_THREADS = 3;for(int iter=0;iter<2;iter++) {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT,new MockAnalyzer()).setMaxBufferedDocs(2).setMergeScheduler(new ConcurrentMergeScheduler());// We expect disk full exceptions in the merge threads@@ -2586,7 +2608,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1084: test unlimited field lengthpublic void testUnlimitedMaxFieldLength() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));@@ -2608,7 +2630,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1044: Simulate checksum error in segments_Npublic void testSegmentsChecksumError() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = null;@@ -2642,11 +2664,12 @@ public class TestIndexWriter extends LuceneTestCase {fail("segmentInfos failed to retry fallback to correct segments_N file");}reader.close();+ dir.close();}// LUCENE-1044: test writer.commit() when ac=falsepublic void testForceCommit() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer())@@ -2700,7 +2723,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1044: test exception during syncpublic void testExceptionDuringSync() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);FailOnlyInSync failure = new FailOnlyInSync();dir.failOn(failure);@@ -2734,7 +2757,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1168public void testTermVectorCorruption() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);for(int iter=0;iter<2;iter++) {IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer())@@ -2785,7 +2808,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1168public void testTermVectorCorruption2() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);for(int iter=0;iter<2;iter++) {IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer())@@ -2823,7 +2846,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1168public void testTermVectorCorruption3() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2).setRAMBufferSizeMB(@@ -2866,7 +2889,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1084: test user-specified field lengthpublic void testUserSpecifiedMaxFieldLength() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxFieldLength(100000));@@ -2890,7 +2913,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-325: test expungeDeletes, when 2 singular merges// are requiredpublic void testExpungeDeletes() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2).setRAMBufferSizeMB(@@ -2933,7 +2956,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-325: test expungeDeletes, when many adjacent merges are requiredpublic void testExpungeDeletes2() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2).setRAMBufferSizeMB(@@ -2978,7 +3001,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-325: test expungeDeletes without waiting, when// many adjacent merges are requiredpublic void testExpungeDeletes3() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2).setRAMBufferSizeMB(@@ -3021,12 +3044,13 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1179public void testEmptyFieldName() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new Field("", "a b c", Field.Store.NO, Field.Index.ANALYZED));writer.addDocument(doc);writer.close();+ dir.close();}// LUCENE-1198@@ -3048,7 +3072,7 @@ public class TestIndexWriter extends LuceneTestCase {public void testExceptionDocumentsWriterInit() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);MockIndexWriter w = new MockIndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new Field("field", "a field", Field.Store.YES,@@ -3068,7 +3092,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1208public void testExceptionJustBeforeFlush() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);MockIndexWriter w = new MockIndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));Document doc = new Document();doc.add(new Field("field", "a field", Field.Store.YES,@@ -3118,7 +3142,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1210public void testExceptionOnMergeInit() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2).setMergeScheduler(new ConcurrentMergeScheduler());((LogMergePolicy) conf.getMergePolicy()).setMergeFactor(2);@@ -3163,7 +3187,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1222public void testDoBeforeAfterFlush() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);MockIndexWriter3 w = new MockIndexWriter3(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new Field("field", "a field", Field.Store.YES,@@ -3219,7 +3243,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1214public void testExceptionsDuringCommit() throws Throwable {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);FailOnlyInCommit failure = new FailOnlyInCommit();IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();@@ -3268,7 +3292,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-510public void testInvalidUTF16() throws Throwable {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();@@ -3478,7 +3502,7 @@ public class TestIndexWriter extends LuceneTestCase {}};- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new Field("field", tokens));@@ -3514,7 +3538,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1274: test writer.prepareCommit()public void testPrepareCommit() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(5);@@ -3565,7 +3589,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1274: test writer.prepareCommit()public void testPrepareCommitRollback() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);dir.setPreventDoubleWrite(false);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));@@ -3618,7 +3642,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1274public void testPrepareCommitNoChanges() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));writer.prepareCommit();@@ -3924,7 +3948,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1347public void testRollbackExceptionHang() throws Throwable {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);MockIndexWriter4 w = new MockIndexWriter4(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));addDoc(w);@@ -3938,12 +3962,13 @@ public class TestIndexWriter extends LuceneTestCase {w.doFail = false;w.rollback();+ dir.close();}// LUCENE-1219public void testBinaryFieldOffsetLength() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));byte[] b = new byte[50];for(int i=0;i<50;i++)@@ -3973,7 +3998,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1382public void testCommitUserData() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));for(int j=0;j<17;j++)addDoc(w);@@ -4010,7 +4035,7 @@ public class TestIndexWriter extends LuceneTestCase {}public void testOptimizeExceptions() throws IOException {- MockRAMDirectory startDir = new MockRAMDirectory();+ MockRAMDirectory startDir = newDirectory(random);IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2);((LogMergePolicy) conf.getMergePolicy()).setMergeFactor(100);IndexWriter w = new IndexWriter(startDir, conf);@@ -4034,14 +4059,15 @@ public class TestIndexWriter extends LuceneTestCase {w.close();dir.close();}+ startDir.close();}// LUCENE-1429public void testOutOfMemoryErrorCausesCloseToFail() throws Exception {final List<Throwable> thrown = new ArrayList<Throwable>();-- final IndexWriter writer = new IndexWriter(new MockRAMDirectory(),+ final Directory dir = newDirectory(random);+ final IndexWriter writer = new IndexWriter(dir,newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())) {@Overridepublic void message(final String message) {@@ -4062,11 +4088,12 @@ public class TestIndexWriter extends LuceneTestCase {// throws IllegalStateEx w/o bug fixwriter.close();+ dir.close();}// LUCENE-1442public void testDoubleOffsetCounting() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();@@ -4102,7 +4129,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1442public void testDoubleOffsetCounting2() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();Field f = new Field("field", "abcd", Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);@@ -4124,7 +4151,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1448public void testEndOffsetPositionCharAnalyzer() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();Field f = new Field("field", "abcd ", Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);@@ -4146,7 +4173,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1448public void testEndOffsetPositionWithCachingTokenFilter() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);Analyzer analyzer = new MockAnalyzer();IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));Document doc = new Document();@@ -4170,7 +4197,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1448public void testEndOffsetPositionStopFilter() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true)));Document doc = new Document();@@ -4193,7 +4220,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1448public void testEndOffsetPositionStandard() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();@@ -4224,7 +4251,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1448public void testEndOffsetPositionStandardEmptyField() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();@@ -4252,7 +4279,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1448public void testEndOffsetPositionStandardEmptyField2() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();@@ -4306,7 +4333,7 @@ public class TestIndexWriter extends LuceneTestCase {}public void testDeadlock() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));Document doc = new Document();doc.add(new Field("content", "aaa bbb ccc ddd eee fff ggg hhh iii", Field.Store.YES,@@ -4317,7 +4344,7 @@ public class TestIndexWriter extends LuceneTestCase {writer.commit();// index has 2 segments- MockRAMDirectory dir2 = new MockRAMDirectory();+ MockRAMDirectory dir2 = newDirectory(random);IndexWriter writer2 = new IndexWriter(dir2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));writer2.addDocument(doc);writer2.close();@@ -4346,7 +4373,10 @@ public class TestIndexWriter extends LuceneTestCase {@Overridepublic void run() {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir;+ try {+ dir = newDirectory(random);+ } catch (IOException e) { throw new RuntimeException(e); }IndexWriter w = null;boolean first = true;while(!finish) {@@ -4442,6 +4472,7 @@ public class TestIndexWriter extends LuceneTestCase {e.printStackTrace(System.out);}}+ dir.close();}}@@ -4472,7 +4503,7 @@ public class TestIndexWriter extends LuceneTestCase {public void testIndexStoreCombos() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));byte[] b = new byte[50];for(int i=0;i<50;i++)@@ -4535,7 +4566,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-1727: make sure doc fields are stored in orderpublic void testStoredFieldsOrder() throws Throwable {- Directory d = new MockRAMDirectory();+ Directory d = newDirectory(random);IndexWriter w = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new Field("zzz", "a b c", Field.Store.YES, Field.Index.NO));@@ -4567,7 +4598,7 @@ public class TestIndexWriter extends LuceneTestCase {public void testEmbeddedFFFF() throws Throwable {- Directory d = new MockRAMDirectory();+ Directory d = newDirectory(random);IndexWriter w = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new Field("field", "a a\uffffb", Field.Store.NO, Field.Index.ANALYZED));@@ -4584,7 +4615,7 @@ public class TestIndexWriter extends LuceneTestCase {}public void testNoDocsIndex() throws Throwable {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));LogMergePolicy lmp = (LogMergePolicy) writer.getConfig().getMergePolicy();@@ -4605,7 +4636,7 @@ public class TestIndexWriter extends LuceneTestCase {public void testCommitThreadSafety() throws Throwable {final int NUM_THREADS = 5;final double RUN_SEC = 0.5;- final Directory dir = new MockRAMDirectory();+ final Directory dir = newDirectory(random);final IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));w.commit();@@ -4713,7 +4744,7 @@ public class TestIndexWriter extends LuceneTestCase {// sort in codepoint sort order by defaultpublic void testTermUTF16SortOrder() throws Throwable {Random rnd = random;- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(rnd, dir);Document d = new Document();// Single segment@@ -4777,7 +4808,7 @@ public class TestIndexWriter extends LuceneTestCase {}public void testIndexDivisor() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, new MockAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);StringBuilder s = new StringBuilder();// must be > 256@@ -4806,7 +4837,7 @@ public class TestIndexWriter extends LuceneTestCase {public void testDeleteUnusedFiles() throws Exception {for(int iter=0;iter<2;iter++) {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));((LogMergePolicy) w.getMergePolicy()).setUseCompoundFile(true);Document doc = new Document();@@ -4865,7 +4896,7 @@ public class TestIndexWriter extends LuceneTestCase {public void testDeleteUnsedFiles2() throws Exception {// Validates that iw.deleteUnusedFiles() also deletes unused index commits// in case a deletion policy which holds onto commits is used.- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);SnapshotDeletionPolicy sdp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer())@@ -4894,6 +4925,7 @@ public class TestIndexWriter extends LuceneTestCase {assertEquals(1, IndexReader.listCommits(dir).size());writer.close();+ dir.close();}private static class FlushCountingIndexWriter extends IndexWriter {@@ -4909,7 +4941,7 @@ public class TestIndexWriter extends LuceneTestCase {public void testIndexingThenDeleting() throws Exception {final Random r = random;- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);FlushCountingIndexWriter w = new FlushCountingIndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setRAMBufferSizeMB(0.5).setMaxBufferedDocs(-1).setMaxBufferedDeleteTerms(-1));//w.setInfoStream(System.out);Document doc = new Document();@@ -4944,7 +4976,7 @@ public class TestIndexWriter extends LuceneTestCase {// Tests that if we don't call commit(), the directory has 0 commits. This has// changed since LUCENE-2386, where before IW would always commit on a fresh// new index.- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));try {IndexReader.listCommits(dir);@@ -4955,6 +4987,7 @@ public class TestIndexWriter extends LuceneTestCase {// No changes still should generate a commit, because it's a new index.writer.close();assertEquals("expected 1 commits!", 1, IndexReader.listCommits(dir).size());+ dir.close();}public void testEmptyFSDirWithNoLock() throws Exception {@@ -4969,7 +5002,7 @@ public class TestIndexWriter extends LuceneTestCase {// Tests that if IW is created over an empty Directory, some documents are// indexed, flushed (but not committed) and then IW rolls back, then no// files are left in the Directory.- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));@@ -4995,6 +5028,7 @@ public class TestIndexWriter extends LuceneTestCase {// Since we rolled-back above, that close should be a no-opwriter.close();assertEquals("expected a no-op close after IW.rollback()", 0, dir.listAll().length);+ dir.close();}public void testNoSegmentFile() throws IOException {@@ -5023,7 +5057,7 @@ public class TestIndexWriter extends LuceneTestCase {}public void testFutureCommit() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setIndexDeletionPolicy(NoDeletionPolicy.INSTANCE));Document doc = new Document();@@ -5197,7 +5231,7 @@ public class TestIndexWriter extends LuceneTestCase {// LUCENE-2593public void testCorruptionAfterDiskFullDuringMerge() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);final Random rand = random;//IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new MockAnalyzer()).setReaderPooling(true));IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new MockAnalyzer()).setMergeScheduler(new SerialMergeScheduler()).setReaderPooling(true));diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.javaindex b51a0a8cc75..db7557dd772 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterConfig.java@@ -264,7 +264,7 @@ public class TestIndexWriterConfig extends LuceneTestCaseJ4 {// iw.getConfig().getXYZ(), he'll get the same value he passed to// iw.setXYZ().IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer());- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(newRandom());IndexWriter writer = new IndexWriter(dir, conf);writer.setSimilarity(new MySimilarity());@@ -296,6 +296,8 @@ public class TestIndexWriterConfig extends LuceneTestCaseJ4 {writer.setMergePolicy(new LogDocMergePolicy());assertEquals(LogDocMergePolicy.class, writer.getConfig().getMergePolicy().getClass());+ writer.close();+ dir.close();}}diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.javaindex 87a5101a1fc..1f45905d4a7 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java@@ -49,7 +49,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {"Venice has lots of canals" };String[] text = { "Amsterdam", "Venice" };- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDeleteTerms(1));@@ -84,7 +84,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {// test when delete terms only apply to disk segmentspublic void testNonRAMDelete() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDocs(2).setMaxBufferedDeleteTerms(2));@@ -118,7 +118,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {}public void testMaxBufferedDeletes() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDeleteTerms(1));writer.deleteDocuments(new Term("foobar", "1"));@@ -132,7 +132,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {// test when delete terms only apply to ram segmentspublic void testRAMDeletes() throws IOException {for(int t=0;t<2;t++) {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDocs(4).setMaxBufferedDeleteTerms(4));@@ -173,7 +173,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {// test when delete terms apply to both disk and ram segmentspublic void testBothDeletes() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDocs(100).setMaxBufferedDeleteTerms(100));@@ -201,11 +201,13 @@ public class TestIndexWriterDelete extends LuceneTestCase {IndexReader reader = IndexReader.open(dir, true);assertEquals(5, reader.numDocs());modifier.close();+ reader.close();+ dir.close();}// test that batched delete terms are flushed togetherpublic void testBatchDeletes() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDocs(2).setMaxBufferedDeleteTerms(2));@@ -248,7 +250,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {// test deleteAll()public void testDeleteAll() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDocs(2).setMaxBufferedDeleteTerms(2));@@ -294,7 +296,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {// test rollback of deleteAll()public void testDeleteAllRollback() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDocs(2).setMaxBufferedDeleteTerms(2));@@ -331,7 +333,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {// test deleteAll() w/ near real-time readerpublic void testDeleteAllNRT() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDocs(2).setMaxBufferedDeleteTerms(2));@@ -421,7 +423,9 @@ public class TestIndexWriterDelete extends LuceneTestCase {int END_COUNT = 144;// First build up a starting index:- MockRAMDirectory startDir = new MockRAMDirectory();+ MockRAMDirectory startDir = newDirectory(random);+ // TODO: find the resource leak that only occurs sometimes here.+ startDir.setNoDeleteOpenFile(false);IndexWriter writer = new IndexWriter(startDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));for (int i = 0; i < 157; i++) {Document d = new Document();@@ -587,16 +591,15 @@ public class TestIndexWriterDelete extends LuceneTestCase {+ result2 + " instead of expected " + START_COUNT + " or " + END_COUNT);}}-searcher.close();newReader.close();-+ dir.close();if (result2 == END_COUNT) {break;}}-- dir.close();+ modifier.close();+ startDir.close();// Try again with 10 more bytes of free space:diskFree += 10;@@ -653,7 +656,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {"Venice has lots of canals" };String[] text = { "Amsterdam", "Venice" };- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setMaxBufferedDeleteTerms(2).setReaderPooling(false));LogMergePolicy lmp = (LogMergePolicy) modifier.getConfig().getMergePolicy();@@ -763,7 +766,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {"Venice has lots of canals" };String[] text = { "Amsterdam", "Venice" };- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));modifier.commit();dir.failOn(failure.reset());@@ -787,10 +790,11 @@ public class TestIndexWriterDelete extends LuceneTestCase {TestIndexWriter.assertNoUnreferencedFiles(dir, "docsWriter.abort() failed to delete unreferenced files");modifier.close();+ dir.close();}public void testDeleteNullQuery() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter modifier = new IndexWriter(dir, new MockAnalyzer(MockTokenizer.WHITESPACE, false), IndexWriter.MaxFieldLength.UNLIMITED);for (int i = 0; i < 5; i++) {diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.javaindex 029202cc880..49edf6ba0f4 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java@@ -130,7 +130,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {public void testRandomExceptions() throws Throwable {Random random = newRandom();- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);MockIndexWriter writer = new MockIndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setRAMBufferSizeMB(0.1).setMergeScheduler(new ConcurrentMergeScheduler()));@@ -166,12 +166,13 @@ public class TestIndexWriterExceptions extends LuceneTestCase {r2.close();_TestUtil.checkIndex(dir);+ dir.close();}public void testRandomExceptionsThreads() throws Throwable {-- MockRAMDirectory dir = new MockRAMDirectory();- MockIndexWriter writer = new MockIndexWriter(dir, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT, new MockAnalyzer())+ Random random = newRandom();+ MockRAMDirectory dir = newDirectory(random);+ MockIndexWriter writer = new MockIndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setRAMBufferSizeMB(0.2).setMergeScheduler(new ConcurrentMergeScheduler()));((ConcurrentMergeScheduler) writer.getConfig().getMergeScheduler()).setSuppressExceptions();//writer.setMaxBufferedDocs(10);@@ -213,5 +214,6 @@ public class TestIndexWriterExceptions extends LuceneTestCase {r2.close();_TestUtil.checkIndex(dir);+ dir.close();}}diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.javaindex c0900bea5c6..b472358cc1b 100755--- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java@@ -18,24 +18,31 @@ package org.apache.lucene.index;*/import java.io.IOException;+import java.util.Random;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.index.IndexWriterConfig.OpenMode;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util._TestUtil;import org.apache.lucene.util.LuceneTestCase;public class TestIndexWriterMergePolicy extends LuceneTestCase {-+ private Random random;++ @Override+ public void setUp() throws Exception {+ super.setUp();+ random = newRandom();+ }+// Test the normal casepublic void testNormalCase() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10).setMergePolicy(new LogDocMergePolicy()));@@ -45,13 +52,14 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {}writer.close();+ dir.close();}// Test to see if there is over mergepublic void testNoOverMerge() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10).setMergePolicy(new LogDocMergePolicy()));@@ -66,16 +74,17 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {assertTrue(noOverMerge);writer.close();+ dir.close();}// Test the case where flush is forced after every addDocpublic void testForceFlush() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);LogDocMergePolicy mp = new LogDocMergePolicy();mp.setMinMergeDocs(100);mp.setMergeFactor(10);- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10).setMergePolicy(mp));@@ -85,7 +94,7 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {mp = new LogDocMergePolicy();mp.setMergeFactor(10);- writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT,+ writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT,new MockAnalyzer()).setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(10).setMergePolicy(mp));mp.setMinMergeDocs(100);@@ -93,13 +102,14 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {}writer.close();+ dir.close();}// Test the case where mergeFactor changespublic void testMergeFactorChange() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10).setMergePolicy(new LogDocMergePolicy()));@@ -118,13 +128,14 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {checkInvariants(writer);writer.close();+ dir.close();}// Test the case where both mergeFactor and maxBufferedDocs changepublic void testMaxBufferedDocsChange() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(101).setMergePolicy(new LogDocMergePolicy()));@@ -137,7 +148,7 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {}writer.close();- writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT,+ writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT,new MockAnalyzer()).setOpenMode(OpenMode.APPEND).setMaxBufferedDocs(101).setMergePolicy(new LogDocMergePolicy()));@@ -146,9 +157,9 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {writer.close();LogDocMergePolicy ldmp = new LogDocMergePolicy();ldmp.setMergeFactor(10);- writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT,+ writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT,new MockAnalyzer()).setOpenMode(- OpenMode.APPEND).setMaxBufferedDocs(10).setMergePolicy(ldmp));+ OpenMode.APPEND).setMaxBufferedDocs(10).setMergePolicy(ldmp).setMergeScheduler(new ConcurrentMergeScheduler()));// merge policy only fixes segments on levels where merges// have been triggered, so check invariants after all adds@@ -166,15 +177,16 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {checkInvariants(writer);writer.close();+ dir.close();}// Test the case where a merge results in no doc at allpublic void testMergeDocCount0() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);LogDocMergePolicy ldmp = new LogDocMergePolicy();ldmp.setMergeFactor(100);- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10).setMergePolicy(ldmp));@@ -190,9 +202,9 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {ldmp = new LogDocMergePolicy();ldmp.setMergeFactor(5);- writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT,+ writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT,new MockAnalyzer()).setOpenMode(- OpenMode.APPEND).setMaxBufferedDocs(10).setMergePolicy(ldmp));+ OpenMode.APPEND).setMaxBufferedDocs(10).setMergePolicy(ldmp).setMergeScheduler(new ConcurrentMergeScheduler()));// merge factor is changed, so check invariants after all addsfor (int i = 0; i < 10; i++) {@@ -205,6 +217,7 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {assertEquals(10, writer.maxDoc());writer.close();+ dir.close();}private void addDoc(IndexWriter writer) throws IOException {diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterMerging.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterMerging.javaindex 1ded6647b01..c01258f52fa 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterMerging.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterMerging.java@@ -38,8 +38,8 @@ public class TestIndexWriterMerging extends LuceneTestCaseRandom random = newRandom();int num=100;- Directory indexA = new MockRAMDirectory();- Directory indexB = new MockRAMDirectory();+ Directory indexA = newDirectory(random);+ Directory indexB = newDirectory(random);fillIndex(random, indexA, 0, num);boolean fail = verifyIndex(indexA, 0);@@ -55,7 +55,7 @@ public class TestIndexWriterMerging extends LuceneTestCasefail("Index b is invalid");}- Directory merged = new MockRAMDirectory();+ Directory merged = newDirectory(random);IndexWriter writer = new IndexWriter(merged, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2);@@ -68,6 +68,9 @@ public class TestIndexWriterMerging extends LuceneTestCasemerged.close();assertFalse("The merged index is invalid", fail);+ indexA.close();+ indexB.close();+ merged.close();}private boolean verifyIndex(Directory directory, int startAt) throws IOExceptiondiff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.javaindex 8ed507458ea..72ac6d7d502 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriterReader.java@@ -70,7 +70,7 @@ public class TestIndexWriterReader extends LuceneTestCase {public void testUpdateDocument() throws Exception {boolean optimize = true;- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(random);IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));// create the index@@ -131,7 +131,7 @@ public class TestIndexWriterReader extends LuceneTestCase {public void testAddIndexes() throws Exception {boolean optimize = false;- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(random);IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));writer.setInfoStream(infoStream);// create the index@@ -139,7 +139,7 @@ public class TestIndexWriterReader extends LuceneTestCase {writer.flush(false, true, true);// create a 2nd index- Directory dir2 = new MockRAMDirectory();+ Directory dir2 = newDirectory(random);IndexWriter writer2 = new IndexWriter(dir2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));writer2.setInfoStream(infoStream);createIndexNoClose(!optimize, "index2", writer2);@@ -171,17 +171,18 @@ public class TestIndexWriterReader extends LuceneTestCase {r1.close();writer.close();dir1.close();+ dir2.close();}public void testAddIndexes2() throws Exception {boolean optimize = false;- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(random);IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));writer.setInfoStream(infoStream);// create a 2nd index- Directory dir2 = new MockRAMDirectory();+ Directory dir2 = newDirectory(random);IndexWriter writer2 = new IndexWriter(dir2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));writer2.setInfoStream(infoStream);createIndexNoClose(!optimize, "index2", writer2);@@ -199,6 +200,7 @@ public class TestIndexWriterReader extends LuceneTestCase {r1.close();writer.close();dir1.close();+ dir2.close();}/**@@ -209,7 +211,7 @@ public class TestIndexWriterReader extends LuceneTestCase {public void testDeleteFromIndexWriter() throws Exception {boolean optimize = true;- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(random);IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setReaderTermsIndexDivisor(2));writer.setInfoStream(infoStream);// create the index@@ -261,7 +263,7 @@ public class TestIndexWriterReader extends LuceneTestCase {final int numIter = 2;int numDirs = 3;- Directory mainDir = new MockRAMDirectory();+ Directory mainDir = newDirectory(random);IndexWriter mainWriter = new IndexWriter(mainDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));mainWriter.setInfoStream(infoStream);AddDirectoriesThreads addDirThreads = new AddDirectoriesThreads(numIter, mainWriter);@@ -304,7 +306,7 @@ public class TestIndexWriterReader extends LuceneTestCase {public AddDirectoriesThreads(int numDirs, IndexWriter mainWriter) throws Throwable {this.numDirs = numDirs;this.mainWriter = mainWriter;- addDir = new MockRAMDirectory();+ addDir = newDirectory(random);IndexWriter writer = new IndexWriter(addDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));for (int i = 0; i < NUM_INIT_DOCS; i++) {Document doc = createDocument(i, "addindex", 4);@@ -410,7 +412,7 @@ public class TestIndexWriterReader extends LuceneTestCase {* IW.getReader*/public void doTestIndexWriterReopenSegment(boolean optimize) throws Exception {- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(random);IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));writer.setInfoStream(infoStream);IndexReader r1 = writer.getReader();@@ -521,7 +523,7 @@ public class TestIndexWriterReader extends LuceneTestCase {public void testMergeWarmer() throws Exception {- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(random);// Enroll warmerMyWarmer warmer = new MyWarmer();IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random,@@ -556,7 +558,7 @@ public class TestIndexWriterReader extends LuceneTestCase {}public void testAfterCommit() throws Exception {- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(random);IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMergeScheduler(new ConcurrentMergeScheduler()));writer.commit();writer.setInfoStream(infoStream);@@ -589,7 +591,7 @@ public class TestIndexWriterReader extends LuceneTestCase {// Make sure reader remains usable even if IndexWriter closespublic void testAfterClose() throws Exception {- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(random);IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));writer.setInfoStream(infoStream);@@ -618,7 +620,7 @@ public class TestIndexWriterReader extends LuceneTestCase {// Stress test reopen during addIndexespublic void testDuringAddIndexes() throws Exception {- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(random);final IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));writer.setInfoStream(infoStream);((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2);@@ -695,7 +697,7 @@ public class TestIndexWriterReader extends LuceneTestCase {// Stress test reopen during add/deletepublic void testDuringAddDelete() throws Exception {- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(random);final IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));writer.setInfoStream(infoStream);((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2);@@ -775,7 +777,7 @@ public class TestIndexWriterReader extends LuceneTestCase {}public void testExpungeDeletes() throws Throwable {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);final IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new Field("field", "a b c", Field.Store.NO, Field.Index.ANALYZED));@@ -799,7 +801,7 @@ public class TestIndexWriterReader extends LuceneTestCase {}public void testDeletesNumDocs() throws Throwable {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);final IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new Field("field", "a b c", Field.Store.NO, Field.Index.ANALYZED));@@ -829,16 +831,17 @@ public class TestIndexWriterReader extends LuceneTestCase {public void testEmptyIndex() throws Exception {// Ensures that getReader works on an empty index, which hasn't been committed yet.- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));IndexReader r = w.getReader();assertEquals(0, r.numDocs());r.close();w.close();+ dir.close();}public void testSegmentWarmer() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2).setReaderPooling(true));((LogMergePolicy) w.getMergePolicy()).setMergeFactor(10);diff --git a/lucene/src/test/org/apache/lucene/index/TestLazyBug.java b/lucene/src/test/org/apache/lucene/index/TestLazyBug.javaindex d7556810856..fa58b0324d0 100755--- a/lucene/src/test/org/apache/lucene/index/TestLazyBug.java+++ b/lucene/src/test/org/apache/lucene/index/TestLazyBug.java@@ -67,10 +67,10 @@ public class TestLazyBug extends LuceneTestCase {}};- private Directory makeIndex() throws RuntimeException {- Directory dir = new MockRAMDirectory();+ private Directory makeIndex() throws Exception {+ Random r = newRandom();+ Directory dir = newDirectory(r);try {- Random r = newRandom();IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(r,TEST_VERSION_CURRENT, new MockAnalyzer()));LogMergePolicy lmp = (LogMergePolicy) writer.getConfig().getMergePolicy();@@ -120,6 +120,7 @@ public class TestLazyBug extends LuceneTestCase {}}reader.close();+ dir.close();}public void testLazyWorks() throws Exception {diff --git a/lucene/src/test/org/apache/lucene/index/TestLazyProxSkipping.java b/lucene/src/test/org/apache/lucene/index/TestLazyProxSkipping.javaindex d16e942d48a..e78539b0ddf 100755--- a/lucene/src/test/org/apache/lucene/index/TestLazyProxSkipping.java+++ b/lucene/src/test/org/apache/lucene/index/TestLazyProxSkipping.java@@ -120,8 +120,9 @@ public class TestLazyProxSkipping extends LuceneTestCase {}public void testSeek() throws IOException {- Directory directory = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT, new MockAnalyzer()));+ Random random = newRandom();+ Directory directory = newDirectory(random);+ IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));for (int i = 0; i < 10; i++) {Document doc = new Document();doc.add(new Field(this.field, "a b", Field.Store.YES, Field.Index.ANALYZED));@@ -152,7 +153,8 @@ public class TestLazyProxSkipping extends LuceneTestCase {assertEquals(tp.docID(), i);assertEquals(tp.nextPosition(), 0);}-+ reader.close();+ directory.close();}diff --git a/lucene/src/test/org/apache/lucene/index/TestMultiFields.java b/lucene/src/test/org/apache/lucene/index/TestMultiFields.javaindex 2444acec55e..96c836176b5 100644--- a/lucene/src/test/org/apache/lucene/index/TestMultiFields.java+++ b/lucene/src/test/org/apache/lucene/index/TestMultiFields.java@@ -31,7 +31,7 @@ public class TestMultiFields extends LuceneTestCase {int num = 2 * RANDOM_MULTIPLIER;for (int iter = 0; iter < num; iter++) {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(r);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(r, TEST_VERSION_CURRENT, new MockAnalyzer()).setMergePolicy(NoMergePolicy.COMPOUND_FILES));@@ -131,8 +131,9 @@ public class TestMultiFields extends LuceneTestCase {*/public void testSeparateEnums() throws Exception {- Directory dir = new MockRAMDirectory();- IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT, new MockAnalyzer()));+ Random random = newRandom();+ Directory dir = newDirectory(random);+ IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document d = new Document();d.add(new Field("f", "j", Field.Store.NO, Field.Index.NOT_ANALYZED));w.addDocument(d);diff --git a/lucene/src/test/org/apache/lucene/index/TestNRTReaderWithThreads.java b/lucene/src/test/org/apache/lucene/index/TestNRTReaderWithThreads.javaindex 2037c01a14b..2b4802d554b 100644--- a/lucene/src/test/org/apache/lucene/index/TestNRTReaderWithThreads.java+++ b/lucene/src/test/org/apache/lucene/index/TestNRTReaderWithThreads.java@@ -31,7 +31,7 @@ public class TestNRTReaderWithThreads extends LuceneTestCase {AtomicInteger seq = new AtomicInteger(1);public void testIndexing() throws Exception {- Directory mainDir = new MockRAMDirectory();+ Directory mainDir = newDirectory(random);IndexWriter writer = new IndexWriter(mainDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(10));((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2);((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false);diff --git a/lucene/src/test/org/apache/lucene/index/TestNewestSegment.java b/lucene/src/test/org/apache/lucene/index/TestNewestSegment.javaindex 3f7217f459e..b747a9067b0 100644--- a/lucene/src/test/org/apache/lucene/index/TestNewestSegment.java+++ b/lucene/src/test/org/apache/lucene/index/TestNewestSegment.java@@ -17,6 +17,8 @@ package org.apache.lucene.index;* limitations under the License.*/+import java.util.Random;+import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.index.IndexWriter.MaxFieldLength;@@ -25,9 +27,12 @@ import org.apache.lucene.util.LuceneTestCase;public class TestNewestSegment extends LuceneTestCase {public void testNewestSegment() throws Exception {- MockRAMDirectory directory = new MockRAMDirectory();+ Random random = newRandom();+ MockRAMDirectory directory = newDirectory(random);Analyzer analyzer = new MockAnalyzer();- IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT, new MockAnalyzer()));+ IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));assertNull(writer.newestSegment());+ writer.close();+ directory.close();}}diff --git a/lucene/src/test/org/apache/lucene/index/TestNoDeletionPolicy.java b/lucene/src/test/org/apache/lucene/index/TestNoDeletionPolicy.javaindex 66f62252898..55407d11513 100644--- a/lucene/src/test/org/apache/lucene/index/TestNoDeletionPolicy.java+++ b/lucene/src/test/org/apache/lucene/index/TestNoDeletionPolicy.java@@ -23,6 +23,7 @@ import java.lang.reflect.Constructor;import java.lang.reflect.Method;import java.lang.reflect.Modifier;import java.util.Arrays;+import java.util.Random;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;@@ -73,8 +74,9 @@ public class TestNoDeletionPolicy extends LuceneTestCaseJ4 {@Testpublic void testAllCommitsRemain() throws Exception {- Directory dir = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(),+ Random random = newRandom();+ Directory dir = newDirectory(random);+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setIndexDeletionPolicy(NoDeletionPolicy.INSTANCE));for (int i = 0; i < 10; i++) {@@ -85,6 +87,7 @@ public class TestNoDeletionPolicy extends LuceneTestCaseJ4 {assertEquals("wrong number of commits !", i + 1, IndexReader.listCommits(dir).size());}writer.close();+ dir.close();}}diff --git a/lucene/src/test/org/apache/lucene/index/TestNorms.java b/lucene/src/test/org/apache/lucene/index/TestNorms.javaindex 6dbe891f101..83c5380d17d 100755--- a/lucene/src/test/org/apache/lucene/index/TestNorms.java+++ b/lucene/src/test/org/apache/lucene/index/TestNorms.java@@ -76,7 +76,7 @@ public class TestNorms extends LuceneTestCase {*/public void testNorms() throws IOException {Random random = newRandom();- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(random);norms = new ArrayList<Float>();modifiedNorms = new ArrayList<Float>();@@ -93,13 +93,13 @@ public class TestNorms extends LuceneTestCase {modifiedNorms = new ArrayList<Float>();numDocNorms = 0;- Directory dir2 = new MockRAMDirectory();+ Directory dir2 = newDirectory(random);createIndex(random, dir2);doTestNorms(random, dir2);// add index1 and index2 to a third index: index3- Directory dir3 = new MockRAMDirectory();+ Directory dir3 = newDirectory(random);createIndex(random, dir3);IndexWriter iw = new IndexWriter(dir3, newIndexWriterConfig(random,diff --git a/lucene/src/test/org/apache/lucene/index/TestOmitTf.java b/lucene/src/test/org/apache/lucene/index/TestOmitTf.javaindex af5f8928d91..947a1ff347f 100644--- a/lucene/src/test/org/apache/lucene/index/TestOmitTf.java+++ b/lucene/src/test/org/apache/lucene/index/TestOmitTf.java@@ -19,6 +19,7 @@ package org.apache.lucene.index;import java.io.IOException;import java.util.Collection;+import java.util.Random;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util._TestUtil;@@ -29,12 +30,18 @@ import org.apache.lucene.document.Field;import org.apache.lucene.search.*;import org.apache.lucene.search.BooleanClause.Occur;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.search.Explanation.IDFExplanation;public class TestOmitTf extends LuceneTestCase {-+ private Random random;++ @Override+ public void setUp() throws Exception {+ super.setUp();+ random = newRandom();+ }+public static class SimpleSimilarity extends Similarity {@Override public float lengthNorm(String field, int numTerms) { return 1.0f; }@Override public float queryNorm(float sumOfSquaredWeights) { return 1.0f; }@@ -59,9 +66,9 @@ public class TestOmitTf extends LuceneTestCase {// Tests whether the DocumentWriter correctly enable the// omitTermFreqAndPositions bit in the FieldInfopublic void testOmitTermFreqAndPositions() throws Exception {- Directory ram = new MockRAMDirectory();+ Directory ram = newDirectory(random);Analyzer analyzer = new MockAnalyzer();- IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT, analyzer));+ IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));Document d = new Document();// this field will have Tf@@ -106,9 +113,9 @@ public class TestOmitTf extends LuceneTestCase {// Tests whether merging of docs that have different// omitTermFreqAndPositions for the same field workspublic void testMixedMerge() throws Exception {- Directory ram = new MockRAMDirectory();+ Directory ram = newDirectory(random);Analyzer analyzer = new MockAnalyzer();- IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(newRandom(),+ IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(random,TEST_VERSION_CURRENT, analyzer).setMaxBufferedDocs(3));((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2);Document d = new Document();@@ -159,9 +166,9 @@ public class TestOmitTf extends LuceneTestCase {// field X, then adding docs that do omitTermFreqAndPositions for that same// field,public void testMixedRAM() throws Exception {- Directory ram = new MockRAMDirectory();+ Directory ram = newDirectory(random);Analyzer analyzer = new MockAnalyzer();- IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(newRandom(),+ IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(random,TEST_VERSION_CURRENT, analyzer).setMaxBufferedDocs(10));((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2);Document d = new Document();@@ -207,9 +214,9 @@ public class TestOmitTf extends LuceneTestCase {// Verifies no *.prx exists when all fields omit term freq:public void testNoPrxFile() throws Throwable {- Directory ram = new MockRAMDirectory();+ Directory ram = newDirectory(random);Analyzer analyzer = new MockAnalyzer();- IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(newRandom(),+ IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(random,TEST_VERSION_CURRENT, analyzer).setMaxBufferedDocs(3));LogMergePolicy lmp = (LogMergePolicy) writer.getConfig().getMergePolicy();lmp.setMergeFactor(2);@@ -240,9 +247,9 @@ public class TestOmitTf extends LuceneTestCase {// Test scores with one field with Term Freqs and one without, otherwise with equal contentpublic void testBasic() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);Analyzer analyzer = new MockAnalyzer();- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(),+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, analyzer).setMaxBufferedDocs(2).setSimilarity(new SimpleSimilarity()));((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2);diff --git a/lucene/src/test/org/apache/lucene/index/TestParallelReader.java b/lucene/src/test/org/apache/lucene/index/TestParallelReader.javaindex f1c0f25b403..905bc4ce22f 100644--- a/lucene/src/test/org/apache/lucene/index/TestParallelReader.java+++ b/lucene/src/test/org/apache/lucene/index/TestParallelReader.java@@ -40,9 +40,10 @@ import org.apache.lucene.util.LuceneTestCase;public class TestParallelReader extends LuceneTestCase {- private Searcher parallel;- private Searcher single;+ private IndexSearcher parallel;+ private IndexSearcher single;private Random random;+ private Directory dir, dir1, dir2;@Overrideprotected void setUp() throws Exception {@@ -51,6 +52,16 @@ public class TestParallelReader extends LuceneTestCase {single = single(random);parallel = parallel(random);}++ @Override+ protected void tearDown() throws Exception {+ single.getIndexReader().close();+ parallel.getIndexReader().close();+ dir.close();+ dir1.close();+ dir2.close();+ super.tearDown();+ }public void testQueries() throws Exception {queryTest(new TermQuery(new Term("f1", "v1")));@@ -80,6 +91,9 @@ public class TestParallelReader extends LuceneTestCase {assertTrue(fieldNames.contains("f2"));assertTrue(fieldNames.contains("f3"));assertTrue(fieldNames.contains("f4"));+ pr.close();+ dir1.close();+ dir2.close();}public void testDocument() throws IOException {@@ -101,6 +115,9 @@ public class TestParallelReader extends LuceneTestCase {assertEquals("v2", doc24.get("f4"));assertEquals("v2", doc223.get("f2"));assertEquals("v2", doc223.get("f3"));+ pr.close();+ dir1.close();+ dir2.close();}public void testIncompatibleIndexes() throws IOException {@@ -108,7 +125,7 @@ public class TestParallelReader extends LuceneTestCase {Directory dir1 = getDir1(random);// one document only:- Directory dir2 = new MockRAMDirectory();+ Directory dir2 = newDirectory(random);IndexWriter w2 = new IndexWriter(dir2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document d3 = new Document();d3.add(new Field("f3", "v1", Field.Store.YES, Field.Index.ANALYZED));@@ -117,12 +134,17 @@ public class TestParallelReader extends LuceneTestCase {ParallelReader pr = new ParallelReader();pr.add(IndexReader.open(dir1, false));+ IndexReader ir = IndexReader.open(dir2, false);try {- pr.add(IndexReader.open(dir2, false));+ pr.add(ir);fail("didn't get exptected exception: indexes don't have same number of documents");} catch (IllegalArgumentException e) {// expected exception}+ pr.close();+ ir.close();+ dir1.close();+ dir2.close();}public void testIsCurrent() throws IOException {@@ -147,6 +169,9 @@ public class TestParallelReader extends LuceneTestCase {// now both are not current anymoreassertFalse(pr.isCurrent());+ pr.close();+ dir1.close();+ dir2.close();}public void testIsOptimized() throws IOException {@@ -197,7 +222,8 @@ public class TestParallelReader extends LuceneTestCase {// now both indexes are optimizedassertTrue(pr.isOptimized());pr.close();-+ dir1.close();+ dir2.close();}private void queryTest(Query query) throws IOException {@@ -216,8 +242,8 @@ public class TestParallelReader extends LuceneTestCase {}// Fields 1-4 indexed together:- private Searcher single(Random random) throws IOException {- Directory dir = new MockRAMDirectory();+ private IndexSearcher single(Random random) throws IOException {+ dir = newDirectory(random);IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document d1 = new Document();d1.add(new Field("f1", "v1", Field.Store.YES, Field.Index.ANALYZED));@@ -237,9 +263,9 @@ public class TestParallelReader extends LuceneTestCase {}// Fields 1 & 2 in one index, 3 & 4 in other, with ParallelReader:- private Searcher parallel(Random random) throws IOException {- Directory dir1 = getDir1(random);- Directory dir2 = getDir2(random);+ private IndexSearcher parallel(Random random) throws IOException {+ dir1 = getDir1(random);+ dir2 = getDir2(random);ParallelReader pr = new ParallelReader();pr.add(IndexReader.open(dir1, false));pr.add(IndexReader.open(dir2, false));@@ -247,7 +273,7 @@ public class TestParallelReader extends LuceneTestCase {}private Directory getDir1(Random random) throws IOException {- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(random);IndexWriter w1 = new IndexWriter(dir1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document d1 = new Document();d1.add(new Field("f1", "v1", Field.Store.YES, Field.Index.ANALYZED));@@ -262,7 +288,7 @@ public class TestParallelReader extends LuceneTestCase {}private Directory getDir2(Random random) throws IOException {- Directory dir2 = new MockRAMDirectory();+ Directory dir2 = newDirectory(random);IndexWriter w2 = new IndexWriter(dir2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document d3 = new Document();d3.add(new Field("f3", "v1", Field.Store.YES, Field.Index.ANALYZED));diff --git a/lucene/src/test/org/apache/lucene/index/TestParallelReaderEmptyIndex.java b/lucene/src/test/org/apache/lucene/index/TestParallelReaderEmptyIndex.javaindex 55dddd3805c..31ab9d4b5a7 100644--- a/lucene/src/test/org/apache/lucene/index/TestParallelReaderEmptyIndex.java+++ b/lucene/src/test/org/apache/lucene/index/TestParallelReaderEmptyIndex.java@@ -48,13 +48,13 @@ public class TestParallelReaderEmptyIndex extends LuceneTestCase {*/public void testEmptyIndex() throws IOException {Random random = newRandom();- MockRAMDirectory rd1 = new MockRAMDirectory();+ MockRAMDirectory rd1 = newDirectory(random);IndexWriter iw = new IndexWriter(rd1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));iw.close();- MockRAMDirectory rd2 = new MockRAMDirectory(rd1);+ MockRAMDirectory rd2 = newDirectory(random, rd1);- MockRAMDirectory rdOut = new MockRAMDirectory();+ MockRAMDirectory rdOut = newDirectory(random);IndexWriter iwOut = new IndexWriter(rdOut, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));ParallelReader pr = new ParallelReader();@@ -78,8 +78,8 @@ public class TestParallelReaderEmptyIndex extends LuceneTestCase {* any exception.*/public void testEmptyIndexWithVectors() throws IOException {- MockRAMDirectory rd1 = new MockRAMDirectory();Random random = newRandom();+ MockRAMDirectory rd1 = newDirectory(random);{IndexWriter iw = new IndexWriter(rd1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();@@ -100,7 +100,7 @@ public class TestParallelReaderEmptyIndex extends LuceneTestCase {iw.close();}- MockRAMDirectory rd2 = new MockRAMDirectory();+ MockRAMDirectory rd2 = newDirectory(random);{IndexWriter iw = new IndexWriter(rd2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();@@ -108,7 +108,7 @@ public class TestParallelReaderEmptyIndex extends LuceneTestCase {iw.close();}- MockRAMDirectory rdOut = new MockRAMDirectory();+ MockRAMDirectory rdOut = newDirectory(random);IndexWriter iwOut = new IndexWriter(rdOut, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));ParallelReader pr = new ParallelReader();diff --git a/lucene/src/test/org/apache/lucene/index/TestParallelTermEnum.java b/lucene/src/test/org/apache/lucene/index/TestParallelTermEnum.javaindex d8fdb8b92aa..1d07b71cfd4 100755--- a/lucene/src/test/org/apache/lucene/index/TestParallelTermEnum.java+++ b/lucene/src/test/org/apache/lucene/index/TestParallelTermEnum.java@@ -32,13 +32,15 @@ import org.apache.lucene.util.Bits;public class TestParallelTermEnum extends LuceneTestCase {private IndexReader ir1;private IndexReader ir2;-+ private MockRAMDirectory rd1;+ private MockRAMDirectory rd2;+@Overrideprotected void setUp() throws Exception {super.setUp();Document doc;Random random = newRandom();- MockRAMDirectory rd1 = new MockRAMDirectory();+ rd1 = newDirectory(random);IndexWriter iw1 = new IndexWriter(rd1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));doc = new Document();@@ -50,7 +52,7 @@ public class TestParallelTermEnum extends LuceneTestCase {iw1.addDocument(doc);iw1.close();- MockRAMDirectory rd2 = new MockRAMDirectory();+ rd2 = newDirectory(random);IndexWriter iw2 = new IndexWriter(rd2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));doc = new Document();@@ -71,6 +73,8 @@ public class TestParallelTermEnum extends LuceneTestCase {protected void tearDown() throws Exception {ir1.close();ir2.close();+ rd1.close();+ rd2.close();super.tearDown();}diff --git a/lucene/src/test/org/apache/lucene/index/TestPayloadProcessorProvider.java b/lucene/src/test/org/apache/lucene/index/TestPayloadProcessorProvider.javaindex ca6b6fa99c5..f5132932aff 100644--- a/lucene/src/test/org/apache/lucene/index/TestPayloadProcessorProvider.java+++ b/lucene/src/test/org/apache/lucene/index/TestPayloadProcessorProvider.java@@ -126,7 +126,7 @@ public class TestPayloadProcessorProvider extends LuceneTestCaseJ4 {private void populateDirs(Random random, Directory[] dirs, boolean multipleCommits)throws IOException {for (int i = 0; i < dirs.length; i++) {- dirs[i] = new MockRAMDirectory();+ dirs[i] = newDirectory(random);populateDocs(random, dirs[i], multipleCommits);verifyPayloadExists(dirs[i], "p", new BytesRef("p1"), NUM_DOCS);verifyPayloadExists(dirs[i], "p", new BytesRef("p2"), NUM_DOCS);@@ -179,7 +179,7 @@ public class TestPayloadProcessorProvider extends LuceneTestCaseJ4 {Directory[] dirs = new Directory[2];populateDirs(random, dirs, multipleCommits);- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);if (!addToEmptyIndex) {populateDocs(random, dir, multipleCommits);verifyPayloadExists(dir, "p", new BytesRef("p1"), NUM_DOCS);@@ -212,6 +212,9 @@ public class TestPayloadProcessorProvider extends LuceneTestCaseJ4 {numExpectedPayloads = NUM_DOCS * dirs.length+ (addToEmptyIndex ? 0 : NUM_DOCS);verifyPayloadExists(dir, "p", new BytesRef("p2"), numExpectedPayloads);+ for (Directory d : dirs)+ d.close();+ dir.close();}@Test@@ -237,7 +240,7 @@ public class TestPayloadProcessorProvider extends LuceneTestCaseJ4 {@Testpublic void testRegularMerges() throws Exception {Random random = newRandom();- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);populateDocs(random, dir, true);verifyPayloadExists(dir, "p", new BytesRef("p1"), NUM_DOCS);verifyPayloadExists(dir, "p", new BytesRef("p2"), NUM_DOCS);@@ -253,6 +256,7 @@ public class TestPayloadProcessorProvider extends LuceneTestCaseJ4 {verifyPayloadExists(dir, "p", new BytesRef("p1"), 0);verifyPayloadExists(dir, "p", new BytesRef("p2"), NUM_DOCS);+ dir.close();}}diff --git a/lucene/src/test/org/apache/lucene/index/TestPayloads.java b/lucene/src/test/org/apache/lucene/index/TestPayloads.javaindex 4451f176f2c..fc5dd3bba44 100644--- a/lucene/src/test/org/apache/lucene/index/TestPayloads.java+++ b/lucene/src/test/org/apache/lucene/index/TestPayloads.java@@ -101,7 +101,7 @@ public class TestPayloads extends LuceneTestCase {// payload bit in the FieldInfopublic void testPayloadFieldBit() throws Exception {rnd = newRandom();- Directory ram = new MockRAMDirectory();+ Directory ram = newDirectory(rnd);PayloadAnalyzer analyzer = new PayloadAnalyzer();IndexWriter writer = new IndexWriter(ram, newIndexWriterConfig(rnd, TEST_VERSION_CURRENT, analyzer));Document d = new Document();@@ -153,20 +153,22 @@ public class TestPayloads extends LuceneTestCase {assertTrue("Payload field bit should be set.", fi.fieldInfo("f2").storePayloads);assertTrue("Payload field bit should be set.", fi.fieldInfo("f3").storePayloads);reader.close();+ ram.close();}// Tests if payloads are correctly stored and loaded using both RamDirectory and FSDirectorypublic void testPayloadsEncoding() throws Exception {rnd = newRandom();// first perform the test using a RAMDirectory- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(rnd);performTest(rnd, dir);-+ dir.close();// now use a FSDirectory and repeat same testFile dirName = _TestUtil.getTempDir("test_payloads");dir = FSDirectory.open(dirName);performTest(rnd, dir);_TestUtil.rmDir(dirName);+ dir.close();}// builds an index with payloads in the given Directory and performs@@ -489,7 +491,7 @@ public class TestPayloads extends LuceneTestCase {final int numDocs = 50 * RANDOM_MULTIPLIER;final ByteArrayPool pool = new ByteArrayPool(numThreads, 5);- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(rnd);final IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(rnd,TEST_VERSION_CURRENT, new MockAnalyzer()));final String field = "test";@@ -535,7 +537,7 @@ public class TestPayloads extends LuceneTestCase {}}reader.close();-+ dir.close();assertEquals(pool.size(), numThreads);}diff --git a/lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java b/lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.javaindex 47d97aa0dd7..cb6e6308d08 100644--- a/lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java+++ b/lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java@@ -21,19 +21,32 @@ import static org.junit.Assert.*;import java.io.IOException;import java.util.Map;-import java.util.Random;import java.util.Map.Entry;import org.apache.lucene.document.Document;import org.apache.lucene.index.IndexWriterConfig.OpenMode;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;+import org.junit.After;+import org.junit.Before;import org.junit.Test;public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPolicy {-// Keep it a class member so that getDeletionPolicy can use it- private Directory snapshotDir = new MockRAMDirectory();+ private Directory snapshotDir;++ @Before+ @Override+ public void setUp() throws Exception {+ super.setUp();+ snapshotDir = newDirectory(random);+ }++ @After+ @Override+ public void tearDown() throws Exception {+ snapshotDir.close();+ super.tearDown();+ }@Overrideprotected SnapshotDeletionPolicy getDeletionPolicy() throws IOException {@@ -57,9 +70,8 @@ public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPo@Override@Testpublic void testExistingSnapshots() throws Exception {- Random random = newRandom();int numSnapshots = 3;- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);PersistentSnapshotDeletionPolicy psdp = (PersistentSnapshotDeletionPolicy) getDeletionPolicy();IndexWriter writer = new IndexWriter(dir, getConfig(random, psdp));prepareIndexAndSnapshots(psdp, writer, numSnapshots, "snapshot");@@ -75,6 +87,7 @@ public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPoassertSnapshotExists(dir, psdp, numSnapshots);assertEquals(numSnapshots, psdp.getSnapshots().size());psdp.close();+ dir.close();}@Test(expected=IllegalArgumentException.class)@@ -85,9 +98,10 @@ public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPo@Testpublic void testInvalidSnapshotInfos() throws Exception {// Add the correct number of documents (1), but without snapshot information- IndexWriter writer = new IndexWriter(snapshotDir, getConfig(newRandom(), null));+ IndexWriter writer = new IndexWriter(snapshotDir, getConfig(random, null));writer.addDocument(new Document());writer.close();+ PersistentSnapshotDeletionPolicy dp = null;try {new PersistentSnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy(), snapshotDir, OpenMode.APPEND,@@ -100,7 +114,7 @@ public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPo@Testpublic void testNoSnapshotInfos() throws Exception {// Initialize an empty index in snapshotDir - PSDP should initialize successfully.- new IndexWriter(snapshotDir, getConfig(newRandom(), null)).close();+ new IndexWriter(snapshotDir, getConfig(random, null)).close();new PersistentSnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy(), snapshotDir, OpenMode.APPEND,TEST_VERSION_CURRENT).close();@@ -109,7 +123,7 @@ public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPo@Test(expected=IllegalStateException.class)public void testTooManySnapshotInfos() throws Exception {// Write two documents to the snapshots directory - illegal.- IndexWriter writer = new IndexWriter(snapshotDir, getConfig(newRandom(), null));+ IndexWriter writer = new IndexWriter(snapshotDir, getConfig(random, null));writer.addDocument(new Document());writer.addDocument(new Document());writer.close();@@ -122,9 +136,9 @@ public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPo@Testpublic void testSnapshotRelease() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);PersistentSnapshotDeletionPolicy psdp = (PersistentSnapshotDeletionPolicy) getDeletionPolicy();- IndexWriter writer = new IndexWriter(dir, getConfig(newRandom(), psdp));+ IndexWriter writer = new IndexWriter(dir, getConfig(random, psdp));prepareIndexAndSnapshots(psdp, writer, 1, "snapshot");writer.close();@@ -135,6 +149,8 @@ public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPonew KeepOnlyLastCommitDeletionPolicy(), snapshotDir, OpenMode.APPEND,TEST_VERSION_CURRENT);assertEquals("Should have no snapshots !", 0, psdp.getSnapshots().size());+ psdp.close();+ dir.close();}}diff --git a/lucene/src/test/org/apache/lucene/index/TestRollback.java b/lucene/src/test/org/apache/lucene/index/TestRollback.javaindex e0308c91319..23c537b415d 100644--- a/lucene/src/test/org/apache/lucene/index/TestRollback.java+++ b/lucene/src/test/org/apache/lucene/index/TestRollback.java@@ -25,15 +25,14 @@ import org.apache.lucene.document.Field;import org.apache.lucene.document.Field.Index;import org.apache.lucene.document.Field.Store;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;public class TestRollback extends LuceneTestCase {// LUCENE-2536public void testRollbackIntegrityWithBufferFlush() throws Exception {- Directory dir = new MockRAMDirectory();Random random = newRandom();+ Directory dir = newDirectory(random);RandomIndexWriter rw = new RandomIndexWriter(random, dir);for (int i = 0; i < 5; i++) {Document doc = new Document();diff --git a/lucene/src/test/org/apache/lucene/index/TestSegmentMerger.java b/lucene/src/test/org/apache/lucene/index/TestSegmentMerger.javaindex 2f6a618120e..15da4f2d46b 100644--- a/lucene/src/test/org/apache/lucene/index/TestSegmentMerger.java+++ b/lucene/src/test/org/apache/lucene/index/TestSegmentMerger.java@@ -27,17 +27,18 @@ import org.apache.lucene.util.BytesRef;import java.io.IOException;import java.util.Collection;+import java.util.Random;public class TestSegmentMerger extends LuceneTestCase {//The variables for the new merged segment- private Directory mergedDir = new MockRAMDirectory();+ private Directory mergedDir;private String mergedSegment = "test";//First segment to be merged- private Directory merge1Dir = new MockRAMDirectory();+ private Directory merge1Dir;private Document doc1 = new Document();private SegmentReader reader1 = null;//Second Segment to be merged- private Directory merge2Dir = new MockRAMDirectory();+ private Directory merge2Dir;private Document doc2 = new Document();private SegmentReader reader2 = null;@@ -49,6 +50,10 @@ public class TestSegmentMerger extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();+ Random random = newRandom();+ mergedDir = newDirectory(random);+ merge1Dir = newDirectory(random);+ merge2Dir = newDirectory(random);DocHelper.setupDoc(doc1);SegmentInfo info1 = DocHelper.writeDoc(merge1Dir, doc1);DocHelper.setupDoc(doc2);@@ -56,6 +61,16 @@ public class TestSegmentMerger extends LuceneTestCase {reader1 = SegmentReader.get(true, info1, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR);reader2 = SegmentReader.get(true, info2, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR);}++ @Override+ protected void tearDown() throws Exception {+ reader1.close();+ reader2.close();+ mergedDir.close();+ merge1Dir.close();+ merge2Dir.close();+ super.tearDown();+ }public void test() {assertTrue(mergedDir != null);@@ -118,5 +133,6 @@ public class TestSegmentMerger extends LuceneTestCase {}TestSegmentReader.checkNorms(mergedReader);+ mergedReader.close();}}diff --git a/lucene/src/test/org/apache/lucene/index/TestSegmentReader.java b/lucene/src/test/org/apache/lucene/index/TestSegmentReader.javaindex 8db0a77a396..b5c75987657 100644--- a/lucene/src/test/org/apache/lucene/index/TestSegmentReader.java+++ b/lucene/src/test/org/apache/lucene/index/TestSegmentReader.java@@ -31,7 +31,7 @@ import org.apache.lucene.search.Similarity;import org.apache.lucene.store.MockRAMDirectory;public class TestSegmentReader extends LuceneTestCase {- private MockRAMDirectory dir = new MockRAMDirectory();+ private MockRAMDirectory dir;private Document testDoc = new Document();private SegmentReader reader = null;@@ -43,10 +43,18 @@ public class TestSegmentReader extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();+ dir = newDirectory(newRandom());DocHelper.setupDoc(testDoc);SegmentInfo info = DocHelper.writeDoc(dir, testDoc);reader = SegmentReader.get(true, info, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR);}++ @Override+ protected void tearDown() throws Exception {+ reader.close();+ dir.close();+ super.tearDown();+ }public void test() {assertTrue(dir != null);@@ -81,6 +89,7 @@ public class TestSegmentReader extends LuceneTestCase {assertTrue(deleteReader.isDeleted(0) == true);assertTrue(deleteReader.hasDeletions() == true);assertTrue(deleteReader.numDocs() == 0);+ deleteReader.close();}public void testGetFieldNameVariations() {diff --git a/lucene/src/test/org/apache/lucene/index/TestSegmentTermDocs.java b/lucene/src/test/org/apache/lucene/index/TestSegmentTermDocs.javaindex 370bab226ad..5f0a504cadf 100644--- a/lucene/src/test/org/apache/lucene/index/TestSegmentTermDocs.java+++ b/lucene/src/test/org/apache/lucene/index/TestSegmentTermDocs.java@@ -18,8 +18,6 @@ package org.apache.lucene.index;*/import org.apache.lucene.util.LuceneTestCase;-import org.apache.lucene.store.MockRAMDirectory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.store.Directory;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;@@ -27,11 +25,13 @@ import org.apache.lucene.document.Field;import org.apache.lucene.util.BytesRef;import java.io.IOException;+import java.util.Random;public class TestSegmentTermDocs extends LuceneTestCase {private Document testDoc = new Document();- private Directory dir = new MockRAMDirectory();+ private Directory dir;private SegmentInfo info;+ private Random random;public TestSegmentTermDocs(String s) {super(s);@@ -40,9 +40,17 @@ public class TestSegmentTermDocs extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();+ random = newRandom();+ dir = newDirectory(random);DocHelper.setupDoc(testDoc);info = DocHelper.writeDoc(dir, testDoc);}++ @Override+ protected void tearDown() throws Exception {+ dir.close();+ super.tearDown();+ }public void test() {assertTrue(dir != null);@@ -103,8 +111,8 @@ public class TestSegmentTermDocs extends LuceneTestCase {}public void testSkipTo(int indexDivisor) throws IOException {- Directory dir = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT, new MockAnalyzer()));+ Directory dir = newDirectory(random);+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Term ta = new Term("content","aaa");for(int i = 0; i < 10; i++)@@ -248,7 +256,6 @@ public class TestSegmentTermDocs extends LuceneTestCase {}public void testIndexDivisor() throws IOException {- dir = new MockRAMDirectory();testDoc = new Document();DocHelper.setupDoc(testDoc);DocHelper.writeDoc(dir, testDoc);diff --git a/lucene/src/test/org/apache/lucene/index/TestSegmentTermEnum.java b/lucene/src/test/org/apache/lucene/index/TestSegmentTermEnum.javaindex e781e5acda9..9ff59c07927 100644--- a/lucene/src/test/org/apache/lucene/index/TestSegmentTermEnum.java+++ b/lucene/src/test/org/apache/lucene/index/TestSegmentTermEnum.java@@ -28,16 +28,27 @@ import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.index.IndexWriterConfig.OpenMode;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;-import org.apache.lucene.store.MockRAMDirectory;public class TestSegmentTermEnum extends LuceneTestCase {- Directory dir = new MockRAMDirectory();+ Directory dir;+ Random random;++ @Override+ public void setUp() throws Exception {+ super.setUp();+ random = newRandom();+ dir = newDirectory(random);+ }++ @Override+ public void tearDown() throws Exception {+ dir.close();+ super.tearDown();+ }public void testTermEnum() throws IOException {- Random random = newRandom();IndexWriter writer = null;writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));@@ -66,8 +77,7 @@ public class TestSegmentTermEnum extends LuceneTestCase {public void testPrevTermAtEnd() throws IOException{- Directory dir = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard")));addDoc(writer, "aaa bbb");writer.close();SegmentReader reader = SegmentReader.getOnlySegmentReader(dir);@@ -81,6 +91,7 @@ public class TestSegmentTermEnum extends LuceneTestCase {assertEquals(TermsEnum.SeekStatus.FOUND, terms.seek(ordB));assertEquals("bbb", terms.term().utf8ToString());+ reader.close();}private void verifyDocFreq()@@ -113,6 +124,7 @@ public class TestSegmentTermEnum extends LuceneTestCase {// assert that term is 'bbb'assertEquals("bbb", termEnum.term().utf8ToString());assertEquals(100, termEnum.docFreq());+ reader.close();}private void addDoc(IndexWriter writer, String value) throws IOExceptiondiff --git a/lucene/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java b/lucene/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.javaindex 6d848968a5b..c47756fb7e5 100644--- a/lucene/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java+++ b/lucene/src/test/org/apache/lucene/index/TestSnapshotDeletionPolicy.java@@ -23,6 +23,7 @@ import org.apache.lucene.index.SnapshotDeletionPolicy;import org.apache.lucene.util.LuceneTestCaseJ4;import org.apache.lucene.util.ThreadInterruptedException;import org.apache.lucene.util._TestUtil;+import org.junit.Before;import org.junit.Test;//@@ -31,9 +32,16 @@ import org.junit.Test;//public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {-+ protected Random random;public static final String INDEX_PATH = "test.snapshots";+ @Before+ @Override+ public void setUp() throws Exception {+ super.setUp();+ random = newRandom();+ }+protected IndexWriterConfig getConfig(Random random, IndexDeletionPolicy dp) {IndexWriterConfig conf = newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer());if (dp != null) {@@ -85,7 +93,6 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {@Testpublic void testSnapshotDeletionPolicy() throws Exception {- Random random = newRandom();File dir = _TestUtil.getTempDir(INDEX_PATH);try {Directory fsDir = FSDirectory.open(dir);@@ -95,7 +102,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {_TestUtil.rmDir(dir);}- MockRAMDirectory dir2 = new MockRAMDirectory();+ MockRAMDirectory dir2 = newDirectory(random);runTest(random, dir2);dir2.close();}@@ -231,10 +238,9 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {public void testBasicSnapshots() throws Exception {int numSnapshots = 3;SnapshotDeletionPolicy sdp = getDeletionPolicy();- Random random = newRandom();// Create 3 snapshots: snapshot0, snapshot1, snapshot2- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));prepareIndexAndSnapshots(sdp, writer, numSnapshots, "snapshot");writer.close();@@ -259,12 +265,12 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {// expected - snapshot should not exist}}+ dir.close();}@Testpublic void testMultiThreadedSnapshotting() throws Exception {- Random random = newRandom();- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);final SnapshotDeletionPolicy sdp = getDeletionPolicy();final IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));@@ -303,13 +309,13 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {}assertEquals(1, IndexReader.listCommits(dir).size());writer.close();+ dir.close();}@Testpublic void testRollbackToOldSnapshot() throws Exception {- Random random = newRandom();int numSnapshots = 2;- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);SnapshotDeletionPolicy sdp = getDeletionPolicy();IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));prepareIndexAndSnapshots(sdp, writer, numSnapshots, "snapshot");@@ -325,12 +331,12 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {// but 'snapshot1' files will still exist (need to release snapshot before they can be deleted).String segFileName = sdp.getSnapshot("snapshot1").getSegmentsFileName();assertTrue("snapshot files should exist in the directory: " + segFileName, dir.fileExists(segFileName));+ dir.close();}@Testpublic void testReleaseSnapshot() throws Exception {- Random random = newRandom();- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);SnapshotDeletionPolicy sdp = getDeletionPolicy();IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));prepareIndexAndSnapshots(sdp, writer, 1, "snapshot");@@ -353,15 +359,15 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {assertNull(sdp.getSnapshots().get(snapId));writer.deleteUnusedFiles();assertFalse("segments file should not be found in dirctory: " + segFileName, dir.fileExists(segFileName));+ dir.close();}@Testpublic void testExistingSnapshots() throws Exception {- Random random = newRandom();// Tests the ability to construct a SDP from existing snapshots, and// asserts that those snapshots/commit points are protected.int numSnapshots = 3;- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);SnapshotDeletionPolicy sdp = getDeletionPolicy();IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));prepareIndexAndSnapshots(sdp, writer, numSnapshots, "snapshot");@@ -374,12 +380,12 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {writer.deleteUnusedFiles();writer.close();assertSnapshotExists(dir, sdp, numSnapshots);+ dir.close();}@Testpublic void testSnapshotLastCommitTwice() throws Exception {- Random random = newRandom();- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);SnapshotDeletionPolicy sdp = getDeletionPolicy();IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));writer.addDocument(new Document());@@ -401,14 +407,14 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {checkSnapshotExists(dir, ic2);writer.close();+ dir.close();}@Testpublic void testMissingCommits() throws Exception {- Random random = newRandom();// Tests the behavior of SDP when commits that are given at ctor are missing// on onInit().- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);SnapshotDeletionPolicy sdp = getDeletionPolicy();IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));writer.addDocument(new Document());@@ -436,6 +442,7 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCaseJ4 {} catch (IllegalStateException e) {// expected.}+ dir.close();}}diff --git a/lucene/src/test/org/apache/lucene/index/TestStressIndexing.java b/lucene/src/test/org/apache/lucene/index/TestStressIndexing.javaindex ef11a55f477..a109f751d12 100644--- a/lucene/src/test/org/apache/lucene/index/TestStressIndexing.java+++ b/lucene/src/test/org/apache/lucene/index/TestStressIndexing.java@@ -169,7 +169,7 @@ public class TestStressIndexing extends MultiCodecTestCase {RANDOM = newRandom();// With ConcurrentMergeScheduler, in RAMDir- Directory directory = new MockRAMDirectory();+ Directory directory = newDirectory(RANDOM);runStressTest(directory, new ConcurrentMergeScheduler());directory.close();diff --git a/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java b/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.javaindex 8a930e70e07..7c7993def76 100644--- a/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java+++ b/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java@@ -64,7 +64,7 @@ public class TestStressIndexing2 extends MultiCodecTestCase {public void testRandomIWReader() throws Throwable {r = newRandom();- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(r);// TODO: verify equals using IW.getReaderDocsAndWriter dw = indexRandomIWReader(5, 3, 100, dir);@@ -78,9 +78,9 @@ public class TestStressIndexing2 extends MultiCodecTestCase {public void testRandom() throws Throwable {r = newRandom();- Directory dir1 = new MockRAMDirectory();+ Directory dir1 = newDirectory(r);// dir1 = FSDirectory.open("foofoofoo");- Directory dir2 = new MockRAMDirectory();+ Directory dir2 = newDirectory(r);// mergeFactor=2; maxBufferedDocs=2; Map docs = indexRandom(1, 3, 2, dir1);int maxThreadStates = 1+r.nextInt(10);boolean doReaderPooling = r.nextBoolean();@@ -92,6 +92,8 @@ public class TestStressIndexing2 extends MultiCodecTestCase {// verifyEquals(dir2, dir2, "id");verifyEquals(dir1, dir2, "id");+ dir1.close();+ dir2.close();}public void testMultiConfig() throws Throwable {@@ -111,13 +113,15 @@ public class TestStressIndexing2 extends MultiCodecTestCase {int nThreads=r.nextInt(5)+1;int iter=r.nextInt(5)+1;int range=r.nextInt(20)+1;- Directory dir1 = new MockRAMDirectory();- Directory dir2 = new MockRAMDirectory();+ Directory dir1 = newDirectory(r);+ Directory dir2 = newDirectory(r);Map<String,Document> docs = indexRandom(nThreads, iter, range, dir1, maxThreadStates, doReaderPooling);//System.out.println("TEST: index serial");indexSerial(r, docs, dir2);//System.out.println("TEST: verify");verifyEquals(dir1, dir2, "id");+ dir1.close();+ dir2.close();}}diff --git a/lucene/src/test/org/apache/lucene/index/TestTermVectorsReader.java b/lucene/src/test/org/apache/lucene/index/TestTermVectorsReader.javaindex 0c6cf62df81..f5446e89a57 100644--- a/lucene/src/test/org/apache/lucene/index/TestTermVectorsReader.java+++ b/lucene/src/test/org/apache/lucene/index/TestTermVectorsReader.java@@ -22,6 +22,7 @@ import java.io.Reader;import java.util.Arrays;import java.util.Iterator;import java.util.Map;+import java.util.Random;import java.util.SortedSet;import org.apache.lucene.analysis.Analyzer;@@ -43,7 +44,7 @@ public class TestTermVectorsReader extends LuceneTestCase {private String[] testTerms = {"this", "is", "a", "test"};private int[][] positions = new int[testTerms.length][];private TermVectorOffsetInfo[][] offsets = new TermVectorOffsetInfo[testTerms.length][];- private MockRAMDirectory dir = new MockRAMDirectory();+ private MockRAMDirectory dir;private String seg;private FieldInfos fieldInfos = new FieldInfos();private static int TERM_FREQ = 3;@@ -93,7 +94,9 @@ public class TestTermVectorsReader extends LuceneTestCase {}Arrays.sort(tokens);- IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(newRandom(), TEST_VERSION_CURRENT, new MyAnalyzer()).setMaxBufferedDocs(-1));+ Random random = newRandom();+ dir = newDirectory(random);+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MyAnalyzer()).setMaxBufferedDocs(-1));((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundFile(false);((LogMergePolicy) writer.getConfig().getMergePolicy()).setUseCompoundDocStore(false);((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(10);@@ -122,6 +125,12 @@ public class TestTermVectorsReader extends LuceneTestCase {fieldInfos = new FieldInfos(dir, IndexFileNames.segmentFileName(seg, "", IndexFileNames.FIELD_INFOS_EXTENSION));}++ @Override+ protected void tearDown() throws Exception {+ dir.close();+ super.tearDown();+ }private class MyTokenStream extends TokenStream {int tokenUpto;@@ -182,6 +191,7 @@ public class TestTermVectorsReader extends LuceneTestCase {assertTrue(term.equals(testTerms[i]));}}+ reader.close();}public void testPositionReader() throws IOException {@@ -224,6 +234,7 @@ public class TestTermVectorsReader extends LuceneTestCase {//System.out.println("Term: " + term);assertTrue(term.equals(testTerms[i]));}+ reader.close();}public void testOffsetReader() throws IOException {@@ -252,6 +263,7 @@ public class TestTermVectorsReader extends LuceneTestCase {assertTrue(termVectorOffsetInfo.equals(offsets[i][j]));}}+ reader.close();}public void testMapper() throws IOException {@@ -366,37 +378,45 @@ public class TestTermVectorsReader extends LuceneTestCase {assertEquals(0, docNumAwareMapper.getDocumentNumber());ir.close();-+ reader.close();}/*** Make sure exceptions and bad params are handled appropriately*/- public void testBadParams() {+ public void testBadParams() throws IOException {+ TermVectorsReader reader = null;try {- TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);+ reader = new TermVectorsReader(dir, seg, fieldInfos);//Bad document number, good field numberreader.get(50, testFields[0]);fail();} catch (IOException e) {// expected exception+ } finally {+ reader.close();}try {- TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);+ reader = new TermVectorsReader(dir, seg, fieldInfos);//Bad document number, no fieldreader.get(50);fail();} catch (IOException e) {// expected exception+ } finally {+ reader.close();}try {- TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);+ reader = new TermVectorsReader(dir, seg, fieldInfos);//good document number, bad field numberTermFreqVector vector = reader.get(0, "f50");assertTrue(vector == null);+ reader.close();} catch (IOException e) {fail();+ } finally {+ reader.close();}}diff --git a/lucene/src/test/org/apache/lucene/index/TestTermdocPerf.java b/lucene/src/test/org/apache/lucene/index/TestTermdocPerf.javaindex 0c3d9b28154..09cd81d8a02 100644--- a/lucene/src/test/org/apache/lucene/index/TestTermdocPerf.java+++ b/lucene/src/test/org/apache/lucene/index/TestTermdocPerf.java@@ -57,8 +57,7 @@ class RepeatingTokenStream extends TokenStream {public class TestTermdocPerf extends LuceneTestCase {- void addDocs(Directory dir, final int ndocs, String field, final String val, final int maxTF, final float percentDocs) throws IOException {- final Random random = newRandom();+ void addDocs(final Random random, Directory dir, final int ndocs, String field, final String val, final int maxTF, final float percentDocs) throws IOException {final RepeatingTokenStream ts = new RepeatingTokenStream(val);Analyzer analyzer = new Analyzer() {@@ -87,10 +86,11 @@ public class TestTermdocPerf extends LuceneTestCase {public int doTest(int iter, int ndocs, int maxTF, float percentDocs) throws IOException {- Directory dir = new MockRAMDirectory();+ Random random = newRandom();+ Directory dir = newDirectory(random);long start = System.currentTimeMillis();- addDocs(dir, ndocs, "foo", "val", maxTF, percentDocs);+ addDocs(random, dir, ndocs, "foo", "val", maxTF, percentDocs);long end = System.currentTimeMillis();if (VERBOSE) System.out.println("milliseconds for creation of " + ndocs + " docs = " + (end-start));diff --git a/lucene/src/test/org/apache/lucene/index/TestThreadedOptimize.java b/lucene/src/test/org/apache/lucene/index/TestThreadedOptimize.javaindex 92673c48493..606383a8603 100644--- a/lucene/src/test/org/apache/lucene/index/TestThreadedOptimize.java+++ b/lucene/src/test/org/apache/lucene/index/TestThreadedOptimize.java@@ -139,7 +139,7 @@ public class TestThreadedOptimize extends LuceneTestCase {*/public void testThreadedOptimize() throws Exception {Random random = newRandom();- Directory directory = new MockRAMDirectory();+ Directory directory = newDirectory(random);runTest(random, directory, new SerialMergeScheduler());runTest(random, directory, new ConcurrentMergeScheduler());directory.close();diff --git a/lucene/src/test/org/apache/lucene/index/TestTransactionRollback.java b/lucene/src/test/org/apache/lucene/index/TestTransactionRollback.javaindex b5a2a4b81e9..efe84a2836f 100644--- a/lucene/src/test/org/apache/lucene/index/TestTransactionRollback.java+++ b/lucene/src/test/org/apache/lucene/index/TestTransactionRollback.java@@ -124,7 +124,7 @@ public class TestTransactionRollback extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- dir = new MockRAMDirectory();+ dir = newDirectory(random);random = newRandom();//Build index, of records 1 to 100, committing after each batch of 10IndexDeletionPolicy sdp=new KeepAllDeletionPolicy();@@ -143,6 +143,12 @@ public class TestTransactionRollback extends LuceneTestCase {w.close();}++ @Override+ protected void tearDown() throws Exception {+ dir.close();+ super.tearDown();+ }// Rolls back to previous commit pointclass RollbackDeletionPolicy implements IndexDeletionPolicy {diff --git a/lucene/src/test/org/apache/lucene/index/TestTransactions.java b/lucene/src/test/org/apache/lucene/index/TestTransactions.javaindex cb7417d448c..646d6ac5005 100644--- a/lucene/src/test/org/apache/lucene/index/TestTransactions.java+++ b/lucene/src/test/org/apache/lucene/index/TestTransactions.java@@ -195,8 +195,8 @@ public class TestTransactions extends LuceneTestCase {public void testTransactions() throws Throwable {RANDOM = newRandom();- MockRAMDirectory dir1 = new MockRAMDirectory();- MockRAMDirectory dir2 = new MockRAMDirectory();+ MockRAMDirectory dir1 = newDirectory(RANDOM);+ MockRAMDirectory dir2 = newDirectory(RANDOM);dir1.setPreventDoubleWrite(false);dir2.setPreventDoubleWrite(false);dir1.failOn(new RandomFailure());@@ -225,5 +225,7 @@ public class TestTransactions extends LuceneTestCase {for(int i=0;i<numThread;i++)assertTrue(!threads[i].failed);+ dir1.close();+ dir2.close();}}diff --git a/lucene/src/test/org/apache/lucene/index/codecs/intblock/TestIntBlockCodec.java b/lucene/src/test/org/apache/lucene/index/codecs/intblock/TestIntBlockCodec.javaindex 8bc3ecd7efa..f8ea07047b8 100644--- a/lucene/src/test/org/apache/lucene/index/codecs/intblock/TestIntBlockCodec.java+++ b/lucene/src/test/org/apache/lucene/index/codecs/intblock/TestIntBlockCodec.java@@ -25,7 +25,7 @@ import org.apache.lucene.index.codecs.mockintblock.*;public class TestIntBlockCodec extends LuceneTestCase {public void testSimpleIntBlocks() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(newRandom());IntStreamFactory f = new MockFixedIntBlockCodec(128).getIntFactory();@@ -47,7 +47,7 @@ public class TestIntBlockCodec extends LuceneTestCase {}public void testEmptySimpleIntBlocks() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(newRandom());IntStreamFactory f = new MockFixedIntBlockCodec(128).getIntFactory();IntIndexOutput out = f.createOutput(dir, "test");diff --git a/lucene/src/test/org/apache/lucene/index/codecs/preflex/TestSurrogates.java b/lucene/src/test/org/apache/lucene/index/codecs/preflex/TestSurrogates.javaindex 6a8dbd1d3a5..d1ff288fdf9 100644--- a/lucene/src/test/org/apache/lucene/index/codecs/preflex/TestSurrogates.java+++ b/lucene/src/test/org/apache/lucene/index/codecs/preflex/TestSurrogates.java@@ -274,7 +274,7 @@ public class TestSurrogates extends LuceneTestCaseJ4 {public void testSurrogatesOrder() throws Exception {Random r = newRandom();- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(r);RandomIndexWriter w = new RandomIndexWriter(r,dir,newIndexWriterConfig(r, TEST_VERSION_CURRENT,@@ -338,5 +338,7 @@ public class TestSurrogates extends LuceneTestCaseJ4 {doTestSeekDoesNotExist(r, numField, fieldTerms, fieldTermsArray, reader);reader.close();+ w.close();+ dir.close();}}diff --git a/lucene/src/test/org/apache/lucene/queryParser/TestMultiFieldQueryParser.java b/lucene/src/test/org/apache/lucene/queryParser/TestMultiFieldQueryParser.javaindex ccc011d597f..39bc3c8717c 100644--- a/lucene/src/test/org/apache/lucene/queryParser/TestMultiFieldQueryParser.java+++ b/lucene/src/test/org/apache/lucene/queryParser/TestMultiFieldQueryParser.java@@ -21,6 +21,7 @@ import java.io.IOException;import java.io.Reader;import java.util.HashMap;import java.util.Map;+import java.util.Random;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.TokenStream;@@ -283,8 +284,9 @@ public class TestMultiFieldQueryParser extends LuceneTestCase {public void testStopWordSearching() throws Exception {Analyzer analyzer = new MockAnalyzer();- Directory ramDir = new MockRAMDirectory();- IndexWriter iw = new IndexWriter(ramDir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));+ Random random = newRandom();+ Directory ramDir = newDirectory(random);+ IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));Document doc = new Document();doc.add(new Field("body", "blah the footest blah", Field.Store.NO, Field.Index.ANALYZED));iw.addDocument(doc);@@ -298,6 +300,7 @@ public class TestMultiFieldQueryParser extends LuceneTestCase {ScoreDoc[] hits = is.search(q, null, 1000).scoreDocs;assertEquals(1, hits.length);is.close();+ ramDir.close();}/**diff --git a/lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java b/lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.javaindex e3d23fbc7ce..0fff9a256b1 100644--- a/lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java+++ b/lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java@@ -27,6 +27,7 @@ import java.util.Date;import java.util.GregorianCalendar;import java.util.HashSet;import java.util.Locale;+import java.util.Random;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.MockAnalyzer;@@ -569,9 +570,9 @@ public class TestQueryParser extends LocalizedTestCase {}public void testFarsiRangeCollating() throws Exception {-- MockRAMDirectory ramDir = new MockRAMDirectory();- IndexWriter iw = new IndexWriter(ramDir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));+ Random random = newRandom();+ MockRAMDirectory ramDir = newDirectory(random);+ IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));Document doc = new Document();doc.add(new Field("content","\u0633\u0627\u0628",Field.Store.YES, Field.Index.NOT_ANALYZED));@@ -610,6 +611,7 @@ public class TestQueryParser extends LocalizedTestCase {assertEquals("The index Term should be included.", 1, result.length);is.close();+ ramDir.close();}private String escapeDateString(String s) {@@ -978,8 +980,9 @@ public class TestQueryParser extends LocalizedTestCase {}public void testLocalDateFormat() throws IOException, ParseException {- MockRAMDirectory ramDir = new MockRAMDirectory();- IndexWriter iw = new IndexWriter(ramDir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));+ Random random = newRandom();+ MockRAMDirectory ramDir = newDirectory(random);+ IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)));addDateDoc("a", 2005, 12, 2, 10, 15, 33, iw);addDateDoc("b", 2005, 12, 4, 22, 15, 00, iw);iw.close();@@ -991,6 +994,7 @@ public class TestQueryParser extends LocalizedTestCase {assertHits(1, "{12/1/2005 TO 12/4/2005}", is);assertHits(0, "{12/3/2005 TO 12/4/2005}", is);is.close();+ ramDir.close();}public void testStarParsing() throws Exception {@@ -1124,9 +1128,10 @@ public class TestQueryParser extends LocalizedTestCase {// enableStopPositionIncr & QueryParser's enablePosIncr// "match"public void testPositionIncrements() throws Exception {- Directory dir = new MockRAMDirectory();+ Random random = newRandom();+ Directory dir = newDirectory(random);Analyzer a = new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true);- IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, a));+ IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, a));Document doc = new Document();doc.add(new Field("f", "the wizard of ozzy", Field.Store.NO, Field.Index.ANALYZED));w.addDocument(doc);diff --git a/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java b/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.javaindex 503d303c826..ff47de33e98 100644--- a/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java+++ b/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java@@ -34,7 +34,7 @@ public class BaseTestRangeFilter extends LuceneTestCase {public static final boolean F = false;public static final boolean T = true;- protected Random rand;+ protected Random rand = newRandom();/*** Collation interacts badly with hyphens -- collation produces different@@ -46,20 +46,23 @@ public class BaseTestRangeFilter extends LuceneTestCase {int maxR;int minR;boolean allowNegativeRandomInts;- MockRAMDirectory index = new MockRAMDirectory();+ MockRAMDirectory index;TestIndex(int minR, int maxR, boolean allowNegativeRandomInts) {this.minR = minR;this.maxR = maxR;this.allowNegativeRandomInts = allowNegativeRandomInts;+ try {+ index = newDirectory(rand);+ } catch (IOException e) { throw new RuntimeException(e); }}}IndexReader signedIndexReader;IndexReader unsignedIndexReader;- TestIndex signedIndexDir = new TestIndex(Integer.MAX_VALUE, Integer.MIN_VALUE, true);- TestIndex unsignedIndexDir = new TestIndex(Integer.MAX_VALUE, 0, false);+ TestIndex signedIndexDir;+ TestIndex unsignedIndexDir;int minId = 0;int maxId = 10000;@@ -88,7 +91,8 @@ public class BaseTestRangeFilter extends LuceneTestCase {protected void setUp() throws Exception {super.setUp();- rand = newRandom();+ signedIndexDir = new TestIndex(Integer.MAX_VALUE, Integer.MIN_VALUE, true);+ unsignedIndexDir = new TestIndex(Integer.MAX_VALUE, 0, false);signedIndexReader = build(rand, signedIndexDir);unsignedIndexReader = build(rand, unsignedIndexDir);}@@ -96,6 +100,8 @@ public class BaseTestRangeFilter extends LuceneTestCase {protected void tearDown() throws Exception {signedIndexReader.close();unsignedIndexReader.close();+ signedIndexDir.index.close();+ unsignedIndexDir.index.close();super.tearDown();}diff --git a/lucene/src/test/org/apache/lucene/search/TestAutomatonQuery.java b/lucene/src/test/org/apache/lucene/search/TestAutomatonQuery.javaindex 7df36f45dec..5bc66325f01 100644--- a/lucene/src/test/org/apache/lucene/search/TestAutomatonQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestAutomatonQuery.java@@ -43,7 +43,7 @@ public class TestAutomatonQuery extends LuceneTestCase {public void setUp() throws Exception {super.setUp();Random random = newRandom();- directory = new MockRAMDirectory();+ directory = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, directory);Document doc = new Document();Field titleField = new Field("title", "some title", Field.Store.NO,diff --git a/lucene/src/test/org/apache/lucene/search/TestAutomatonQueryUnicode.java b/lucene/src/test/org/apache/lucene/search/TestAutomatonQueryUnicode.javaindex ebb031d9b1d..538af9bf595 100644--- a/lucene/src/test/org/apache/lucene/search/TestAutomatonQueryUnicode.java+++ b/lucene/src/test/org/apache/lucene/search/TestAutomatonQueryUnicode.java@@ -46,7 +46,7 @@ public class TestAutomatonQueryUnicode extends LuceneTestCase {public void setUp() throws Exception {super.setUp();Random random = newRandom();- directory = new MockRAMDirectory();+ directory = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, directory);Document doc = new Document();Field titleField = new Field("title", "some title", Field.Store.NO,diff --git a/lucene/src/test/org/apache/lucene/search/TestBoolean2.java b/lucene/src/test/org/apache/lucene/search/TestBoolean2.javaindex 952473fb4de..608738d42c4 100644--- a/lucene/src/test/org/apache/lucene/search/TestBoolean2.java+++ b/lucene/src/test/org/apache/lucene/search/TestBoolean2.java@@ -46,6 +46,7 @@ public class TestBoolean2 extends LuceneTestCase {private static int NUM_EXTRA_DOCS = 6000;public static final String field = "field";+ private Directory directory;private Directory dir2;private int mulFactor;@@ -53,7 +54,7 @@ public class TestBoolean2 extends LuceneTestCase {protected void setUp() throws Exception {super.setUp();rnd = newRandom();- MockRAMDirectory directory = new MockRAMDirectory();+ directory = newDirectory(rnd);RandomIndexWriter writer= new RandomIndexWriter(rnd, directory);for (int i = 0; i < docFields.length; i++) {Document doc = new Document();@@ -96,8 +97,10 @@ public class TestBoolean2 extends LuceneTestCase {@Overrideprotected void tearDown() throws Exception {+ searcher.close();reader.close();dir2.close();+ directory.close();super.tearDown();}diff --git a/lucene/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java b/lucene/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.javaindex c4b948e55b5..121fbeb65da 100644--- a/lucene/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java+++ b/lucene/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java@@ -55,7 +55,7 @@ public class TestBooleanMinShouldMatch extends LuceneTestCase {"X 4 5 6"};- index = new MockRAMDirectory();+ index = newDirectory(rnd);RandomIndexWriter w = new RandomIndexWriter(rnd, index);for (int i = 0; i < data.length; i++) {diff --git a/lucene/src/test/org/apache/lucene/search/TestBooleanOr.java b/lucene/src/test/org/apache/lucene/search/TestBooleanOr.javaindex f1dfaff604d..2c37195cf2c 100644--- a/lucene/src/test/org/apache/lucene/search/TestBooleanOr.java+++ b/lucene/src/test/org/apache/lucene/search/TestBooleanOr.java@@ -137,9 +137,10 @@ public class TestBooleanOr extends LuceneTestCase {super.setUp();//- dir = new MockRAMDirectory();-Random random = newRandom();+ dir = newDirectory(random);++//RandomIndexWriter writer = new RandomIndexWriter(random, dir);diff --git a/lucene/src/test/org/apache/lucene/search/TestBooleanPrefixQuery.java b/lucene/src/test/org/apache/lucene/search/TestBooleanPrefixQuery.javaindex f0647fa0fd6..2e9da31a3d6 100644--- a/lucene/src/test/org/apache/lucene/search/TestBooleanPrefixQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestBooleanPrefixQuery.java@@ -17,6 +17,8 @@ package org.apache.lucene.search;* limitations under the License.*/+import java.util.Random;+import org.apache.lucene.util.LuceneTestCase;import junit.framework.Test;import junit.framework.TestSuite;@@ -65,7 +67,8 @@ public class TestBooleanPrefixQuery extends LuceneTestCase {}public void testMethod() throws Exception {- MockRAMDirectory directory = new MockRAMDirectory();+ Random random = newRandom();+ MockRAMDirectory directory = newDirectory(random);String[] categories = new String[]{"food","foodanddrink",@@ -75,7 +78,7 @@ public class TestBooleanPrefixQuery extends LuceneTestCase {Query rw1 = null;Query rw2 = null;IndexReader reader = null;- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);for (int i = 0; i < categories.length; i++) {Document doc = new Document();doc.add(new Field("category", categories[i], Field.Store.YES, Field.Index.NOT_ANALYZED));diff --git a/lucene/src/test/org/apache/lucene/search/TestBooleanQuery.java b/lucene/src/test/org/apache/lucene/search/TestBooleanQuery.javaindex 9bac35cd374..45ad8398c04 100644--- a/lucene/src/test/org/apache/lucene/search/TestBooleanQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestBooleanQuery.java@@ -17,6 +17,8 @@ package org.apache.lucene.search;* limitations under the License.*/+import java.util.Random;+import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.RandomIndexWriter;import org.apache.lucene.document.Document;@@ -59,8 +61,9 @@ public class TestBooleanQuery extends LuceneTestCase {// LUCENE-1630public void testNullOrSubScorer() throws Throwable {- Directory dir = new MockRAMDirectory();- RandomIndexWriter w = new RandomIndexWriter(newRandom(), dir);+ Random random = newRandom();+ Directory dir = newDirectory(random);+ RandomIndexWriter w = new RandomIndexWriter(random, dir);Document doc = new Document();doc.add(new Field("field", "a b c d", Field.Store.NO, Field.Index.ANALYZED));w.addDocument(doc);diff --git a/lucene/src/test/org/apache/lucene/search/TestBooleanScorer.java b/lucene/src/test/org/apache/lucene/search/TestBooleanScorer.javaindex d6a3138197d..8472d04749f 100644--- a/lucene/src/test/org/apache/lucene/search/TestBooleanScorer.java+++ b/lucene/src/test/org/apache/lucene/search/TestBooleanScorer.java@@ -19,6 +19,7 @@ package org.apache.lucene.search;import java.io.IOException;import java.util.Arrays;+import java.util.Random;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;@@ -39,11 +40,12 @@ public class TestBooleanScorer extends LuceneTestCaseprivate static final String FIELD = "category";public void testMethod() throws Exception {- MockRAMDirectory directory = new MockRAMDirectory();+ Random random = newRandom();+ MockRAMDirectory directory = newDirectory(random);String[] values = new String[] { "1", "2", "3", "4" };- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);for (int i = 0; i < values.length; i++) {Document doc = new Document();doc.add(new Field(FIELD, values[i], Field.Store.YES, Field.Index.NOT_ANALYZED));diff --git a/lucene/src/test/org/apache/lucene/search/TestCachingSpanFilter.java b/lucene/src/test/org/apache/lucene/search/TestCachingSpanFilter.javaindex 97fcc13962c..df909f8900a 100644--- a/lucene/src/test/org/apache/lucene/search/TestCachingSpanFilter.java+++ b/lucene/src/test/org/apache/lucene/search/TestCachingSpanFilter.java@@ -18,25 +18,28 @@ package org.apache.lucene.search;*/import java.io.IOException;+import java.util.Random;-import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.index.IndexReader;-import org.apache.lucene.index.IndexWriter;-import org.apache.lucene.index.IndexWriterConfig;+import org.apache.lucene.index.RandomIndexWriter;import org.apache.lucene.index.Term;import org.apache.lucene.search.spans.SpanTermQuery;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;public class TestCachingSpanFilter extends LuceneTestCase {public void testEnforceDeletions() throws Exception {- Directory dir = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));- IndexReader reader = writer.getReader();+ Random random = newRandom();+ Directory dir = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, dir);+ // NOTE: cannot use writer.getReader because RIW (on+ // flipping a coin) may give us a newly opened reader,+ // but we use .reopen on this reader below and expect to+ // (must) get an NRT reader:+ IndexReader reader = writer.w.getReader();IndexSearcher searcher = new IndexSearcher(reader);// add a doc, refresh the reader, and check that its there@@ -110,6 +113,9 @@ public class TestCachingSpanFilter extends LuceneTestCase {docs = searcher.search(constantScore, 1);assertEquals("[just filter] Should *not* find a hit...", 0, docs.totalHits);+ writer.close();+ reader.close();+ dir.close();}private static IndexReader refreshReader(IndexReader reader) throws IOException {diff --git a/lucene/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java b/lucene/src/test/org/apache/lucene/search/TestCachingWrapperFilter.javaindex fda343b3fbb..0c5bbbdcf21 100644--- a/lucene/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java+++ b/lucene/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java@@ -42,7 +42,7 @@ public class TestCachingWrapperFilter extends LuceneTestCase {}public void testCachingWorks() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, dir);writer.close();@@ -64,10 +64,11 @@ public class TestCachingWrapperFilter extends LuceneTestCase {assertFalse("second time", filter.wasCalled());reader.close();+ dir.close();}public void testNullDocIdSet() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, dir);writer.close();@@ -85,10 +86,11 @@ public class TestCachingWrapperFilter extends LuceneTestCase {assertSame(DocIdSet.EMPTY_DOCIDSET, cacher.getDocIdSet(reader));reader.close();+ dir.close();}public void testNullDocIdSetIterator() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, dir);writer.close();@@ -111,6 +113,7 @@ public class TestCachingWrapperFilter extends LuceneTestCase {assertSame(DocIdSet.EMPTY_DOCIDSET, cacher.getDocIdSet(reader));reader.close();+ dir.close();}private static void assertDocIdSetCacheable(IndexReader reader, Filter filter, boolean shouldCacheable) throws IOException {@@ -128,7 +131,7 @@ public class TestCachingWrapperFilter extends LuceneTestCase {}public void testIsCacheAble() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, dir);writer.addDocument(new Document());writer.close();@@ -151,10 +154,11 @@ public class TestCachingWrapperFilter extends LuceneTestCase {}, true);reader.close();+ dir.close();}public void testEnforceDeletions() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, dir);// NOTE: cannot use writer.getReader because RIW (on@@ -266,6 +270,9 @@ public class TestCachingWrapperFilter extends LuceneTestCase {// doesn't count as a missassertEquals(missCount, filter.missCount);+ reader.close();+ writer.close();+ dir.close();}private static IndexReader refreshReader(IndexReader reader) throws IOException {diff --git a/lucene/src/test/org/apache/lucene/search/TestCustomSearcherSort.java b/lucene/src/test/org/apache/lucene/search/TestCustomSearcherSort.javaindex 627c971a2bd..22b9bac52bf 100644--- a/lucene/src/test/org/apache/lucene/search/TestCustomSearcherSort.java+++ b/lucene/src/test/org/apache/lucene/search/TestCustomSearcherSort.java@@ -31,7 +31,6 @@ import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.RandomIndexWriter;import org.apache.lucene.index.Term;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;/** Unit test for sorting code. */@@ -50,7 +49,7 @@ public class TestCustomSearcherSort extends LuceneTestCase implements Serializabprotected void setUp() throws Exception {super.setUp();Random rand = newRandom();- index = new MockRAMDirectory();+ index = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, index);RandomGen random = new RandomGen(rand);for (int i = 0; i < INDEX_SIZE; ++i) { // don't decrease; if to low thediff --git a/lucene/src/test/org/apache/lucene/search/TestDateFilter.java b/lucene/src/test/org/apache/lucene/search/TestDateFilter.javaindex 16583a64966..84d6fd7a391 100644--- a/lucene/src/test/org/apache/lucene/search/TestDateFilter.java+++ b/lucene/src/test/org/apache/lucene/search/TestDateFilter.java@@ -27,6 +27,7 @@ import org.apache.lucene.index.Term;import org.apache.lucene.store.MockRAMDirectory;import java.io.IOException;+import java.util.Random;/*** DateFilter JUnit tests.@@ -44,8 +45,9 @@ public class TestDateFilter extends LuceneTestCase {*/public void testBefore() throws IOException {// create an index- MockRAMDirectory indexStore = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), indexStore);+ Random random = newRandom();+ MockRAMDirectory indexStore = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, indexStore);long now = System.currentTimeMillis();@@ -110,8 +112,9 @@ public class TestDateFilter extends LuceneTestCase {*/public void testAfter() throws IOException {// create an index- MockRAMDirectory indexStore = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), indexStore);+ Random random = newRandom();+ MockRAMDirectory indexStore = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, indexStore);long now = System.currentTimeMillis();diff --git a/lucene/src/test/org/apache/lucene/search/TestDateSort.java b/lucene/src/test/org/apache/lucene/search/TestDateSort.javaindex 7187658b9c2..8571042ac45 100644--- a/lucene/src/test/org/apache/lucene/search/TestDateSort.java+++ b/lucene/src/test/org/apache/lucene/search/TestDateSort.java@@ -18,6 +18,7 @@ package org.apache.lucene.search;*/import java.util.Arrays;+import java.util.Random;import org.apache.lucene.util.LuceneTestCase;@@ -51,8 +52,9 @@ public class TestDateSort extends LuceneTestCase {protected void setUp() throws Exception {super.setUp();// Create an index writer.- directory = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ Random random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);// oldest doc:// Add the first document. text = "Document 1" dateTime = Oct 10 03:25:22 EDT 2007diff --git a/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java b/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.javaindex 7c2ce1504e4..c669cbf5c47 100644--- a/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java@@ -80,8 +80,8 @@ public class TestDisjunctionMaxQuery extends LuceneTestCase {protected void setUp() throws Exception {super.setUp();- index = new MockRAMDirectory();Random random = newRandom();+ index = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, index,newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setSimilarity(sim));diff --git a/lucene/src/test/org/apache/lucene/search/TestDocBoost.java b/lucene/src/test/org/apache/lucene/search/TestDocBoost.javaindex ca0ffce6b1c..4d1492c4e38 100644--- a/lucene/src/test/org/apache/lucene/search/TestDocBoost.java+++ b/lucene/src/test/org/apache/lucene/search/TestDocBoost.java@@ -18,6 +18,7 @@ package org.apache.lucene.search;*/import java.io.IOException;+import java.util.Random;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.document.*;@@ -37,8 +38,9 @@ public class TestDocBoost extends LuceneTestCase {}public void testDocBoost() throws Exception {- MockRAMDirectory store = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), store);+ Random random = newRandom();+ MockRAMDirectory store = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, store);Fieldable f1 = new Field("field", "word", Field.Store.YES, Field.Index.ANALYZED);Fieldable f2 = new Field("field", "word", Field.Store.YES, Field.Index.ANALYZED);diff --git a/lucene/src/test/org/apache/lucene/search/TestDocIdSet.java b/lucene/src/test/org/apache/lucene/search/TestDocIdSet.javaindex 11db91884c1..0a7e6571c39 100644--- a/lucene/src/test/org/apache/lucene/search/TestDocIdSet.java+++ b/lucene/src/test/org/apache/lucene/search/TestDocIdSet.java@@ -21,6 +21,7 @@ import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.Iterator;+import java.util.Random;import junit.framework.Assert;@@ -101,8 +102,9 @@ public class TestDocIdSet extends LuceneTestCase {public void testNullDocIdSet() throws Exception {// Tests that if a Filter produces a null DocIdSet, which is given to// IndexSearcher, everything works fine. This came up in LUCENE-1754.- Directory dir = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), dir);+ Random random = newRandom();+ Directory dir = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, dir);Document doc = new Document();doc.add(new Field("c", "val", Store.NO, Index.NOT_ANALYZED_NO_NORMS));writer.addDocument(doc);diff --git a/lucene/src/test/org/apache/lucene/search/TestElevationComparator.java b/lucene/src/test/org/apache/lucene/search/TestElevationComparator.javaindex dc3eba31596..48671cd80c1 100644--- a/lucene/src/test/org/apache/lucene/search/TestElevationComparator.java+++ b/lucene/src/test/org/apache/lucene/search/TestElevationComparator.java@@ -28,6 +28,7 @@ import org.apache.lucene.util.BytesRef;import java.io.IOException;import java.util.HashMap;import java.util.Map;+import java.util.Random;public class TestElevationComparator extends LuceneTestCase {@@ -35,8 +36,9 @@ public class TestElevationComparator extends LuceneTestCase {//@Testpublic void testSorting() throws Throwable {- Directory directory = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));+ Random random = newRandom();+ Directory directory = newDirectory(random);+ IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(2));((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(1000);writer.addDocument(adoc(new String[] {"id", "a", "title", "ipod", "str_s", "a"}));writer.addDocument(adoc(new String[] {"id", "b", "title", "ipod ipod", "str_s", "b"}));diff --git a/lucene/src/test/org/apache/lucene/search/TestExplanations.java b/lucene/src/test/org/apache/lucene/search/TestExplanations.javaindex af4d6124bcb..5abb081b25a 100644--- a/lucene/src/test/org/apache/lucene/search/TestExplanations.java+++ b/lucene/src/test/org/apache/lucene/search/TestExplanations.java@@ -17,6 +17,8 @@ package org.apache.lucene.search;* limitations under the License.*/+import java.util.Random;+import org.apache.lucene.queryParser.QueryParser;import org.apache.lucene.queryParser.ParseException;import org.apache.lucene.analysis.MockAnalyzer;@@ -51,6 +53,7 @@ public class TestExplanations extends LuceneTestCase {protected IndexSearcher searcher;protected IndexReader reader;protected Directory directory;+ protected Random random;public static final String KEY = "KEY";public static final String FIELD = "field";@@ -68,8 +71,9 @@ public class TestExplanations extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();- RandomIndexWriter writer= new RandomIndexWriter(newRandom(), directory);+ random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter writer= new RandomIndexWriter(random, directory);for (int i = 0; i < docFields.length; i++) {Document doc = new Document();doc.add(new Field(KEY, ""+i, Field.Store.NO, Field.Index.NOT_ANALYZED));diff --git a/lucene/src/test/org/apache/lucene/search/TestFieldCache.java b/lucene/src/test/org/apache/lucene/search/TestFieldCache.javaindex 7f0d4bc3257..5a010d274e3 100644--- a/lucene/src/test/org/apache/lucene/search/TestFieldCache.java+++ b/lucene/src/test/org/apache/lucene/search/TestFieldCache.java@@ -25,7 +25,6 @@ import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.RandomIndexWriter;import org.apache.lucene.index.TermsEnum;import org.apache.lucene.store.MockRAMDirectory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.store.Directory;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util._TestUtil;@@ -39,7 +38,9 @@ public class TestFieldCache extends LuceneTestCase {protected IndexReader reader;private static final int NUM_DOCS = 1000 * RANDOM_MULTIPLIER;private String[] unicodeStrings;-+ private Random random;+ private Directory directory;+public TestFieldCache(String s) {super(s);}@@ -47,9 +48,9 @@ public class TestFieldCache extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- Random r = newRandom();- MockRAMDirectory directory = new MockRAMDirectory();- RandomIndexWriter writer= new RandomIndexWriter(r, directory);+ random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter writer= new RandomIndexWriter(random, directory);long theLong = Long.MAX_VALUE;double theDouble = Double.MAX_VALUE;byte theByte = Byte.MAX_VALUE;@@ -67,18 +68,18 @@ public class TestFieldCache extends LuceneTestCase {doc.add(new Field("theFloat", String.valueOf(theFloat--), Field.Store.NO, Field.Index.NOT_ANALYZED));// sometimes skip the field:- if (r.nextInt(40) != 17) {+ if (random.nextInt(40) != 17) {String s = null;- if (i > 0 && r.nextInt(3) == 1) {+ if (i > 0 && random.nextInt(3) == 1) {// reuse past string -- try to find one that's not nullfor(int iter=0;iter<10 && s==null;iter++) {- s = unicodeStrings[r.nextInt(i)];+ s = unicodeStrings[random.nextInt(i)];}if (s == null) {- s = _TestUtil.randomUnicodeString(r, 250);+ s = _TestUtil.randomUnicodeString(random, 250);}} else {- s = _TestUtil.randomUnicodeString(r, 250);+ s = _TestUtil.randomUnicodeString(random, 250);}unicodeStrings[i] = s;doc.add(new Field("theRandomUnicodeString", unicodeStrings[i], Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));@@ -89,6 +90,13 @@ public class TestFieldCache extends LuceneTestCase {writer.close();}+ @Override+ protected void tearDown() throws Exception {+ reader.close();+ directory.close();+ super.tearDown();+ }+public void testInfoStream() throws Exception {try {FieldCache cache = FieldCache.DEFAULT;@@ -202,8 +210,8 @@ public class TestFieldCache extends LuceneTestCase {}public void testEmptyIndex() throws Exception {- Directory dir = new MockRAMDirectory();- IndexWriter writer= new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(500));+ Directory dir = newDirectory(random);+ IndexWriter writer= new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(500));IndexReader r = writer.getReader();FieldCache.DocTerms terms = FieldCache.DEFAULT.getTerms(r, "foobar");FieldCache.DocTermsIndex termsIndex = FieldCache.DEFAULT.getTermsIndex(r, "foobar");diff --git a/lucene/src/test/org/apache/lucene/search/TestFieldCacheRangeFilter.java b/lucene/src/test/org/apache/lucene/search/TestFieldCacheRangeFilter.javaindex df01a298fdb..067fec1ca7e 100644--- a/lucene/src/test/org/apache/lucene/search/TestFieldCacheRangeFilter.java+++ b/lucene/src/test/org/apache/lucene/search/TestFieldCacheRangeFilter.java@@ -21,7 +21,6 @@ import java.io.IOException;import org.apache.lucene.index.IndexReader;-import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.Term;import org.apache.lucene.index.IndexWriter;import org.apache.lucene.analysis.MockAnalyzer;@@ -516,8 +515,8 @@ public class TestFieldCacheRangeFilter extends BaseTestRangeFilter {// test using a sparse index (with deleted docs).public void testSparseIndex() throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ MockRAMDirectory dir = newDirectory(rand);+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new MockAnalyzer()));for (int d = -20; d <= 20; d++) {Document doc = new Document();@@ -551,6 +550,8 @@ public class TestFieldCacheRangeFilter extends BaseTestRangeFilter {result = search.search(q,FieldCacheRangeFilter.newByteRange("id",Byte.valueOf((byte) -20),Byte.valueOf((byte) -10),T,T), 100).scoreDocs;assertEquals("find all", 11, result.length);+ reader.close();+ dir.close();}}diff --git a/lucene/src/test/org/apache/lucene/search/TestFieldCacheTermsFilter.java b/lucene/src/test/org/apache/lucene/search/TestFieldCacheTermsFilter.javaindex 35167ea48b2..f071d1d25e8 100644--- a/lucene/src/test/org/apache/lucene/search/TestFieldCacheTermsFilter.java+++ b/lucene/src/test/org/apache/lucene/search/TestFieldCacheTermsFilter.java@@ -27,6 +27,7 @@ import org.apache.lucene.store.MockRAMDirectory;import java.util.ArrayList;import java.util.List;+import java.util.Random;/*** A basic unit test for FieldCacheTermsFilter@@ -36,8 +37,9 @@ import java.util.List;public class TestFieldCacheTermsFilter extends LuceneTestCase {public void testMissingTerms() throws Exception {String fieldName = "field1";- MockRAMDirectory rd = new MockRAMDirectory();- RandomIndexWriter w = new RandomIndexWriter(newRandom(), rd);+ Random random = newRandom();+ MockRAMDirectory rd = newDirectory(random);+ RandomIndexWriter w = new RandomIndexWriter(random, rd);for (int i = 0; i < 100; i++) {Document doc = new Document();int term = i * 10; //terms are units of 10;diff --git a/lucene/src/test/org/apache/lucene/search/TestFilteredQuery.java b/lucene/src/test/org/apache/lucene/search/TestFilteredQuery.javaindex 8328b192330..9430d510c06 100644--- a/lucene/src/test/org/apache/lucene/search/TestFilteredQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestFilteredQuery.java@@ -27,6 +27,7 @@ import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.DocIdBitSet;import java.util.BitSet;+import java.util.Random;/*** FilteredQuery JUnit tests.@@ -47,8 +48,9 @@ public class TestFilteredQuery extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter (newRandom(), directory);+ Random random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter (random, directory);Document doc = new Document();doc.add (new Field("field", "one two three four five", Field.Store.YES, Field.Index.ANALYZED));diff --git a/lucene/src/test/org/apache/lucene/search/TestFilteredSearch.java b/lucene/src/test/org/apache/lucene/search/TestFilteredSearch.javaindex 3770746aca7..7ac1cf6e45d 100644--- a/lucene/src/test/org/apache/lucene/search/TestFilteredSearch.java+++ b/lucene/src/test/org/apache/lucene/search/TestFilteredSearch.java@@ -18,6 +18,7 @@package org.apache.lucene.search;import java.io.IOException;+import java.util.Random;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.analysis.MockAnalyzer;@@ -26,7 +27,6 @@ import org.apache.lucene.document.Field;import org.apache.lucene.index.CorruptIndexException;import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.IndexWriter;-import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.Term;import org.apache.lucene.index.IndexWriterConfig.OpenMode;import org.apache.lucene.store.Directory;@@ -48,18 +48,22 @@ public class TestFilteredSearch extends LuceneTestCase {public void testFilteredSearch() throws CorruptIndexException, LockObtainFailedException, IOException {boolean enforceSingleSegment = true;- MockRAMDirectory directory = new MockRAMDirectory();+ Random random = newRandom();+ MockRAMDirectory directory = newDirectory(random);int[] filterBits = {1, 36};SimpleDocIdSetFilter filter = new SimpleDocIdSetFilter(filterBits);- IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));searchFiltered(writer, directory, filter, enforceSingleSegment);// run the test on more than one segmentenforceSingleSegment = false;// reset - it is statefulfilter.reset();- writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(10));+ writer.close();+ writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE).setMaxBufferedDocs(10));// we index 60 docs - this will create 6 segmentssearchFiltered(writer, directory, filter, enforceSingleSegment);+ writer.close();+ directory.close();}public void searchFiltered(IndexWriter writer, Directory directory, SimpleDocIdSetFilter filter, boolean optimize) {@@ -81,7 +85,7 @@ public class TestFilteredSearch extends LuceneTestCase {filter.setTopReader(indexSearcher.getIndexReader());ScoreDoc[] hits = indexSearcher.search(booleanQuery, filter, 1000).scoreDocs;assertEquals("Number of matched documents", 1, hits.length);-+ indexSearcher.close();}catch (IOException e) {fail(e.getMessage());diff --git a/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.java b/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.javaindex eb3df66f21a..093f9a5e96c 100644--- a/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.java@@ -19,6 +19,7 @@ package org.apache.lucene.search;import java.util.List;import java.util.Arrays;+import java.util.Random;import java.io.IOException;import org.apache.lucene.analysis.MockAnalyzer;@@ -30,7 +31,6 @@ import org.apache.lucene.index.Term;import org.apache.lucene.queryParser.QueryParser;import org.apache.lucene.store.Directory;import org.apache.lucene.store.MockRAMDirectory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;/**@@ -40,8 +40,9 @@ import org.apache.lucene.util.LuceneTestCase;public class TestFuzzyQuery extends LuceneTestCase {public void testFuzziness() throws Exception {- MockRAMDirectory directory = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ Random random = newRandom();+ MockRAMDirectory directory = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);addDoc("aaaaa", writer);addDoc("aaaab", writer);addDoc("aaabb", writer);@@ -193,8 +194,9 @@ public class TestFuzzyQuery extends LuceneTestCase {}public void testFuzzinessLong() throws Exception {- MockRAMDirectory directory = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ Random random = newRandom();+ MockRAMDirectory directory = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);addDoc("aaaaaaa", writer);addDoc("segment", writer);@@ -283,8 +285,9 @@ public class TestFuzzyQuery extends LuceneTestCase {}public void testTokenLengthOpt() throws IOException {- MockRAMDirectory directory = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ Random random = newRandom();+ MockRAMDirectory directory = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);addDoc("12345678911", writer);addDoc("segment", writer);@@ -320,8 +323,9 @@ public class TestFuzzyQuery extends LuceneTestCase {/** Test the TopTermsBoostOnlyBooleanQueryRewrite rewrite method. */public void testBoostOnlyRewrite() throws Exception {- MockRAMDirectory directory = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ Random random = newRandom();+ MockRAMDirectory directory = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);addDoc("Lucene", writer);addDoc("Lucene", writer);addDoc("Lucenne", writer);@@ -346,9 +350,9 @@ public class TestFuzzyQuery extends LuceneTestCase {public void testGiga() throws Exception {MockAnalyzer analyzer = new MockAnalyzer();-- Directory index = new MockRAMDirectory();- RandomIndexWriter w = new RandomIndexWriter(newRandom(), index);+ Random random = newRandom();+ Directory index = newDirectory(random);+ RandomIndexWriter w = new RandomIndexWriter(random, index);addDoc("Lucene in Action", w);addDoc("Lucene for Dummies", w);diff --git a/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery2.java b/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery2.javaindex cd46b7b9e04..22cc155a122 100644--- a/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery2.java+++ b/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery2.java@@ -86,7 +86,7 @@ public class TestFuzzyQuery2 extends LuceneTestCase {int bits = Integer.parseInt(reader.readLine());int terms = (int) Math.pow(2, bits);- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, dir, new MockAnalyzer(MockTokenizer.KEYWORD, false));Document doc = new Document();diff --git a/lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java b/lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.javaindex 80024c6adb2..fa358699339 100644--- a/lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java@@ -17,6 +17,7 @@package org.apache.lucene.search;import java.io.IOException;+import java.util.Random;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.MockAnalyzer;@@ -39,9 +40,9 @@ public class TestMatchAllDocsQuery extends LuceneTestCase {private Analyzer analyzer = new MockAnalyzer();public void testQuery() throws Exception {-- MockRAMDirectory dir = new MockRAMDirectory();- IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(+ Random random = newRandom();+ MockRAMDirectory dir = newDirectory(random);+ IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, analyzer).setMaxBufferedDocs(2));addDoc("one", iw, 1f);addDoc("two", iw, 20f);diff --git a/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java b/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.javaindex 5d5adf958a6..5314da8f166 100644--- a/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java@@ -31,6 +31,7 @@ import org.apache.lucene.util.LuceneTestCase;import java.io.IOException;import java.util.LinkedList;+import java.util.Random;/*** This class tests the MultiPhraseQuery class.@@ -43,8 +44,9 @@ public class TestMultiPhraseQuery extends LuceneTestCase {}public void testPhrasePrefix() throws IOException {- MockRAMDirectory indexStore = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), indexStore);+ Random random = newRandom();+ MockRAMDirectory indexStore = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, indexStore);add("blueberry pie", writer);add("blueberry strudel", writer);add("blueberry pizza", writer);@@ -136,8 +138,9 @@ public class TestMultiPhraseQuery extends LuceneTestCase {// LUCENE-2580public void testTall() throws IOException {- MockRAMDirectory indexStore = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), indexStore);+ Random random = newRandom();+ MockRAMDirectory indexStore = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, indexStore);add("blueberry chocolate pie", writer);add("blueberry chocolate tart", writer);IndexReader r = writer.getReader();@@ -165,9 +168,9 @@ public class TestMultiPhraseQuery extends LuceneTestCase {// In order to cause the bug, the outer query must have more than one term// and all terms required.// The contained PhraseMultiQuery must contain exactly one term array.-- MockRAMDirectory indexStore = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), indexStore);+ Random random = newRandom();+ MockRAMDirectory indexStore = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, indexStore);add("blueberry pie", writer);add("blueberry chewing gum", writer);add("blue raspberry pie", writer);@@ -198,8 +201,9 @@ public class TestMultiPhraseQuery extends LuceneTestCase {}public void testPhrasePrefixWithBooleanQuery() throws IOException {- MockRAMDirectory indexStore = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), indexStore);+ Random random = newRandom();+ MockRAMDirectory indexStore = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, indexStore);add("This is a test", "object", writer);add("a note", "note", writer);@@ -226,8 +230,9 @@ public class TestMultiPhraseQuery extends LuceneTestCase {}public void testNoDocs() throws Exception {- MockRAMDirectory indexStore = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), indexStore);+ Random random = newRandom();+ MockRAMDirectory indexStore = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, indexStore);add("a note", "note", writer);IndexReader reader = writer.getReader();diff --git a/lucene/src/test/org/apache/lucene/search/TestMultiSearcher.java b/lucene/src/test/org/apache/lucene/search/TestMultiSearcher.javaindex 584f67df8bd..d3770e24cb9 100644--- a/lucene/src/test/org/apache/lucene/search/TestMultiSearcher.java+++ b/lucene/src/test/org/apache/lucene/search/TestMultiSearcher.java@@ -30,11 +30,11 @@ import org.apache.lucene.index.IndexWriterConfig.OpenMode;import org.apache.lucene.queryParser.QueryParser;import org.apache.lucene.store.Directory;import org.apache.lucene.store.MockRAMDirectory;-import org.apache.lucene.store.MockRAMDirectory;import java.io.IOException;import java.util.Collections;import java.util.HashSet;import java.util.Map;+import java.util.Random;import java.util.Set;/**@@ -42,6 +42,14 @@ import java.util.Set;*/public class TestMultiSearcher extends LuceneTestCase{+ private Random random;++ @Override+ public void setUp() throws Exception {+ super.setUp();+ random = newRandom();+ }+public TestMultiSearcher(String name){super(name);@@ -57,8 +65,8 @@ public class TestMultiSearcher extends LuceneTestCasepublic void testEmptyIndex() throws Exception {// creating two directories for indices- Directory indexStoreA = new MockRAMDirectory();- Directory indexStoreB = new MockRAMDirectory();+ Directory indexStoreA = newDirectory(random);+ Directory indexStoreB = newDirectory(random);// creating a document to storeDocument lDoc = new Document();@@ -81,9 +89,9 @@ public class TestMultiSearcher extends LuceneTestCaselDoc3.add(new Field("handle", "1", Field.Store.YES, Field.Index.NOT_ANALYZED));// creating an index writer for the first index- IndexWriter writerA = new IndexWriter(indexStoreA, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ IndexWriter writerA = new IndexWriter(indexStoreA, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));// creating an index writer for the second index, but writing nothing- IndexWriter writerB = new IndexWriter(indexStoreB, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ IndexWriter writerB = new IndexWriter(indexStoreB, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));//--------------------------------------------------------------------// scenario 1@@ -127,7 +135,7 @@ public class TestMultiSearcher extends LuceneTestCase//--------------------------------------------------------------------// adding one document to the empty index- writerB = new IndexWriter(indexStoreB, new IndexWriterConfig(+ writerB = new IndexWriter(indexStoreB, newIndexWriterConfig(random,TEST_VERSION_CURRENT,new MockAnalyzer()).setOpenMode(OpenMode.APPEND));@@ -216,11 +224,11 @@ public class TestMultiSearcher extends LuceneTestCasereturn document;}- private static void initIndex(Directory directory, int nDocs, boolean create, String contents2) throws IOException {+ private static void initIndex(Random random, Directory directory, int nDocs, boolean create, String contents2) throws IOException {IndexWriter indexWriter=null;try {- indexWriter = new IndexWriter(directory, new IndexWriterConfig(+ indexWriter = new IndexWriter(directory, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(create ? OpenMode.CREATE : OpenMode.APPEND));@@ -238,13 +246,13 @@ public class TestMultiSearcher extends LuceneTestCaseMockRAMDirectory ramDirectory1, ramDirectory2;IndexSearcher indexSearcher1, indexSearcher2;- ramDirectory1 = new MockRAMDirectory();- ramDirectory2 = new MockRAMDirectory();+ ramDirectory1 = newDirectory(random);+ ramDirectory2 = newDirectory(random);Query query = new TermQuery(new Term("contents", "doc0"));// Now put the documents in a different index- initIndex(ramDirectory1, 10, true, null); // documents with a single token "doc0", "doc1", etc...- initIndex(ramDirectory2, 10, true, "x"); // documents with two tokens "doc0" and "x", "doc1" and x, etc...+ initIndex(random, ramDirectory1, 10, true, null); // documents with a single token "doc0", "doc1", etc...+ initIndex(random, ramDirectory2, 10, true, "x"); // documents with two tokens "doc0" and "x", "doc1" and x, etc...indexSearcher1 = new IndexSearcher(ramDirectory1, true);indexSearcher2 = new IndexSearcher(ramDirectory2, true);@@ -277,6 +285,10 @@ public class TestMultiSearcher extends LuceneTestCaseassertTrue("value is null and it shouldn't be", value != null);value = document.get("other");assertTrue("value is not null and it should be", value == null);+ indexSearcher1.close();+ indexSearcher2.close();+ ramDirectory1.close();+ ramDirectory2.close();}/* uncomment this when the highest score is always normalized to 1.0, even when it was < 1.0@@ -296,11 +308,11 @@ public class TestMultiSearcher extends LuceneTestCaseIndexSearcher indexSearcher1;ScoreDoc[] hits;- ramDirectory1=new MockRAMDirectory();+ ramDirectory1=newDirectory(random);// First put the documents in the same index- initIndex(ramDirectory1, nDocs, true, null); // documents with a single token "doc0", "doc1", etc...- initIndex(ramDirectory1, nDocs, false, "x"); // documents with two tokens "doc0" and "x", "doc1" and x, etc...+ initIndex(random, ramDirectory1, nDocs, true, null); // documents with a single token "doc0", "doc1", etc...+ initIndex(random, ramDirectory1, nDocs, false, "x"); // documents with two tokens "doc0" and "x", "doc1" and x, etc...indexSearcher1=new IndexSearcher(ramDirectory1, true);indexSearcher1.setDefaultFieldSortScoring(true, true);@@ -323,12 +335,12 @@ public class TestMultiSearcher extends LuceneTestCaseMockRAMDirectory ramDirectory2;IndexSearcher indexSearcher2;- ramDirectory1=new MockRAMDirectory();- ramDirectory2=new MockRAMDirectory();+ ramDirectory1=newDirectory(random);+ ramDirectory2=newDirectory(random);// Now put the documents in a different index- initIndex(ramDirectory1, nDocs, true, null); // documents with a single token "doc0", "doc1", etc...- initIndex(ramDirectory2, nDocs, true, "x"); // documents with two tokens "doc0" and "x", "doc1" and x, etc...+ initIndex(random, ramDirectory1, nDocs, true, null); // documents with a single token "doc0", "doc1", etc...+ initIndex(random, ramDirectory2, nDocs, true, "x"); // documents with two tokens "doc0" and "x", "doc1" and x, etc...indexSearcher1=new IndexSearcher(ramDirectory1, true);indexSearcher1.setDefaultFieldSortScoring(true, true);@@ -366,8 +378,8 @@ public class TestMultiSearcher extends LuceneTestCase* @throws IOException*/public void testCustomSimilarity () throws IOException {- MockRAMDirectory dir = new MockRAMDirectory();- initIndex(dir, 10, true, "x"); // documents with two tokens "doc0" and "x", "doc1" and x, etc...+ MockRAMDirectory dir = newDirectory(random);+ initIndex(random, dir, 10, true, "x"); // documents with two tokens "doc0" and "x", "doc1" and x, etc...IndexSearcher srchr = new IndexSearcher(dir, true);MultiSearcher msrchr = getMultiSearcherInstance(new Searcher[]{srchr});@@ -403,30 +415,38 @@ public class TestMultiSearcher extends LuceneTestCase// The scores from the IndexSearcher and Multisearcher should be the same// if the same similarity is used.assertEquals("MultiSearcher score must be equal to single searcher score!", score1, scoreN, 1e-6);+ msrchr.close();+ srchr.close();+ dir.close();}public void testDocFreq() throws IOException{- MockRAMDirectory dir1 = new MockRAMDirectory();- MockRAMDirectory dir2 = new MockRAMDirectory();+ MockRAMDirectory dir1 = newDirectory(random);+ MockRAMDirectory dir2 = newDirectory(random);- initIndex(dir1, 10, true, "x"); // documents with two tokens "doc0" and "x", "doc1" and x, etc...- initIndex(dir2, 5, true, "x"); // documents with two tokens "doc0" and "x", "doc1" and x, etc...+ initIndex(random, dir1, 10, true, "x"); // documents with two tokens "doc0" and "x", "doc1" and x, etc...+ initIndex(random, dir2, 5, true, "x"); // documents with two tokens "doc0" and "x", "doc1" and x, etc...IndexSearcher searcher1 = new IndexSearcher(dir1, true);IndexSearcher searcher2 = new IndexSearcher(dir2, true);MultiSearcher multiSearcher = getMultiSearcherInstance(new Searcher[]{searcher1, searcher2});assertEquals(15, multiSearcher.docFreq(new Term("contents","x")));+ multiSearcher.close();+ searcher1.close();+ searcher2.close();+ dir1.close();+ dir2.close();}public void testCreateDocFrequencyMap() throws IOException{- MockRAMDirectory dir1 = new MockRAMDirectory();- MockRAMDirectory dir2 = new MockRAMDirectory();+ MockRAMDirectory dir1 = newDirectory(random);+ MockRAMDirectory dir2 = newDirectory(random);Term template = new Term("contents") ;String[] contents = {"a", "b", "c"};HashSet<Term> termsSet = new HashSet<Term>();for (int i = 0; i < contents.length; i++) {- initIndex(dir1, i+10, i==0, contents[i]);- initIndex(dir2, i+5, i==0, contents[i]);+ initIndex(random, dir1, i+10, i==0, contents[i]);+ initIndex(random, dir2, i+5, i==0, contents[i]);termsSet.add(template.createTerm(contents[i]));}IndexSearcher searcher1 = new IndexSearcher(dir1, true);@@ -437,5 +457,10 @@ public class TestMultiSearcher extends LuceneTestCasefor (int i = 0; i < contents.length; i++) {assertEquals(Integer.valueOf((i*2) +15), docFrequencyMap.get(template.createTerm(contents[i])));}+ multiSearcher.close();+ searcher1.close();+ searcher2.close();+ dir1.close();+ dir2.close();}}diff --git a/lucene/src/test/org/apache/lucene/search/TestMultiSearcherRanking.java b/lucene/src/test/org/apache/lucene/search/TestMultiSearcherRanking.javaindex efbe3ad83c5..be1658ba5d5 100644--- a/lucene/src/test/org/apache/lucene/search/TestMultiSearcherRanking.java+++ b/lucene/src/test/org/apache/lucene/search/TestMultiSearcherRanking.java@@ -28,6 +28,7 @@ import org.apache.lucene.queryParser.QueryParser;import org.apache.lucene.store.Directory;import org.apache.lucene.store.MockRAMDirectory;import java.io.IOException;+import java.util.Random;/*** Tests {@link MultiSearcher} ranking, i.e. makes sure this bug is fixed:@@ -111,13 +112,14 @@ public class TestMultiSearcherRanking extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();+ Random random = newRandom();// create MultiSearcher from two seperate searchers- Directory d1 = new MockRAMDirectory();- IndexWriter iw1 = new IndexWriter(d1, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ d1 = newDirectory(random);+ IndexWriter iw1 = new IndexWriter(d1, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));addCollection1(iw1);iw1.close();- Directory d2 = new MockRAMDirectory();- IndexWriter iw2 = new IndexWriter(d2, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ d2 = newDirectory(random);+ IndexWriter iw2 = new IndexWriter(d2, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));addCollection2(iw2);iw2.close();@@ -127,14 +129,26 @@ public class TestMultiSearcherRanking extends LuceneTestCase {multiSearcher = new MultiSearcher(s);// create IndexSearcher which contains all documents- Directory d = new MockRAMDirectory();- IndexWriter iw = new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ d = newDirectory(random);+ IndexWriter iw = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));addCollection1(iw);addCollection2(iw);iw.close();singleSearcher = new IndexSearcher(d, true);}+ Directory d1, d2, d;++ @Override+ protected void tearDown() throws Exception {+ multiSearcher.close();+ singleSearcher.close();+ d1.close();+ d2.close();+ d.close();+ super.tearDown();+ }+private void addCollection1(IndexWriter iw) throws IOException {add("one blah three", iw);add("one foo three multiOne", iw);diff --git a/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java b/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.javaindex 58573219c1d..ee66c4100da 100644--- a/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java+++ b/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java@@ -55,7 +55,7 @@ public class TestMultiTermConstantScore extends BaseTestRangeFilter {"B 2 4 5 6", "Y 3 5 6", null, "C 3 6","X 4 5 6" };- small = new MockRAMDirectory();+ small = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, small, new MockAnalyzer(MockTokenizer.WHITESPACE, false));for (int i = 0; i < data.length; i++) {@@ -609,7 +609,7 @@ public class TestMultiTermConstantScore extends BaseTestRangeFilter {public void testFarsi() throws Exception {/* build an index */- MockRAMDirectory farsiIndex = new MockRAMDirectory();+ MockRAMDirectory farsiIndex = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, farsiIndex, new MockAnalyzer(MockTokenizer.SIMPLE, true));Document doc = new Document();doc.add(new Field("content", "\u0633\u0627\u0628", Field.Store.YES,@@ -649,7 +649,7 @@ public class TestMultiTermConstantScore extends BaseTestRangeFilter {public void testDanish() throws Exception {/* build an index */- MockRAMDirectory danishIndex = new MockRAMDirectory();+ MockRAMDirectory danishIndex = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, danishIndex, new MockAnalyzer(MockTokenizer.SIMPLE, true));// Danish collation orders the words below in the given orderdiff --git a/lucene/src/test/org/apache/lucene/search/TestMultiThreadTermVectors.java b/lucene/src/test/org/apache/lucene/search/TestMultiThreadTermVectors.javaindex ef2caf606f5..faea2f40220 100644--- a/lucene/src/test/org/apache/lucene/search/TestMultiThreadTermVectors.java+++ b/lucene/src/test/org/apache/lucene/search/TestMultiThreadTermVectors.java@@ -23,15 +23,15 @@ import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.*;import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.IndexWriter;-import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.TermFreqVector;import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.English;import java.io.IOException;+import java.util.Random;public class TestMultiThreadTermVectors extends LuceneTestCase {- private MockRAMDirectory directory = new MockRAMDirectory();+ private MockRAMDirectory directory;public int numDocs = 100;public int numThreads = 3;@@ -42,7 +42,9 @@ public class TestMultiThreadTermVectors extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ Random random = newRandom();+ directory = newDirectory(random);+ IndexWriter writer = new IndexWriter(directory, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));//writer.setUseCompoundFile(false);//writer.infoStream = System.out;for (int i = 0; i < numDocs; i++) {@@ -55,6 +57,12 @@ public class TestMultiThreadTermVectors extends LuceneTestCase {}+ @Override+ protected void tearDown() throws Exception {+ directory.close();+ super.tearDown();+ }+public void test() throws Exception {IndexReader reader = null;diff --git a/lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java b/lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.javaindex 538b76ef923..c5cbb898d8d 100644--- a/lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestMultiValuedNumericRangeQuery.java@@ -40,7 +40,7 @@ public class TestMultiValuedNumericRangeQuery extends LuceneTestCase {public void testMultiValuedNRQ() throws Exception {final Random rnd = newRandom();- MockRAMDirectory directory = new MockRAMDirectory();+ MockRAMDirectory directory = newDirectory(rnd);RandomIndexWriter writer = new RandomIndexWriter(rnd, directory);DecimalFormat format = new DecimalFormat("00000000000", new DecimalFormatSymbols(Locale.US));diff --git a/lucene/src/test/org/apache/lucene/search/TestNot.java b/lucene/src/test/org/apache/lucene/search/TestNot.javaindex 56ab6de0d6d..9f56a40b14c 100644--- a/lucene/src/test/org/apache/lucene/search/TestNot.java+++ b/lucene/src/test/org/apache/lucene/search/TestNot.java@@ -17,6 +17,8 @@ package org.apache.lucene.search;* limitations under the License.*/+import java.util.Random;+import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.index.IndexReader;@@ -38,8 +40,9 @@ public class TestNot extends LuceneTestCase {}public void testNot() throws Exception {- MockRAMDirectory store = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), store);+ Random random = newRandom();+ MockRAMDirectory store = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, store);Document d1 = new Document();d1.add(new Field("field", "a b", Field.Store.YES, Field.Index.ANALYZED));diff --git a/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java b/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.javaindex f073614a411..4e14de0331c 100644--- a/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java+++ b/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java@@ -49,11 +49,12 @@ public class TestNumericRangeQuery32 extends LuceneTestCaseJ4 {private static MockRAMDirectory directory = null;private static IndexReader reader = null;private static IndexSearcher searcher = null;-+ private static Random random = null;+@BeforeClasspublic static void beforeClass() throws Exception {- directory = new MockRAMDirectory();- Random random = newStaticRandom(TestNumericRangeQuery32.class);+ random = newStaticRandom(TestNumericRangeQuery32.class);+ directory = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, directory);NumericField@@ -280,8 +281,8 @@ public class TestNumericRangeQuery32 extends LuceneTestCaseJ4 {@Testpublic void testInfiniteValues() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ MockRAMDirectory dir = newDirectory(random);+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new NumericField("float").setFloatValue(Float.NEGATIVE_INFINITY));doc.add(new NumericField("int").setIntValue(Integer.MIN_VALUE));diff --git a/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java b/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.javaindex 999115682b5..d7c83e38186 100644--- a/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java+++ b/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java@@ -48,11 +48,12 @@ public class TestNumericRangeQuery64 extends LuceneTestCaseJ4 {private static MockRAMDirectory directory = null;private static IndexReader reader = null;private static IndexSearcher searcher = null;+ private static Random random = null;@BeforeClasspublic static void beforeClass() throws Exception {- directory = new MockRAMDirectory();- Random random = newStaticRandom(TestNumericRangeQuery64.class);+ random = newStaticRandom(TestNumericRangeQuery64.class);+ directory = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, directory);NumericField@@ -298,8 +299,8 @@ public class TestNumericRangeQuery64 extends LuceneTestCaseJ4 {@Testpublic void testInfiniteValues() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(+ MockRAMDirectory dir = newDirectory(random);+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new NumericField("double").setDoubleValue(Double.NEGATIVE_INFINITY));diff --git a/lucene/src/test/org/apache/lucene/search/TestPhrasePrefixQuery.java b/lucene/src/test/org/apache/lucene/search/TestPhrasePrefixQuery.javaindex 7a289240fd5..37823d2b2cf 100644--- a/lucene/src/test/org/apache/lucene/search/TestPhrasePrefixQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestPhrasePrefixQuery.java@@ -30,6 +30,7 @@ import org.apache.lucene.store.MockRAMDirectory;import java.io.IOException;import java.util.LinkedList;+import java.util.Random;/*** This class tests PhrasePrefixQuery class.@@ -43,8 +44,9 @@ public class TestPhrasePrefixQuery extends LuceneTestCase {**/public void testPhrasePrefix() throws IOException {- MockRAMDirectory indexStore = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), indexStore);+ Random random = newRandom();+ MockRAMDirectory indexStore = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, indexStore);Document doc1 = new Document();Document doc2 = new Document();Document doc3 = new Document();diff --git a/lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java b/lucene/src/test/org/apache/lucene/search/TestPhraseQuery.javaindex 36079999b55..c3da70c9766 100644--- a/lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java@@ -55,7 +55,7 @@ public class TestPhraseQuery extends LuceneTestCase {public void setUp() throws Exception {super.setUp();random = newRandom();- directory = new MockRAMDirectory();+ directory = newDirectory(random);Analyzer analyzer = new Analyzer() {@Overridepublic TokenStream tokenStream(String fieldName, Reader reader) {@@ -213,7 +213,7 @@ public class TestPhraseQuery extends LuceneTestCase {}public void testPhraseQueryWithStopAnalyzer() throws Exception {- MockRAMDirectory directory = new MockRAMDirectory();+ MockRAMDirectory directory = newDirectory(random);Analyzer stopAnalyzer = new MockAnalyzer(MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, false);RandomIndexWriter writer = new RandomIndexWriter(random, directory,newIndexWriterConfig(random, Version.LUCENE_24, stopAnalyzer));@@ -249,7 +249,7 @@ public class TestPhraseQuery extends LuceneTestCase {}public void testPhraseQueryInConjunctionScorer() throws Exception {- MockRAMDirectory directory = new MockRAMDirectory();+ MockRAMDirectory directory = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, directory);Document doc = new Document();@@ -336,7 +336,7 @@ public class TestPhraseQuery extends LuceneTestCase {}public void testSlopScoring() throws IOException {- Directory directory = new MockRAMDirectory();+ Directory directory = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, directory);Document doc = new Document();@@ -597,7 +597,7 @@ public class TestPhraseQuery extends LuceneTestCase {}public void testRandomPhrases() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);Analyzer analyzer = new MockAnalyzer();RandomIndexWriter w = new RandomIndexWriter(random, dir, analyzer);diff --git a/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java b/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.javaindex 738d3dfe96e..bd0c0890f9c 100644--- a/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java+++ b/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java@@ -21,6 +21,7 @@ import java.io.Reader;import java.io.IOException;import java.io.StringReader;import java.util.Collection;+import java.util.Random;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.analysis.MockTokenizer;@@ -90,8 +91,9 @@ public class TestPositionIncrement extends LuceneTestCase {};}};- Directory store = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), store, analyzer);+ Random random = newRandom();+ Directory store = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, store, analyzer);Document d = new Document();d.add(new Field("field", "bogus", Field.Store.YES, Field.Index.ANALYZED));writer.addDocument(d);@@ -240,8 +242,9 @@ public class TestPositionIncrement extends LuceneTestCase {new CharacterRunAutomaton(new RegExp("[sS][tT][oO][pP]").toAutomaton());public void testPayloadsPos0() throws Exception {- Directory dir = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), dir, new TestPayloadAnalyzer());+ Random random = newRandom();+ Directory dir = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, dir, new TestPayloadAnalyzer());Document doc = new Document();doc.add(new Field("content", new StringReader("a a b c d e a f g h i j a b k k")));diff --git a/lucene/src/test/org/apache/lucene/search/TestPrefixFilter.java b/lucene/src/test/org/apache/lucene/search/TestPrefixFilter.javaindex 4293cf28319..4368c5cdaf0 100644--- a/lucene/src/test/org/apache/lucene/search/TestPrefixFilter.java+++ b/lucene/src/test/org/apache/lucene/search/TestPrefixFilter.java@@ -17,6 +17,8 @@ package org.apache.lucene.search;* limitations under the License.*/+import java.util.Random;+import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.index.IndexReader;@@ -31,13 +33,14 @@ import org.apache.lucene.document.Field;*/public class TestPrefixFilter extends LuceneTestCase {public void testPrefixFilter() throws Exception {- MockRAMDirectory directory = new MockRAMDirectory();+ Random random = newRandom();+ MockRAMDirectory directory = newDirectory(random);String[] categories = new String[] {"/Computers/Linux","/Computers/Mac/One","/Computers/Mac/Two","/Computers/Windows"};- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);for (int i = 0; i < categories.length; i++) {Document doc = new Document();doc.add(new Field("category", categories[i], Field.Store.YES, Field.Index.NOT_ANALYZED));diff --git a/lucene/src/test/org/apache/lucene/search/TestPrefixInBooleanQuery.java b/lucene/src/test/org/apache/lucene/search/TestPrefixInBooleanQuery.javaindex 6f58d0fa452..0bd4214f7b4 100644--- a/lucene/src/test/org/apache/lucene/search/TestPrefixInBooleanQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestPrefixInBooleanQuery.java@@ -17,6 +17,8 @@ package org.apache.lucene.search;* limitations under the License.*/+import java.util.Random;+import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;@@ -38,15 +40,16 @@ import org.apache.lucene.store.MockRAMDirectory;public class TestPrefixInBooleanQuery extends LuceneTestCase {private static final String FIELD = "name";- private MockRAMDirectory directory = new MockRAMDirectory();+ private MockRAMDirectory directory;private IndexReader reader;private IndexSearcher searcher;@Overrideprotected void setUp() throws Exception {super.setUp();-- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ Random random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);for (int i = 0; i < 5137; ++i) {Document doc = new Document();diff --git a/lucene/src/test/org/apache/lucene/search/TestPrefixQuery.java b/lucene/src/test/org/apache/lucene/search/TestPrefixQuery.javaindex 0e240afc3b2..67228ce1cf2 100644--- a/lucene/src/test/org/apache/lucene/search/TestPrefixQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestPrefixQuery.java@@ -17,6 +17,8 @@ package org.apache.lucene.search;* limitations under the License.*/+import java.util.Random;+import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.index.IndexReader;@@ -31,12 +33,13 @@ import org.apache.lucene.document.Field;*/public class TestPrefixQuery extends LuceneTestCase {public void testPrefixQuery() throws Exception {- MockRAMDirectory directory = new MockRAMDirectory();+ Random random = newRandom();+ MockRAMDirectory directory = newDirectory(random);String[] categories = new String[] {"/Computers","/Computers/Mac","/Computers/Windows"};- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);for (int i = 0; i < categories.length; i++) {Document doc = new Document();doc.add(new Field("category", categories[i], Field.Store.YES, Field.Index.NOT_ANALYZED));diff --git a/lucene/src/test/org/apache/lucene/search/TestPrefixRandom.java b/lucene/src/test/org/apache/lucene/search/TestPrefixRandom.javaindex 37bd93afc40..6dfd43947e2 100644--- a/lucene/src/test/org/apache/lucene/search/TestPrefixRandom.java+++ b/lucene/src/test/org/apache/lucene/search/TestPrefixRandom.java@@ -48,7 +48,7 @@ public class TestPrefixRandom extends LuceneTestCase {protected void setUp() throws Exception {super.setUp();random = newRandom();- dir = new MockRAMDirectory();+ dir = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, dir, new MockAnalyzer(MockTokenizer.KEYWORD, false));Document doc = new Document();diff --git a/lucene/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java b/lucene/src/test/org/apache/lucene/search/TestQueryWrapperFilter.javaindex c7765438032..59a4ebbc6c2 100644--- a/lucene/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java+++ b/lucene/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java@@ -17,6 +17,8 @@ package org.apache.lucene.search;* limitations under the License.*/+import java.util.Random;+import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.document.Field.Index;@@ -26,14 +28,14 @@ import org.apache.lucene.index.RandomIndexWriter;import org.apache.lucene.index.Term;import org.apache.lucene.search.BooleanClause.Occur;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;public class TestQueryWrapperFilter extends LuceneTestCase {public void testBasic() throws Exception {- Directory dir = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), dir);+ Random random = newRandom();+ Directory dir = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, dir);Document doc = new Document();doc.add(new Field("field", "value", Store.NO, Index.ANALYZED));writer.addDocument(doc);diff --git a/lucene/src/test/org/apache/lucene/search/TestRegexpQuery.java b/lucene/src/test/org/apache/lucene/search/TestRegexpQuery.javaindex 8fd0c1aaaed..c961e0ba025 100644--- a/lucene/src/test/org/apache/lucene/search/TestRegexpQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestRegexpQuery.java@@ -19,6 +19,7 @@ package org.apache.lucene.search;import java.io.IOException;import java.util.Arrays;+import java.util.Random;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;@@ -26,7 +27,6 @@ import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.RandomIndexWriter;import org.apache.lucene.index.Term;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.automaton.Automaton;import org.apache.lucene.util.automaton.AutomatonProvider;@@ -45,8 +45,9 @@ public class TestRegexpQuery extends LuceneTestCase {public void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ Random random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);Document doc = new Document();doc.add(new Field(FN,"the quick brown fox jumps over the lazy ??? dog 493432 49344",diff --git a/lucene/src/test/org/apache/lucene/search/TestRegexpRandom.java b/lucene/src/test/org/apache/lucene/search/TestRegexpRandom.javaindex 0e198f74e99..75fc6884fa7 100644--- a/lucene/src/test/org/apache/lucene/search/TestRegexpRandom.java+++ b/lucene/src/test/org/apache/lucene/search/TestRegexpRandom.java@@ -47,7 +47,7 @@ public class TestRegexpRandom extends LuceneTestCase {protected void setUp() throws Exception {super.setUp();random = newRandom();- dir = new MockRAMDirectory();+ dir = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, dir);Document doc = new Document();diff --git a/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java b/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.javaindex 7d69a14103e..cea476eb1d1 100644--- a/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java+++ b/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java@@ -56,7 +56,7 @@ public class TestRegexpRandom2 extends LuceneTestCase {protected void setUp() throws Exception {super.setUp();random = newRandom();- dir = new MockRAMDirectory();+ dir = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, dir, new MockAnalyzer(MockTokenizer.KEYWORD, false));Document doc = new Document();diff --git a/lucene/src/test/org/apache/lucene/search/TestScorerPerf.java b/lucene/src/test/org/apache/lucene/search/TestScorerPerf.javaindex c31279787b3..cb87b4861e4 100755--- a/lucene/src/test/org/apache/lucene/search/TestScorerPerf.java+++ b/lucene/src/test/org/apache/lucene/search/TestScorerPerf.java@@ -36,21 +36,22 @@ import org.apache.lucene.document.Field;*/public class TestScorerPerf extends LuceneTestCase {- Random r;+ Random r = newRandom();boolean validate = true; // set to false when doing performance testingBitSet[] sets;Term[] terms;IndexSearcher s;+ Directory d;public void createDummySearcher() throws Exception {// Create a dummy index with nothing in it.// This could possibly fail if Lucene starts checking for docid ranges...- MockRAMDirectory rd = new MockRAMDirectory();- IndexWriter iw = new IndexWriter(rd, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ d = newDirectory(r);+ IndexWriter iw = new IndexWriter(d, newIndexWriterConfig(r, TEST_VERSION_CURRENT, new MockAnalyzer()));iw.addDocument(new Document());iw.close();- s = new IndexSearcher(rd, true);+ s = new IndexSearcher(d, true);}public void createRandomTerms(int nDocs, int nTerms, double power, Directory dir) throws Exception {@@ -62,7 +63,7 @@ public class TestScorerPerf extends LuceneTestCase {terms[i] = new Term("f",Character.toString((char)('A'+i)));}- IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));+ IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(r, TEST_VERSION_CURRENT, new MockAnalyzer()).setOpenMode(OpenMode.CREATE));for (int i=0; i<nDocs; i++) {Document d = new Document();for (int j=0; j<nTerms; j++) {@@ -315,13 +316,13 @@ public class TestScorerPerf extends LuceneTestCase {public void testConjunctions() throws Exception {// test many small sets... the bugs will be found on boundary conditions- r = newRandom();createDummySearcher();validate=true;sets=randBitSets(1000 * RANDOM_MULTIPLIER, 10 * RANDOM_MULTIPLIER);doConjunctions(10000 * RANDOM_MULTIPLIER, 5 * RANDOM_MULTIPLIER);doNestedConjunctions(10000 * RANDOM_MULTIPLIER, 3 * RANDOM_MULTIPLIER, 3 * RANDOM_MULTIPLIER);s.close();+ d.close();}/***diff --git a/lucene/src/test/org/apache/lucene/search/TestSetNorm.java b/lucene/src/test/org/apache/lucene/search/TestSetNorm.javaindex d1f3df1d429..3581342274e 100644--- a/lucene/src/test/org/apache/lucene/search/TestSetNorm.java+++ b/lucene/src/test/org/apache/lucene/search/TestSetNorm.java@@ -18,6 +18,7 @@ package org.apache.lucene.search;*/import java.io.IOException;+import java.util.Random;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.analysis.MockAnalyzer;@@ -39,8 +40,9 @@ public class TestSetNorm extends LuceneTestCase {}public void testSetNorm() throws Exception {- MockRAMDirectory store = new MockRAMDirectory();- IndexWriter writer = new IndexWriter(store, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ Random random = newRandom();+ MockRAMDirectory store = newDirectory(random);+ IndexWriter writer = new IndexWriter(store, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));// add the same document four timesFieldable f1 = new Field("field", "word", Field.Store.YES, Field.Index.ANALYZED);@@ -63,7 +65,8 @@ public class TestSetNorm extends LuceneTestCase {// check that searches are ordered by this boostfinal float[] scores = new float[4];- new IndexSearcher(store, true).search+ IndexSearcher is = new IndexSearcher(store, true);+ is.search(new TermQuery(new Term("field", "word")),new Collector() {private int base = 0;@@ -85,12 +88,13 @@ public class TestSetNorm extends LuceneTestCase {return true;}});-+ is.close();float lastScore = 0.0f;for (int i = 0; i < 4; i++) {assertTrue(scores[i] > lastScore);lastScore = scores[i];}+ store.close();}}diff --git a/lucene/src/test/org/apache/lucene/search/TestSimilarity.java b/lucene/src/test/org/apache/lucene/search/TestSimilarity.javaindex 32a2316f4c0..cfa18285972 100644--- a/lucene/src/test/org/apache/lucene/search/TestSimilarity.java+++ b/lucene/src/test/org/apache/lucene/search/TestSimilarity.java@@ -65,8 +65,8 @@ public class TestSimilarity extends LuceneTestCase {}public void testSimilarity() throws Exception {- MockRAMDirectory store = new MockRAMDirectory();Random random = newRandom();+ MockRAMDirectory store = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, store,newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setSimilarity(new SimpleSimilarity()));diff --git a/lucene/src/test/org/apache/lucene/search/TestSimpleExplanations.java b/lucene/src/test/org/apache/lucene/search/TestSimpleExplanations.javaindex 8ee02d9c024..ab08f89b93a 100644--- a/lucene/src/test/org/apache/lucene/search/TestSimpleExplanations.java+++ b/lucene/src/test/org/apache/lucene/search/TestSimpleExplanations.java@@ -17,6 +17,8 @@ package org.apache.lucene.search;* limitations under the License.*/+import java.util.Random;+import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;@@ -307,8 +309,8 @@ public class TestSimpleExplanations extends TestExplanations {public void testTermQueryMultiSearcherExplain() throws Exception {// creating two directories for indices- Directory indexStoreA = new MockRAMDirectory();- Directory indexStoreB = new MockRAMDirectory();+ Directory indexStoreA = newDirectory(random);+ Directory indexStoreB = newDirectory(random);Document lDoc = new Document();lDoc.add(new Field("handle", "1 2", Field.Store.YES, Field.Index.ANALYZED));@@ -317,9 +319,9 @@ public class TestSimpleExplanations extends TestExplanations {Document lDoc3 = new Document();lDoc3.add(new Field("handle", "1 2", Field.Store.YES, Field.Index.ANALYZED));- IndexWriter writerA = new IndexWriter(indexStoreA, new IndexWriterConfig(+ IndexWriter writerA = new IndexWriter(indexStoreA, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));- IndexWriter writerB = new IndexWriter(indexStoreB, new IndexWriterConfig(+ IndexWriter writerB = new IndexWriter(indexStoreB, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));writerA.addDocument(lDoc);@@ -368,6 +370,8 @@ public class TestSimpleExplanations extends TestExplanations {assertTrue(exp, exp.indexOf("1=3") > -1);assertTrue(exp, exp.indexOf("2=3") > -1);mSearcher.close();+ indexStoreA.close();+ indexStoreB.close();}}diff --git a/lucene/src/test/org/apache/lucene/search/TestSloppyPhraseQuery.java b/lucene/src/test/org/apache/lucene/search/TestSloppyPhraseQuery.javaindex b0b76279bda..33c0c982bf0 100755--- a/lucene/src/test/org/apache/lucene/search/TestSloppyPhraseQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestSloppyPhraseQuery.java@@ -125,7 +125,7 @@ public class TestSloppyPhraseQuery extends LuceneTestCase {private float checkPhraseQuery(Document doc, PhraseQuery query, int slop, int expectedNumResults) throws Exception {query.setSlop(slop);- MockRAMDirectory ramDir = new MockRAMDirectory();+ MockRAMDirectory ramDir = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, ramDir, new MockAnalyzer(MockTokenizer.WHITESPACE, false));writer.addDocument(doc);diff --git a/lucene/src/test/org/apache/lucene/search/TestSort.java b/lucene/src/test/org/apache/lucene/search/TestSort.javaindex 15dfeb2900c..9503a396716 100644--- a/lucene/src/test/org/apache/lucene/search/TestSort.java+++ b/lucene/src/test/org/apache/lucene/search/TestSort.java@@ -19,6 +19,7 @@ package org.apache.lucene.search;import java.io.IOException;import java.io.Serializable;+import java.util.ArrayList;import java.util.BitSet;import java.util.HashMap;import java.util.Iterator;@@ -45,7 +46,6 @@ import org.apache.lucene.search.FieldValueHitQueue.Entry;import org.apache.lucene.store.LockObtainFailedException;import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.DocIdBitSet;import org.apache.lucene.util.LuceneTestCase;@@ -60,9 +60,9 @@ import org.apache.lucene.util.LuceneTestCase;public class TestSort extends LuceneTestCase implements Serializable {private static final int NUM_STRINGS = 6000 * RANDOM_MULTIPLIER;- private Searcher full;- private Searcher searchX;- private Searcher searchY;+ private IndexSearcher full;+ private IndexSearcher searchX;+ private IndexSearcher searchY;private Query queryX;private Query queryY;private Query queryA;@@ -108,9 +108,10 @@ public class TestSort extends LuceneTestCase implements Serializable {};// create an index of all the documents, or just the x, or just the y documents- private Searcher getIndex (boolean even, boolean odd)+ private IndexSearcher getIndex (boolean even, boolean odd)throws IOException {- MockRAMDirectory indexStore = new MockRAMDirectory();+ MockRAMDirectory indexStore = newDirectory(random);+ dirs.add(indexStore);RandomIndexWriter writer = new RandomIndexWriter(random, indexStore);for (int i=0; i<data.length; ++i) {@@ -139,13 +140,14 @@ public class TestSort extends LuceneTestCase implements Serializable {return s;}- private Searcher getFullIndex()+ private IndexSearcher getFullIndex()throws IOException {return getIndex (true, true);}private IndexSearcher getFullStrings() throws CorruptIndexException, LockObtainFailedException, IOException {- MockRAMDirectory indexStore = new MockRAMDirectory ();+ MockRAMDirectory indexStore = newDirectory (random);+ dirs.add(indexStore);IndexWriter writer = new IndexWriter(indexStore, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()).setMaxBufferedDocs(4));((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(97);@@ -197,17 +199,17 @@ public class TestSort extends LuceneTestCase implements Serializable {return randInt;}- private Searcher getXIndex()+ private IndexSearcher getXIndex()throws IOException {return getIndex (true, false);}- private Searcher getYIndex()+ private IndexSearcher getYIndex()throws IOException {return getIndex (false, true);}- private Searcher getEmptyIndex()+ private IndexSearcher getEmptyIndex()throws IOException {return getIndex (false, false);}@@ -226,6 +228,21 @@ public class TestSort extends LuceneTestCase implements Serializable {queryG = new TermQuery (new Term ("contents", "g"));sort = new Sort();}++ private ArrayList<Directory> dirs = new ArrayList<Directory>();++ @Override+ protected void tearDown() throws Exception {+ full.reader.close();+ searchX.reader.close();+ searchY.reader.close();+ full.close();+ searchX.close();+ searchY.close();+ for (Directory dir : dirs)+ dir.close();+ super.tearDown();+ }// test the sorts by score and document numberpublic void testBuiltInSorts() throws Exception {@@ -323,7 +340,7 @@ public class TestSort extends LuceneTestCase implements Serializable {System.out.println("topn field1(field2)(docID):" + buff);}assertFalse("Found sort results out of order", fail);-+ searcher.close();}/**@@ -1015,8 +1032,8 @@ public class TestSort extends LuceneTestCase implements Serializable {}public void testEmptyStringVsNullStringSort() throws Exception {- Directory dir = new MockRAMDirectory();- IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(+ Directory dir = newDirectory(random);+ IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));Document doc = new Document();doc.add(new Field("f", "", Field.Store.NO, Field.Index.NOT_ANALYZED));@@ -1040,8 +1057,8 @@ public class TestSort extends LuceneTestCase implements Serializable {}public void testLUCENE2142() throws IOException {- MockRAMDirectory indexStore = new MockRAMDirectory ();- IndexWriter writer = new IndexWriter(indexStore, new IndexWriterConfig(+ MockRAMDirectory indexStore = newDirectory (random);+ IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(random,TEST_VERSION_CURRENT, new MockAnalyzer()));for (int i=0; i<5; i++) {Document doc = new Document();@@ -1055,7 +1072,10 @@ public class TestSort extends LuceneTestCase implements Serializable {new SortField("string", SortField.STRING),SortField.FIELD_DOC );// this should not throw AIOOBE or RuntimeEx- new IndexSearcher (indexStore, true).search(new MatchAllDocsQuery(), null, 500, sort);+ IndexSearcher searcher = new IndexSearcher(indexStore, true);+ searcher.search(new MatchAllDocsQuery(), null, 500, sort);+ searcher.close();+ indexStore.close();}}diff --git a/lucene/src/test/org/apache/lucene/search/TestSpanQueryFilter.java b/lucene/src/test/org/apache/lucene/search/TestSpanQueryFilter.javaindex 2e810040731..a68f4888806 100644--- a/lucene/src/test/org/apache/lucene/search/TestSpanQueryFilter.java+++ b/lucene/src/test/org/apache/lucene/search/TestSpanQueryFilter.java@@ -17,6 +17,7 @@ package org.apache.lucene.search;*/import java.util.List;+import java.util.Random;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;@@ -26,7 +27,6 @@ import org.apache.lucene.index.SlowMultiReaderWrapper;import org.apache.lucene.index.Term;import org.apache.lucene.search.spans.SpanTermQuery;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.English;import org.apache.lucene.util.LuceneTestCase;@@ -38,8 +38,9 @@ public class TestSpanQueryFilter extends LuceneTestCase {}public void testFilterWorks() throws Exception {- Directory dir = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), dir);+ Random random = newRandom();+ Directory dir = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, dir);for (int i = 0; i < 500; i++) {Document document = new Document();document.add(new Field("field", English.intToEnglish(i) + " equals " + English.intToEnglish(i),diff --git a/lucene/src/test/org/apache/lucene/search/TestTermRangeFilter.java b/lucene/src/test/org/apache/lucene/search/TestTermRangeFilter.javaindex f07dc1ec784..ebbcf375d83 100644--- a/lucene/src/test/org/apache/lucene/search/TestTermRangeFilter.java+++ b/lucene/src/test/org/apache/lucene/search/TestTermRangeFilter.java@@ -398,7 +398,7 @@ public class TestTermRangeFilter extends BaseTestRangeFilter {public void testFarsi() throws Exception {/* build an index */- MockRAMDirectory farsiIndex = new MockRAMDirectory();+ MockRAMDirectory farsiIndex = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, farsiIndex);Document doc = new Document();doc.add(new Field("content", "\u0633\u0627\u0628", Field.Store.YES,@@ -438,7 +438,7 @@ public class TestTermRangeFilter extends BaseTestRangeFilter {public void testDanish() throws Exception {/* build an index */- MockRAMDirectory danishIndex = new MockRAMDirectory();+ MockRAMDirectory danishIndex = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, danishIndex);// Danish collation orders the words below in the given order// (example taken from TestSort.testInternationalSort() ).diff --git a/lucene/src/test/org/apache/lucene/search/TestTermRangeQuery.java b/lucene/src/test/org/apache/lucene/search/TestTermRangeQuery.javaindex dd7fc6a4191..0afbe66a91a 100644--- a/lucene/src/test/org/apache/lucene/search/TestTermRangeQuery.java+++ b/lucene/src/test/org/apache/lucene/search/TestTermRangeQuery.java@@ -20,7 +20,6 @@ package org.apache.lucene.search;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.index.IndexWriter;-import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.IndexWriterConfig.OpenMode;import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.analysis.Analyzer;@@ -34,6 +33,7 @@ import org.apache.lucene.util.LuceneTestCase;import java.io.IOException;import java.io.Reader;import java.util.Locale;+import java.util.Random;import java.util.Set;import java.util.HashSet;import java.util.Arrays;@@ -44,11 +44,19 @@ public class TestTermRangeQuery extends LuceneTestCase {private int docCount = 0;private MockRAMDirectory dir;-+ private Random random;+@Overrideprotected void setUp() throws Exception {super.setUp();- dir = new MockRAMDirectory();+ random = newRandom();+ dir = newDirectory(random);+ }++ @Override+ protected void tearDown() throws Exception {+ dir.close();+ super.tearDown();}public void testExclusive() throws Exception {@@ -333,7 +341,7 @@ public class TestTermRangeQuery extends LuceneTestCase {}private void initializeIndex(String[] values, Analyzer analyzer) throws IOException {- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,TEST_VERSION_CURRENT, analyzer).setOpenMode(OpenMode.CREATE));for (int i = 0; i < values.length; i++) {insertDoc(writer, values[i]);@@ -342,7 +350,7 @@ public class TestTermRangeQuery extends LuceneTestCase {}private void addDoc(String content) throws IOException {- IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setOpenMode(OpenMode.APPEND));+ IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false)).setOpenMode(OpenMode.APPEND));insertDoc(writer, content);writer.close();}diff --git a/lucene/src/test/org/apache/lucene/search/TestTermScorer.java b/lucene/src/test/org/apache/lucene/search/TestTermScorer.javaindex aef5c62e224..fbcf58cbe75 100644--- a/lucene/src/test/org/apache/lucene/search/TestTermScorer.java+++ b/lucene/src/test/org/apache/lucene/search/TestTermScorer.java@@ -20,6 +20,7 @@ package org.apache.lucene.search;import java.io.IOException;import java.util.ArrayList;import java.util.List;+import java.util.Random;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.document.Document;@@ -46,9 +47,10 @@ public class TestTermScorer extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();+ Random random = newRandom();+ directory = newDirectory(random);- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory);for (int i = 0; i < values.length; i++) {Document doc = new Document();docdiff --git a/lucene/src/test/org/apache/lucene/search/TestTermVectors.java b/lucene/src/test/org/apache/lucene/search/TestTermVectors.javaindex d925b9ac6f7..5414b39fc1d 100644--- a/lucene/src/test/org/apache/lucene/search/TestTermVectors.java+++ b/lucene/src/test/org/apache/lucene/search/TestTermVectors.java@@ -26,7 +26,6 @@ import org.apache.lucene.document.Field;import org.apache.lucene.index.*;import org.apache.lucene.index.IndexWriterConfig.OpenMode;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.English;import java.io.IOException;@@ -38,7 +37,7 @@ import java.util.SortedSet;public class TestTermVectors extends LuceneTestCase {private IndexSearcher searcher;private IndexReader reader;- private Directory directory = new MockRAMDirectory();+ private Directory directory;private Random random;@@ -50,6 +49,7 @@ public class TestTermVectors extends LuceneTestCase {protected void setUp() throws Exception {super.setUp();random = newRandom();+ directory = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, directory, new MockAnalyzer(MockTokenizer.SIMPLE, true));//writer.setUseCompoundFile(true);//writer.infoStream = System.out;@@ -115,7 +115,7 @@ public class TestTermVectors extends LuceneTestCase {}public void testTermVectorsFieldOrder() throws IOException {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, dir, new MockAnalyzer(MockTokenizer.SIMPLE, true));Document doc = new Document();doc.add(new Field("c", "some content here", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));@@ -243,7 +243,7 @@ public class TestTermVectors extends LuceneTestCase {Document testDoc4 = new Document();setupDoc(testDoc4, test4);- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, dir,newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true))diff --git a/lucene/src/test/org/apache/lucene/search/TestThreadSafe.java b/lucene/src/test/org/apache/lucene/search/TestThreadSafe.javaindex d2f605725ec..2ae2c680ab0 100755--- a/lucene/src/test/org/apache/lucene/search/TestThreadSafe.java+++ b/lucene/src/test/org/apache/lucene/search/TestThreadSafe.java@@ -18,7 +18,6 @@ package org.apache.lucene.search;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.IndexWriterConfig;@@ -33,10 +32,8 @@ import java.io.IOException;public class TestThreadSafe extends LuceneTestCase {Random r;Directory dir1;- Directory dir2;IndexReader ir1;- IndexReader ir2;String failure=null;@@ -142,7 +139,7 @@ public class TestThreadSafe extends LuceneTestCase {public void testLazyLoadThreadSafety() throws Exception{r = newRandom();- dir1 = new MockRAMDirectory();+ dir1 = newDirectory(r);// test w/ field sizes bigger than the buffer of an index inputbuildDir(dir1, 15, 5, 2000);@@ -151,7 +148,9 @@ public class TestThreadSafe extends LuceneTestCase {for (int i = 0; i < num; i++) {ir1 = IndexReader.open(dir1, false);doTest(10,100);+ ir1.close();}+ dir1.close();}}diff --git a/lucene/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java b/lucene/src/test/org/apache/lucene/search/TestTimeLimitingCollector.javaindex 0f48ddfd2e2..be29841d866 100644--- a/lucene/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java+++ b/lucene/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java@@ -19,6 +19,7 @@ package org.apache.lucene.search;import java.io.IOException;import java.util.BitSet;+import java.util.Random;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;@@ -76,8 +77,9 @@ public class TestTimeLimitingCollector extends LuceneTestCase {"blueberry strudel","blueberry pizza",};- directory = new MockRAMDirectory();- RandomIndexWriter iw = new RandomIndexWriter(newRandom(), directory);+ Random random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter iw = new RandomIndexWriter(random, directory);for (int i=0; i<N_DOCS; i++) {add(docText[i%docText.length], iw);diff --git a/lucene/src/test/org/apache/lucene/search/TestTopDocsCollector.java b/lucene/src/test/org/apache/lucene/search/TestTopDocsCollector.javaindex f3b79c1cd4a..621c5cc237a 100644--- a/lucene/src/test/org/apache/lucene/search/TestTopDocsCollector.java+++ b/lucene/src/test/org/apache/lucene/search/TestTopDocsCollector.java@@ -18,12 +18,12 @@ package org.apache.lucene.search;*/import java.io.IOException;+import java.util.Random;import org.apache.lucene.document.Document;import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.RandomIndexWriter;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;public class TestTopDocsCollector extends LuceneTestCase {@@ -90,7 +90,7 @@ public class TestTopDocsCollector extends LuceneTestCase {private static final float MAX_SCORE = 9.17561f;- private Directory dir = new MockRAMDirectory();+ private Directory dir;private IndexReader reader;private TopDocsCollector<ScoreDoc> doSearch(int numResults) throws IOException {@@ -108,7 +108,9 @@ public class TestTopDocsCollector extends LuceneTestCase {// populate an index with 30 documents, this should be enough for the test.// The documents have no content - the test uses MatchAllDocsQuery().- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), dir);+ Random random = newRandom();+ dir = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, dir);for (int i = 0; i < 30; i++) {writer.addDocument(new Document());}diff --git a/lucene/src/test/org/apache/lucene/search/TestTopScoreDocCollector.java b/lucene/src/test/org/apache/lucene/search/TestTopScoreDocCollector.javaindex 765c374cff4..26e7e66adfe 100644--- a/lucene/src/test/org/apache/lucene/search/TestTopScoreDocCollector.java+++ b/lucene/src/test/org/apache/lucene/search/TestTopScoreDocCollector.java@@ -24,7 +24,6 @@ import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.RandomIndexWriter;import org.apache.lucene.search.BooleanClause.Occur;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;public class TestTopScoreDocCollector extends LuceneTestCase {@@ -37,9 +36,8 @@ public class TestTopScoreDocCollector extends LuceneTestCase {}public void testOutOfOrderCollection() throws Exception {-- Directory dir = new MockRAMDirectory();Random random = newRandom();+ Directory dir = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, dir);for (int i = 0; i < 10; i++) {writer.addDocument(new Document());diff --git a/lucene/src/test/org/apache/lucene/search/TestWildcard.java b/lucene/src/test/org/apache/lucene/search/TestWildcard.javaindex 7ac8ddb3bfa..99e08b1634f 100644--- a/lucene/src/test/org/apache/lucene/search/TestWildcard.java+++ b/lucene/src/test/org/apache/lucene/search/TestWildcard.java@@ -99,6 +99,8 @@ public class TestWildcardq = searcher.rewrite(wq);assertTrue(q instanceof ConstantScoreQuery);assertEquals(q.getBoost(), wq.getBoost());+ searcher.close();+ indexStore.close();}/**@@ -114,6 +116,8 @@ public class TestWildcardQuery q = searcher.rewrite(wq);assertTrue(q instanceof BooleanQuery);assertEquals(0, ((BooleanQuery) q).clauses().size());+ searcher.close();+ indexStore.close();}/**@@ -134,6 +138,8 @@ public class TestWildcardassertMatches(searcher, wq, 2);assertFalse(wq.getTermsEnum(searcher.getIndexReader()) instanceof PrefixTermsEnum);assertFalse(wq.getTermsEnum(searcher.getIndexReader()) instanceof AutomatonTermsEnum);+ searcher.close();+ indexStore.close();}/**@@ -171,6 +177,8 @@ public class TestWildcardassertMatches(searcher, new WildcardQuery(new Term("body", "*tall")), 0);assertMatches(searcher, new WildcardQuery(new Term("body", "*tal")), 1);assertMatches(searcher, new WildcardQuery(new Term("body", "*tal*")), 2);+ searcher.close();+ indexStore.close();}/**@@ -196,11 +204,13 @@ public class TestWildcardassertMatches(searcher, query4, 3);assertMatches(searcher, query5, 0);assertMatches(searcher, query6, 1); // Query: 'meta??' matches 'metals' not 'metal'+ searcher.close();+ indexStore.close();}private MockRAMDirectory getIndexStore(String field, String[] contents)throws IOException {- MockRAMDirectory indexStore = new MockRAMDirectory();+ MockRAMDirectory indexStore = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, indexStore);for (int i = 0; i < contents.length; ++i) {Document doc = new Document();@@ -256,7 +266,7 @@ public class TestWildcard};// prepare the index- MockRAMDirectory dir = new MockRAMDirectory();+ MockRAMDirectory dir = newDirectory(random);RandomIndexWriter iw = new RandomIndexWriter(random, dir);for (int i = 0; i < docs.length; i++) {Document doc = new Document();@@ -312,5 +322,6 @@ public class TestWildcard}searcher.close();+ dir.close();}}diff --git a/lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java b/lucene/src/test/org/apache/lucene/search/TestWildcardRandom.javaindex 5d92ddb30cb..09e08deebba 100644--- a/lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java+++ b/lucene/src/test/org/apache/lucene/search/TestWildcardRandom.java@@ -47,7 +47,7 @@ public class TestWildcardRandom extends LuceneTestCase {protected void setUp() throws Exception {super.setUp();random = newRandom();- dir = new MockRAMDirectory();+ dir = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, dir);Document doc = new Document();diff --git a/lucene/src/test/org/apache/lucene/search/function/FunctionTestSetup.java b/lucene/src/test/org/apache/lucene/search/function/FunctionTestSetup.javaindex 223e1965957..b43fa71c140 100755--- a/lucene/src/test/org/apache/lucene/search/function/FunctionTestSetup.java+++ b/lucene/src/test/org/apache/lucene/search/function/FunctionTestSetup.java@@ -25,7 +25,6 @@ import org.apache.lucene.document.Fieldable;import org.apache.lucene.index.RandomIndexWriter;import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCaseJ4;import org.apache.lucene.util._TestUtil;import java.util.Random;@@ -85,9 +84,10 @@ public class FunctionTestSetup extends LuceneTestCaseJ4 {@Override@Afterpublic void tearDown() throws Exception {- super.tearDown();+ dir.close();dir = null;anlzr = null;+ super.tearDown();}@Override@@ -95,9 +95,9 @@ public class FunctionTestSetup extends LuceneTestCaseJ4 {public void setUp() throws Exception {super.setUp();// prepare a small index with just a few documents.- dir = new MockRAMDirectory();- anlzr = new MockAnalyzer();Random r = newRandom();+ dir = newDirectory(r);+ anlzr = new MockAnalyzer();IndexWriterConfig iwc = newIndexWriterConfig(r, TEST_VERSION_CURRENT, anlzr);if (doMultiSegment) {iwc.setMaxBufferedDocs(_TestUtil.nextInt(r, 2, 7));diff --git a/lucene/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java b/lucene/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.javaindex c6cbc59096a..6538797a3a5 100755--- a/lucene/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java+++ b/lucene/src/test/org/apache/lucene/search/function/TestCustomScoreQuery.java@@ -281,6 +281,7 @@ public class TestCustomScoreQuery extends FunctionTestSetup {verifyResults(boost, s,h1, h2CustomNeutral, h3CustomMul, h4CustomAdd, h5CustomMulAdd,q1, q2CustomNeutral, q3CustomMul, q4CustomAdd, q5CustomMulAdd);+ s.close();}// verify results are as expected.diff --git a/lucene/src/test/org/apache/lucene/search/function/TestFieldScoreQuery.java b/lucene/src/test/org/apache/lucene/search/function/TestFieldScoreQuery.javaindex 1163b78557b..c18b5aa5688 100755--- a/lucene/src/test/org/apache/lucene/search/function/TestFieldScoreQuery.java+++ b/lucene/src/test/org/apache/lucene/search/function/TestFieldScoreQuery.java@@ -91,6 +91,7 @@ public class TestFieldScoreQuery extends FunctionTestSetup {assertTrue("res id "+resID+" should be < prev res id "+prevID, resID.compareTo(prevID)<0);prevID = resID;}+ s.close();}/** Test that FieldScoreQuery of Type.BYTE returns the expected scores. */@@ -136,6 +137,7 @@ public class TestFieldScoreQuery extends FunctionTestSetup {float expectedScore = expectedFieldScore(id); // "ID7" --> 7.0assertEquals("score of " + id + " shuould be " + expectedScore + " != " + score, expectedScore, score, TEST_SCORE_TOLERANCE_DELTA);}+ s.close();}/** Test that FieldScoreQuery of Type.BYTE caches/reuses loaded values and consumes the proper RAM resources. */@@ -210,7 +212,7 @@ public class TestFieldScoreQuery extends FunctionTestSetup {}}}-+ s.close();// verify new values are reloaded (not reused) for a new readers = new IndexSearcher(dir, true);FieldScoreQuery q = new FieldScoreQuery(field,tp);@@ -233,6 +235,7 @@ public class TestFieldScoreQuery extends FunctionTestSetup {}}}+ s.close();}private String testName() {diff --git a/lucene/src/test/org/apache/lucene/search/function/TestOrdValues.java b/lucene/src/test/org/apache/lucene/search/function/TestOrdValues.javaindex 9a1d02a673e..3e2ffb43ad0 100644--- a/lucene/src/test/org/apache/lucene/search/function/TestOrdValues.java+++ b/lucene/src/test/org/apache/lucene/search/function/TestOrdValues.java@@ -87,6 +87,7 @@ public class TestOrdValues extends FunctionTestSetup {}prevID = resID;}+ s.close();}/**@@ -131,6 +132,7 @@ public class TestOrdValues extends FunctionTestSetup {: id2String(i + 1); // reverse ==> smaller values firstassertTrue("id of result " + i + " shuould be " + expectedId + " != " + score, expectedId.equals(id));}+ s.close();}/**@@ -217,7 +219,7 @@ public class TestOrdValues extends FunctionTestSetup {}}}-+ s.close();// verify new values are reloaded (not reused) for a new readers = new IndexSearcher(dir, true);if (inOrder) {@@ -245,6 +247,7 @@ public class TestOrdValues extends FunctionTestSetup {}}}+ s.close();}private String testName() {diff --git a/lucene/src/test/org/apache/lucene/search/function/TestValueSource.java b/lucene/src/test/org/apache/lucene/search/function/TestValueSource.javaindex 8ad41f9a754..a9aab6f0533 100644--- a/lucene/src/test/org/apache/lucene/search/function/TestValueSource.java+++ b/lucene/src/test/org/apache/lucene/search/function/TestValueSource.java@@ -28,7 +28,7 @@ import org.apache.lucene.document.*;public class TestValueSource extends LuceneTestCase {public void testMultiValueSource() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(newRandom());IndexWriter w = new IndexWriter(dir, new MockAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);Document doc = new Document();Field f = new Field("field", "", Field.Store.NO, Field.Index.NOT_ANALYZED);diff --git a/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java b/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.javaindex 4a4e7fa2491..2705fa6a26f 100644--- a/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java+++ b/lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java@@ -107,6 +107,7 @@ public class PayloadHelper {* @return An IndexSearcher* @throws IOException*/+ // TODO: randomizepublic IndexSearcher setUp(Similarity similarity, int numDocs) throws IOException {MockRAMDirectory directory = new MockRAMDirectory();PayloadAnalyzer analyzer = new PayloadAnalyzer();diff --git a/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java b/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.javaindex 7e66ea5105c..703bda21811 100644--- a/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java+++ b/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java@@ -28,7 +28,6 @@ import org.apache.lucene.analysis.tokenattributes.PayloadAttribute;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.index.IndexReader;-import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.index.Payload;import org.apache.lucene.index.RandomIndexWriter;import org.apache.lucene.index.Term;@@ -42,7 +41,6 @@ import org.apache.lucene.search.spans.SpanQuery;import org.apache.lucene.search.spans.SpanNearQuery;import org.apache.lucene.search.spans.SpanTermQuery;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.English;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.search.Explanation.IDFExplanation;@@ -106,8 +104,8 @@ public class TestPayloadNearQuery extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();Random random = newRandom();+ directory = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, directory,newIndexWriterConfig(random, TEST_VERSION_CURRENT, new PayloadAnalyzer()).setSimilarity(similarity));diff --git a/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java b/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.javaindex 9964dafce70..f6b8b3d5faf 100644--- a/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java+++ b/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java@@ -112,8 +112,8 @@ public class TestPayloadTermQuery extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();Random random = newRandom();+ directory = newDirectory(random);RandomIndexWriter writer = new RandomIndexWriter(random, directory,newIndexWriterConfig(random, TEST_VERSION_CURRENT, new PayloadAnalyzer()).setSimilarity(similarity));diff --git a/lucene/src/test/org/apache/lucene/search/spans/TestBasics.java b/lucene/src/test/org/apache/lucene/search/spans/TestBasics.javaindex 19b9dce0c1f..ee20850ecbe 100644--- a/lucene/src/test/org/apache/lucene/search/spans/TestBasics.java+++ b/lucene/src/test/org/apache/lucene/search/spans/TestBasics.java@@ -18,6 +18,7 @@ package org.apache.lucene.search.spans;*/import java.io.IOException;+import java.util.Random;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.analysis.MockTokenizer;@@ -60,8 +61,9 @@ public class TestBasics extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();- RandomIndexWriter writer = new RandomIndexWriter(newRandom(), directory,+ Random random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter writer = new RandomIndexWriter(random, directory,new MockAnalyzer(MockTokenizer.SIMPLE, true));//writer.infoStream = System.out;for (int i = 0; i < 1000; i++) {diff --git a/lucene/src/test/org/apache/lucene/search/spans/TestFieldMaskingSpanQuery.java b/lucene/src/test/org/apache/lucene/search/spans/TestFieldMaskingSpanQuery.javaindex b355f5255d3..5459b4e55ec 100644--- a/lucene/src/test/org/apache/lucene/search/spans/TestFieldMaskingSpanQuery.java+++ b/lucene/src/test/org/apache/lucene/search/spans/TestFieldMaskingSpanQuery.java@@ -18,6 +18,7 @@ package org.apache.lucene.search.spans;*/import java.util.HashSet;+import java.util.Random;import java.util.Set;import org.apache.lucene.document.Document;@@ -31,7 +32,6 @@ import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.Query;import org.apache.lucene.search.QueryUtils;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;public class TestFieldMaskingSpanQuery extends LuceneTestCase {@@ -55,8 +55,9 @@ public class TestFieldMaskingSpanQuery extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();- RandomIndexWriter writer= new RandomIndexWriter(newRandom(), directory);+ Random random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter writer= new RandomIndexWriter(random, directory);writer.addDocument(doc(new Field[] { field("id", "0"),diff --git a/lucene/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java b/lucene/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.javaindex e053ea2b7fa..9ad318c2bcb 100644--- a/lucene/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java+++ b/lucene/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java@@ -17,6 +17,8 @@ package org.apache.lucene.search.spans;* limitations under the License.*/+import java.util.Random;+import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;@@ -31,7 +33,6 @@ import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.Weight;import org.apache.lucene.search.Scorer;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;public class TestNearSpansOrdered extends LuceneTestCase {@@ -54,8 +55,9 @@ public class TestNearSpansOrdered extends LuceneTestCase {@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();- RandomIndexWriter writer= new RandomIndexWriter(newRandom(), directory);+ Random random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter writer= new RandomIndexWriter(random, directory);for (int i = 0; i < docFields.length; i++) {Document doc = new Document();doc.add(new Field(FIELD, docFields[i], Field.Store.NO, Field.Index.ANALYZED));diff --git a/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java b/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.javaindex e68375dd267..355dbddd1b0 100644--- a/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java+++ b/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java@@ -46,6 +46,7 @@ import org.apache.lucene.search.TermQuery;import org.apache.lucene.search.TopDocs;import org.apache.lucene.search.payloads.PayloadHelper;import org.apache.lucene.search.payloads.PayloadSpanUtil;+import org.apache.lucene.store.Directory;import org.apache.lucene.store.LockObtainFailedException;import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.LuceneTestCase;@@ -56,7 +57,8 @@ public class TestPayloadSpans extends LuceneTestCase {protected IndexReader indexReader;private IndexReader closeIndexReader;private Random rand;-+ private Directory directory;+public TestPayloadSpans(String s) {super(s);}@@ -115,7 +117,7 @@ public class TestPayloadSpans extends LuceneTestCase {- MockRAMDirectory directory = new MockRAMDirectory();+ MockRAMDirectory directory = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, directory,newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new PayloadAnalyzer()).setSimilarity(similarity));@@ -128,6 +130,7 @@ public class TestPayloadSpans extends LuceneTestCase {checkSpans(snq.getSpans(SlowMultiReaderWrapper.wrap(reader)), 1,new int[]{2});reader.close();+ directory.close();}public void testNestedSpans() throws Exception {@@ -184,6 +187,7 @@ public class TestPayloadSpans extends LuceneTestCase {assertTrue("spans is null and it shouldn't be", spans != null);checkSpans(spans, 2, new int[]{3,3});closeIndexReader.close();+ directory.close();}public void testFirstClauseWithoutPayload() throws Exception {@@ -215,6 +219,7 @@ public class TestPayloadSpans extends LuceneTestCase {assertTrue("spans is null and it shouldn't be", spans != null);checkSpans(spans, 1, new int[]{3});closeIndexReader.close();+ directory.close();}public void testHeavilyNestedSpanQuery() throws Exception {@@ -251,11 +256,12 @@ public class TestPayloadSpans extends LuceneTestCase {assertTrue("spans is null and it shouldn't be", spans != null);checkSpans(spans, 2, new int[]{8, 8});closeIndexReader.close();+ directory.close();}public void testShrinkToAfterShortestMatch() throws CorruptIndexException,LockObtainFailedException, IOException {- MockRAMDirectory directory = new MockRAMDirectory();+ MockRAMDirectory directory = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, directory,newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new TestPayloadAnalyzer()));@@ -288,11 +294,12 @@ public class TestPayloadSpans extends LuceneTestCase {assertTrue(payloadSet.contains("a:Noise:10"));assertTrue(payloadSet.contains("k:Noise:11"));reader.close();+ directory.close();}public void testShrinkToAfterShortestMatch2() throws CorruptIndexException,LockObtainFailedException, IOException {- MockRAMDirectory directory = new MockRAMDirectory();+ MockRAMDirectory directory = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, directory,newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new TestPayloadAnalyzer()));@@ -323,11 +330,12 @@ public class TestPayloadSpans extends LuceneTestCase {assertTrue(payloadSet.contains("a:Noise:10"));assertTrue(payloadSet.contains("k:Noise:11"));reader.close();+ directory.close();}public void testShrinkToAfterShortestMatch3() throws CorruptIndexException,LockObtainFailedException, IOException {- MockRAMDirectory directory = new MockRAMDirectory();+ MockRAMDirectory directory = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, directory,newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new TestPayloadAnalyzer()));@@ -364,10 +372,11 @@ public class TestPayloadSpans extends LuceneTestCase {assertTrue(payloadSet.contains("a:Noise:10"));assertTrue(payloadSet.contains("k:Noise:11"));reader.close();+ directory.close();}public void testPayloadSpanUtil() throws Exception {- MockRAMDirectory directory = new MockRAMDirectory();+ MockRAMDirectory directory = newDirectory(rand);RandomIndexWriter writer = new RandomIndexWriter(rand, directory,newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new PayloadAnalyzer()).setSimilarity(similarity));@@ -389,6 +398,7 @@ public class TestPayloadSpans extends LuceneTestCase {System.out.println(new String(bytes));}reader.close();+ directory.close();}private void checkSpans(Spans spans, int expectedNumSpans, int expectedNumPayloads,@@ -425,7 +435,7 @@ public class TestPayloadSpans extends LuceneTestCase {}private IndexSearcher getSearcher() throws Exception {- MockRAMDirectory directory = new MockRAMDirectory();+ directory = newDirectory(rand);String[] docs = new String[]{"xx rr yy mm pp","xx yy mm rr pp", "nopayload qq ss pp np", "one two three four five six seven eight nine ten eleven", "nine one two three four five six seven eight eleven ten"};RandomIndexWriter writer = new RandomIndexWriter(rand, directory,newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new PayloadAnalyzer()).setSimilarity(similarity));diff --git a/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java b/lucene/src/test/org/apache/lucene/search/spans/TestSpans.javaindex b542f744e1c..815db97d5e3 100644--- a/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java+++ b/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java@@ -27,7 +27,6 @@ import org.apache.lucene.search.Scorer;import org.apache.lucene.search.TermQuery;import org.apache.lucene.search.Searcher;import org.apache.lucene.store.Directory;-import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.index.IndexWriter;import org.apache.lucene.index.IndexReader;@@ -39,19 +38,22 @@ import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.lucene.util.LuceneTestCase;import java.io.IOException;+import java.util.Random;public class TestSpans extends LuceneTestCase {private IndexSearcher searcher;private IndexReader reader;private Directory directory;-+ private Random random;+public static final String field = "field";@Overrideprotected void setUp() throws Exception {super.setUp();- directory = new MockRAMDirectory();- RandomIndexWriter writer= new RandomIndexWriter(newRandom(), directory);+ random = newRandom();+ directory = newDirectory(random);+ RandomIndexWriter writer= new RandomIndexWriter(random, directory);for (int i = 0; i < docFields.length; i++) {Document doc = new Document();doc.add(new Field(field, docFields[i], Field.Store.YES, Field.Index.ANALYZED));@@ -461,7 +463,7 @@ public class TestSpans extends LuceneTestCase {// LUCENE-1404public void testNPESpanQuery() throws Throwable {- final Directory dir = new MockRAMDirectory();+ final Directory dir = newDirectory(random);final IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));diff --git a/lucene/src/test/org/apache/lucene/search/spans/TestSpansAdvanced.java b/lucene/src/test/org/apache/lucene/search/spans/TestSpansAdvanced.javaindex 1a28a2555c0..21cac58aa69 100644--- a/lucene/src/test/org/apache/lucene/search/spans/TestSpansAdvanced.java+++ b/lucene/src/test/org/apache/lucene/search/spans/TestSpansAdvanced.java@@ -59,7 +59,7 @@ public class TestSpansAdvanced extends LuceneTestCase {super.setUp();random = newRandom();// create test index- mDirectory = new MockRAMDirectory();+ mDirectory = newDirectory(random);final RandomIndexWriter writer = new RandomIndexWriter(random,mDirectory, new MockAnalyzer(MockTokenizer.SIMPLE, true,MockTokenFilter.ENGLISH_STOPSET, true));diff --git a/lucene/src/test/org/apache/lucene/store/MockRAMDirectory.java b/lucene/src/test/org/apache/lucene/store/MockRAMDirectory.javaindex 64bbc503604..1853caba44c 100644--- a/lucene/src/test/org/apache/lucene/store/MockRAMDirectory.java+++ b/lucene/src/test/org/apache/lucene/store/MockRAMDirectory.java@@ -281,8 +281,15 @@ public class MockRAMDirectory extends RAMDirectory {// super() does not throw IOException currently:throw new RuntimeException("MockRAMDirectory: cannot close: there are still open files: " + openFiles);}+ open = false;}+ boolean open = true;++ public synchronized boolean isOpen() {+ return open;+ }+/*** Objects that represent fail-able conditions. Objects of a derived* class are created and registered with the mock directory. Afterdiff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.javaindex 371bad0902f..6b6eeacea37 100644--- a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java+++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java@@ -21,8 +21,10 @@ import java.io.File;import java.io.PrintStream;import java.io.IOException;import java.util.Arrays;+import java.util.IdentityHashMap;import java.util.Iterator;import java.util.Locale;+import java.util.Map;import java.util.Random;import java.util.ArrayList;import java.util.List;@@ -39,6 +41,8 @@ import org.apache.lucene.index.codecs.Codec;import org.apache.lucene.search.BooleanQuery;import org.apache.lucene.search.FieldCache;import org.apache.lucene.search.FieldCache.CacheEntry;+import org.apache.lucene.store.Directory;+import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;/**@@ -97,7 +101,9 @@ public abstract class LuceneTestCase extends TestCase {private Locale savedLocale;private TimeZone timeZone;private TimeZone savedTimeZone;-++ private Map<MockRAMDirectory,StackTraceElement[]> stores;+/** Used to track if setUp and tearDown are called correctly from subclasses */private boolean setup;@@ -125,6 +131,7 @@ public abstract class LuceneTestCase extends TestCase {super.setUp();assertFalse("ensure your tearDown() calls super.tearDown()!!!", setup);setup = true;+ stores = new IdentityHashMap<MockRAMDirectory,StackTraceElement[]>();savedUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {public void uncaughtException(Thread t, Throwable e) {@@ -203,6 +210,15 @@ public abstract class LuceneTestCase extends TestCase {purgeFieldCache(FieldCache.DEFAULT);}+ // now look for unclosed resources+ for (MockRAMDirectory d : stores.keySet()) {+ if (d.isOpen()) {+ StackTraceElement elements[] = stores.get(d);+ StackTraceElement element = (elements.length > 1) ? elements[1] : null;+ fail("directory of testcase " + getName() + " was not closed, opened from: " + element);+ }+ }+ stores = null;super.tearDown();}@@ -313,6 +329,20 @@ public abstract class LuceneTestCase extends TestCase {return LuceneTestCaseJ4.newIndexWriterConfig(r, v, a);}+ public MockRAMDirectory newDirectory(Random r) throws IOException {+ StackTraceElement[] stack = new Exception().getStackTrace();+ MockRAMDirectory dir = new MockRAMDirectory();+ stores.put(dir, stack);+ return dir;+ }++ public MockRAMDirectory newDirectory(Random r, Directory d) throws IOException {+ StackTraceElement[] stack = new Exception().getStackTrace();+ MockRAMDirectory dir = new MockRAMDirectory(d);+ stores.put(dir, stack);+ return dir;+ }+/** Gets a resource from the classpath as {@link File}. This method should only be used,* if a real file is needed. To get a stream, code should prefer* {@link Class#getResourceAsStream} using {@code this.getClass()}.diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.javaindex 3ef79d5a4f3..891807c21ef 100644--- a/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java+++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java@@ -26,6 +26,8 @@ import org.apache.lucene.index.SerialMergeScheduler;import org.apache.lucene.search.BooleanQuery;import org.apache.lucene.search.FieldCache;import org.apache.lucene.search.FieldCache.CacheEntry;+import org.apache.lucene.store.Directory;+import org.apache.lucene.store.MockRAMDirectory;import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;import org.apache.lucene.index.codecs.CodecProvider;import org.apache.lucene.index.codecs.Codec;@@ -56,6 +58,7 @@ import java.io.File;import java.io.PrintStream;import java.io.IOException;import java.util.Arrays;+import java.util.IdentityHashMap;import java.util.Iterator;import java.util.Locale;import java.util.Random;@@ -187,6 +190,8 @@ public class LuceneTestCaseJ4 {private static TimeZone timeZone;private static TimeZone savedTimeZone;+ private static Map<MockRAMDirectory,StackTraceElement[]> stores;+private static final String[] TEST_CODECS = new String[] {"MockSep", "MockFixedIntBlock", "MockVariableIntBlock"};private static void swapCodec(Codec c) {@@ -274,6 +279,7 @@ public class LuceneTestCaseJ4 {@BeforeClasspublic static void beforeClassLuceneTestCaseJ4() {+ stores = Collections.synchronizedMap(new IdentityHashMap<MockRAMDirectory,StackTraceElement[]>());codec = installTestCodecs();savedLocale = Locale.getDefault();locale = TEST_LOCALE.equals("random") ? randomLocale(seedRnd) : localeForName(TEST_LOCALE);@@ -288,6 +294,15 @@ public class LuceneTestCaseJ4 {removeTestCodecs(codec);Locale.setDefault(savedLocale);TimeZone.setDefault(savedTimeZone);+ // now look for unclosed resources+ for (MockRAMDirectory d : stores.keySet()) {+ if (d.isOpen()) {+ StackTraceElement elements[] = stores.get(d);+ StackTraceElement element = (elements.length > 1) ? elements[1] : null;+ fail("directory of test was not closed, opened from: " + element);+ }+ }+ stores = null;}// This is how we get control when errors occur.@@ -567,6 +582,20 @@ public class LuceneTestCaseJ4 {return c;}+ public static MockRAMDirectory newDirectory(Random r) throws IOException {+ StackTraceElement[] stack = new Exception().getStackTrace();+ MockRAMDirectory dir = new MockRAMDirectory();+ stores.put(dir, stack);+ return dir;+ }++ public static MockRAMDirectory newDirectory(Random r, Directory d) throws IOException {+ StackTraceElement[] stack = new Exception().getStackTrace();+ MockRAMDirectory dir = new MockRAMDirectory(d);+ stores.put(dir, stack);+ return dir;+ }+/** return a random Locale from the available locales on the system */public static Locale randomLocale(Random random) {Locale locales[] = Locale.getAvailableLocales();diff --git a/lucene/src/test/org/apache/lucene/util/TestFieldCacheSanityChecker.java b/lucene/src/test/org/apache/lucene/util/TestFieldCacheSanityChecker.javaindex 07f92e97590..8daa9d5488d 100644--- a/lucene/src/test/org/apache/lucene/util/TestFieldCacheSanityChecker.java+++ b/lucene/src/test/org/apache/lucene/util/TestFieldCacheSanityChecker.java@@ -29,24 +29,25 @@ import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;import org.apache.lucene.util.FieldCacheSanityChecker.InsanityType;import java.io.IOException;+import java.util.Random;public class TestFieldCacheSanityChecker extends LuceneTestCase {protected IndexReader readerA;protected IndexReader readerB;protected IndexReader readerX;-+ protected MockRAMDirectory dirA, dirB;private static final int NUM_DOCS = 1000;@Overrideprotected void setUp() throws Exception {super.setUp();+ Random random = newRandom();+ dirA = newDirectory(random);+ dirB = newDirectory(random);- MockRAMDirectory dirA = new MockRAMDirectory();- MockRAMDirectory dirB = new MockRAMDirectory();-- IndexWriter wA = new IndexWriter(dirA, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));- IndexWriter wB = new IndexWriter(dirB, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer()));+ IndexWriter wA = new IndexWriter(dirA, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));+ IndexWriter wB = new IndexWriter(dirB, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()));long theLong = Long.MAX_VALUE;double theDouble = Double.MAX_VALUE;@@ -80,6 +81,8 @@ public class TestFieldCacheSanityChecker extends LuceneTestCase {readerA.close();readerB.close();readerX.close();+ dirA.close();+ dirB.close();super.tearDown();}diff --git a/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java b/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.javaindex 97759e3c416..55e9f07a541 100644--- a/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java+++ b/lucene/src/test/org/apache/lucene/util/packed/TestPackedInts.java@@ -56,7 +56,7 @@ public class TestPackedInts extends LuceneTestCase {long ceil = 2;for(int nbits=1;nbits<63;nbits++) {final int valueCount = 100+rnd.nextInt(500);- final Directory d = new MockRAMDirectory();+ final Directory d = newDirectory(rnd);IndexOutput out = d.createOutput("out.bin");PackedInts.Writer w = PackedInts.getWriter(@@ -95,6 +95,7 @@ public class TestPackedInts extends LuceneTestCase {assertEquals(fp, in.getFilePointer());in.close();ceil *= 2;+ d.close();}}}@@ -208,7 +209,7 @@ public class TestPackedInts extends LuceneTestCase {}public void testSingleValue() throws Exception {- Directory dir = new MockRAMDirectory();+ Directory dir = newDirectory(newRandom());IndexOutput out = dir.createOutput("out");PackedInts.Writer w = PackedInts.getWriter(out, 1, 8);w.add(17);diff --git a/modules/analysis/common/src/test/org/apache/lucene/analysis/sinks/TestTeeSinkTokenFilter.java b/modules/analysis/common/src/test/org/apache/lucene/analysis/sinks/TestTeeSinkTokenFilter.javaindex 57e7831761a..e921de4af33 100644--- a/modules/analysis/common/src/test/org/apache/lucene/analysis/sinks/TestTeeSinkTokenFilter.java+++ b/modules/analysis/common/src/test/org/apache/lucene/analysis/sinks/TestTeeSinkTokenFilter.java@@ -40,6 +40,7 @@ import org.apache.lucene.util.AttributeSource;import org.apache.lucene.util.English;import java.io.IOException;import java.io.StringReader;+import java.util.Random;/**@@ -92,9 +93,10 @@ public class TestTeeSinkTokenFilter extends BaseTokenStreamTestCase {// TODO: instead of testing it this way, we can test// with BaseTokenStreamTestCase now...public void testEndOffsetPositionWithTeeSinkTokenFilter() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();+ Random random = newRandom();+ MockRAMDirectory dir = newDirectory(random);Analyzer analyzer = new WhitespaceAnalyzer(TEST_VERSION_CURRENT);- IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));+ IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, analyzer));Document doc = new Document();TeeSinkTokenFilter tee = new TeeSinkTokenFilter(analyzer.tokenStream("field", new StringReader("abcd ")));TokenStream sink = tee.newSinkTokenStream();diff --git a/solr/src/test/org/apache/solr/search/TestSort.java b/solr/src/test/org/apache/solr/search/TestSort.javaindex 3851c5275e5..c8067869a50 100755--- a/solr/src/test/org/apache/solr/search/TestSort.java+++ b/solr/src/test/org/apache/solr/search/TestSort.java@@ -48,7 +48,8 @@ public class TestSort extends AbstractSolrTestCase {}public void testSort() throws Exception {- MockRAMDirectory dir = new MockRAMDirectory();+ Random random = newRandom();+ MockRAMDirectory dir = newDirectory(random);Document smallDoc = new Document();// Field id = new Field("id","0", Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS);Field f = new Field("f","0", Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS);@@ -179,6 +180,8 @@ public class TestSort extends AbstractSolrTestCase {assertEquals(id, collectedDocs.get(j).doc);}}+ searcher.close();+ dir.close();}}