Index: modules/facet/src/test/org/apache/lucene/facet/FacetTestUtils.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/FacetTestUtils.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/FacetTestUtils.java (working copy) @@ -14,12 +14,12 @@ 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.search.Collector; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.TopScoreDocCollector; import org.apache.lucene.store.Directory; -import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.search.MultiCollector; import org.apache.lucene.util.LuceneTestCase; @@ -55,14 +55,21 @@ public class FacetTestUtils { - public static Directory[][] createIndexTaxonomyDirs(int number) { + public static Directory[][] createIndexTaxonomyDirs(int number) throws IOException { Directory[][] dirs = new Directory[number][2]; for (int i = 0; i < number; i++) { - dirs[i][0] = new RAMDirectory(); - dirs[i][1] = new RAMDirectory(); + dirs[i][0] = LuceneTestCase.newDirectory(); + dirs[i][1] = LuceneTestCase.newDirectory(); } return dirs; } + + public static void closeIndexTaxonomyDirs(Directory[][] dirs, int number) throws IOException { + for (int i = 0; i < number; i++) { + dirs[i][0].close(); + dirs[i][1].close(); + } + } public static IndexTaxonomyReaderPair[] createIndexTaxonomyReaderPair( Directory[][] dirs) throws IOException { @@ -122,7 +129,7 @@ return collectors; } - public static void add(FacetIndexingParams iParams, IndexWriter iw, + public static void add(FacetIndexingParams iParams, RandomIndexWriter iw, TaxonomyWriter tw, String... strings) throws IOException, CorruptIndexException { ArrayList cps = new ArrayList(); Index: modules/facet/src/test/org/apache/lucene/facet/search/params/MultiIteratorsPerCLParamsTest.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/params/MultiIteratorsPerCLParamsTest.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/search/params/MultiIteratorsPerCLParamsTest.java (working copy) @@ -4,14 +4,13 @@ import java.util.Arrays; import java.util.List; -import org.apache.lucene.analysis.core.KeywordAnalyzer; +import org.apache.lucene.analysis.MockAnalyzer; +import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; 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.RandomIndexWriter; import org.apache.lucene.store.Directory; -import org.apache.lucene.store.RAMDirectory; import org.junit.Test; import org.apache.lucene.util.LuceneTestCase; @@ -90,8 +89,8 @@ // FacetRequest's dimension CategoryListParams clp = new CategoryListParams(); FacetIndexingParams iParams = new DefaultFacetIndexingParams(clp); - Directory indexDir = new RAMDirectory(); - Directory taxoDir = new RAMDirectory(); + Directory indexDir = newDirectory(); + Directory taxoDir = newDirectory(); populateIndex(iParams, indexDir, taxoDir); TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir); @@ -122,6 +121,10 @@ countForbiddenDimension = null; validateFacetedSearch(iParams, taxo, reader, clCache, allDocs, new String[] { "author", "date" }, new int[] { 5, 5 }, new int[] { 5, 2 }); + taxo.close(); + reader.close(); + indexDir.close(); + taxoDir.close(); } private void validateFacetedSearch(FacetIndexingParams iParams, @@ -163,7 +166,8 @@ private void populateIndex(FacetIndexingParams iParams, Directory indexDir, Directory taxoDir) throws Exception { - IndexWriter writer = new IndexWriter(indexDir, new IndexWriterConfig(TEST_VERSION_CURRENT, new KeywordAnalyzer())); + RandomIndexWriter writer = new RandomIndexWriter(random, indexDir, + newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.KEYWORD, false))); TaxonomyWriter taxoWriter = new LuceneTaxonomyWriter(taxoDir); for (CategoryPath[] categories : perDocCategories) { Index: modules/facet/src/test/org/apache/lucene/facet/search/params/FacetRequestTest.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/params/FacetRequestTest.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/search/params/FacetRequestTest.java (working copy) @@ -2,7 +2,7 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.store.RAMDirectory; +import org.apache.lucene.store.Directory; import org.junit.Test; import org.apache.lucene.util.LuceneTestCase; @@ -53,8 +53,8 @@ @Test public void testGetFacetResultHandlerDifferentTaxonomy() throws Exception { FacetRequest fr = new CountFacetRequest(new CategoryPath("a"), 10); - RAMDirectory dir1 = new RAMDirectory(); - RAMDirectory dir2 = new RAMDirectory(); + Directory dir1 = newDirectory(); + Directory dir2 = newDirectory(); // create empty indexes, so that LTR ctor won't complain about a missing index. new IndexWriter(dir1, new IndexWriterConfig(TEST_VERSION_CURRENT, null)).close(); new IndexWriter(dir2, new IndexWriterConfig(TEST_VERSION_CURRENT, null)).close(); @@ -63,6 +63,10 @@ FacetResultsHandler frh1 = fr.createFacetResultsHandler(tr1); FacetResultsHandler frh2 = fr.createFacetResultsHandler(tr2); assertTrue("should not return the same FacetResultHandler instance for different TaxonomyReader instances", frh1 != frh2); + tr1.close(); + tr2.close(); + dir1.close(); + dir2.close(); } @Test @@ -70,13 +74,15 @@ // Tests that after a FRH is created by FR, changes to FR are not reflected // in the FRH. FacetRequest fr = new CountFacetRequest(new CategoryPath("a"), 10); - RAMDirectory dir = new RAMDirectory(); + Directory dir = newDirectory(); // create empty indexes, so that LTR ctor won't complain about a missing index. new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null)).close(); TaxonomyReader tr = new LuceneTaxonomyReader(dir); FacetResultsHandler frh = fr.createFacetResultsHandler(tr); fr.setDepth(10); assertEquals(FacetRequest.DEFAULT_DEPTH, frh.getFacetRequest().getDepth()); + tr.close(); + dir.close(); } @Test Index: modules/facet/src/test/org/apache/lucene/facet/search/params/FacetSearchParamsTest.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/params/FacetSearchParamsTest.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/search/params/FacetSearchParamsTest.java (working copy) @@ -1,6 +1,6 @@ package org.apache.lucene.facet.search.params; -import org.apache.lucene.store.RAMDirectory; +import org.apache.lucene.store.Directory; import org.junit.Test; import org.apache.lucene.util.LuceneTestCase; @@ -36,11 +36,13 @@ FacetSearchParams fsp = new FacetSearchParams(); assertEquals("unexpected default facet indexing params class", DefaultFacetIndexingParams.class.getName(), fsp.getFacetIndexingParams().getClass().getName()); assertEquals("no facet requests should be added by default", 0, fsp.getFacetRequests().size()); - RAMDirectory dir = new RAMDirectory(); + Directory dir = newDirectory(); new LuceneTaxonomyWriter(dir).close(); TaxonomyReader tr = new LuceneTaxonomyReader(dir); assertEquals("unexpected partition offset for 0 categories", 1, PartitionsUtils.partitionOffset(fsp, 1, tr)); assertEquals("unexpected partition size for 0 categories", 1, PartitionsUtils.partitionSize(fsp,tr)); + tr.close(); + dir.close(); } @Test @@ -53,7 +55,7 @@ @Test public void testPartitionSizeWithCategories() throws Exception { FacetSearchParams fsp = new FacetSearchParams(); - RAMDirectory dir = new RAMDirectory(); + Directory dir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(dir); tw.addCategory(new CategoryPath("a")); tw.commit(); @@ -61,6 +63,8 @@ TaxonomyReader tr = new LuceneTaxonomyReader(dir); assertEquals("unexpected partition offset for 1 categories", 2, PartitionsUtils.partitionOffset(fsp, 1, tr)); assertEquals("unexpected partition size for 1 categories", 2, PartitionsUtils.partitionSize(fsp,tr)); + tr.close(); + dir.close(); } @Test Index: modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java (working copy) @@ -5,13 +5,15 @@ import java.util.ArrayList; import java.util.List; -import org.apache.lucene.analysis.core.WhitespaceAnalyzer; +import org.apache.lucene.analysis.MockAnalyzer; +import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; 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.store.Directory; +import org.apache.lucene.store.MockDirectoryWrapper; import org.junit.Before; import org.junit.Test; @@ -130,17 +132,20 @@ InterruptedException { TFC.setCacheSize(cacheSize); SlowRAMDirectory slowIndexDir = new SlowRAMDirectory(-1, random); + MockDirectoryWrapper indexDir = new MockDirectoryWrapper(random, slowIndexDir); SlowRAMDirectory slowTaxoDir = new SlowRAMDirectory(-1, random); + MockDirectoryWrapper taxoDir = new MockDirectoryWrapper(random, slowTaxoDir); + // Index documents without the "slowness" - MultiCLIndexer.index(slowIndexDir, slowTaxoDir); + MultiCLIndexer.index(indexDir, taxoDir); slowIndexDir.setSleepMillis(sleepMillis); slowTaxoDir.setSleepMillis(sleepMillis); // Open the slow readers - IndexReader slowIndexReader = IndexReader.open(slowIndexDir); - TaxonomyReader slowTaxoReader = new LuceneTaxonomyReader(slowTaxoDir); + IndexReader slowIndexReader = IndexReader.open(indexDir); + TaxonomyReader slowTaxoReader = new LuceneTaxonomyReader(taxoDir); // Class to perform search and return results as threads class Multi extends Thread { @@ -221,6 +226,8 @@ // we're done, close the index reader and the taxonomy. slowIndexReader.close(); slowTaxoReader.close(); + indexDir.close(); + taxoDir.close(); } /** @@ -321,6 +328,7 @@ readers[0].close(); r2.close(); outputFile.delete(); + FacetTestUtils.closeIndexTaxonomyDirs(dirs, 1); } private int assertReadFromDisc(TotalFacetCounts totalCounts, int prevGen, String errMsg) { @@ -384,6 +392,9 @@ readers[0].indexReader, readers[0].taxReader, iParams, null); assertReadFromDisc(totalCounts, 0, "after reading from disk."); outputFile.delete(); + writers[0].close(); + readers[0].close(); + FacetTestUtils.closeIndexTaxonomyDirs(dirs, 1); } /** @@ -397,7 +408,7 @@ // Write index using 'normal' directories IndexWriter w = new IndexWriter(indexDir, new IndexWriterConfig( - TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))); + TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); LuceneTaxonomyWriter tw = new LuceneTaxonomyWriter(taxoDir); DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams(); // Add documents and facets @@ -508,8 +519,11 @@ assertTrue("with cache of size 2 res no. 1 should come from cache", totalCounts1 == TFC.getTotalCounts(readers[1].indexReader, readers[1].taxReader, iParams, null)); + writers[0].close(); + writers[1].close(); readers[0].close(); readers[1].close(); + FacetTestUtils.closeIndexTaxonomyDirs(dirs, 2); } } Index: modules/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java (working copy) @@ -4,14 +4,15 @@ import java.util.Iterator; import java.util.List; -import org.apache.lucene.analysis.core.WhitespaceAnalyzer; +import org.apache.lucene.analysis.MockAnalyzer; +import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.MultiFields; import org.apache.lucene.index.IndexWriterConfig.OpenMode; +import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.IndexSearcher; @@ -62,8 +63,8 @@ public void testDefault() throws Exception { Directory[][] dirs = getDirs(); // create and open an index writer - IndexWriter iw = new IndexWriter(dirs[0][0], new IndexWriterConfig( - TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))); + RandomIndexWriter iw = new RandomIndexWriter(random, dirs[0][0], newIndexWriterConfig( + TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); // create and open a taxonomy writer TaxonomyWriter tw = new LuceneTaxonomyWriter(dirs[0][1], OpenMode.CREATE); @@ -74,15 +75,14 @@ seedIndex(iw, tw, iParams); - iw.commit(); + IndexReader ir = iw.getReader(); tw.commit(); // prepare index reader and taxonomy. TaxonomyReader tr = new LuceneTaxonomyReader(dirs[0][1]); - IndexReader ir = IndexReader.open(dirs[0][0]); // prepare searcher to search against - IndexSearcher searcher = new IndexSearcher(ir); + IndexSearcher searcher = newSearcher(ir); FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher); @@ -98,14 +98,15 @@ searcher.close(); iw.close(); tw.close(); + FacetTestUtils.closeIndexTaxonomyDirs(dirs, 1); } @Test public void testCustom() throws Exception { Directory[][] dirs = getDirs(); // create and open an index writer - IndexWriter iw = new IndexWriter(dirs[0][0], new IndexWriterConfig( - TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))); + RandomIndexWriter iw = new RandomIndexWriter(random, dirs[0][0], newIndexWriterConfig( + TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); // create and open a taxonomy writer TaxonomyWriter tw = new LuceneTaxonomyWriter(dirs[0][1], OpenMode.CREATE); @@ -115,15 +116,14 @@ new CategoryListParams(new Term("$author", "Authors"))); seedIndex(iw, tw, iParams); - iw.commit(); + IndexReader ir = iw.getReader(); tw.commit(); // prepare index reader and taxonomy. TaxonomyReader tr = new LuceneTaxonomyReader(dirs[0][1]); - IndexReader ir = IndexReader.open(dirs[0][0]); // prepare searcher to search against - IndexSearcher searcher = new IndexSearcher(ir); + IndexSearcher searcher = newSearcher(ir); FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher); @@ -139,14 +139,15 @@ searcher.close(); iw.close(); tw.close(); + FacetTestUtils.closeIndexTaxonomyDirs(dirs, 1); } @Test public void testTwoCustomsSameField() throws Exception { Directory[][] dirs = getDirs(); // create and open an index writer - IndexWriter iw = new IndexWriter(dirs[0][0], new IndexWriterConfig( - TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))); + RandomIndexWriter iw = new RandomIndexWriter(random, dirs[0][0], newIndexWriterConfig( + TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); // create and open a taxonomy writer TaxonomyWriter tw = new LuceneTaxonomyWriter(dirs[0][1], OpenMode.CREATE); @@ -158,15 +159,14 @@ new CategoryListParams(new Term("$music", "Composers"))); seedIndex(iw, tw, iParams); - iw.commit(); + IndexReader ir = iw.getReader(); tw.commit(); // prepare index reader and taxonomy. TaxonomyReader tr = new LuceneTaxonomyReader(dirs[0][1]); - IndexReader ir = IndexReader.open(dirs[0][0]); // prepare searcher to search against - IndexSearcher searcher = new IndexSearcher(ir); + IndexSearcher searcher = newSearcher(ir); FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher); @@ -183,6 +183,7 @@ searcher.close(); iw.close(); tw.close(); + FacetTestUtils.closeIndexTaxonomyDirs(dirs, 1); } private void assertPostingListExists(String field, String text, IndexReader ir) throws IOException { @@ -194,8 +195,8 @@ public void testDifferentFieldsAndText() throws Exception { Directory[][] dirs = getDirs(); // create and open an index writer - IndexWriter iw = new IndexWriter(dirs[0][0], new IndexWriterConfig( - TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))); + RandomIndexWriter iw = new RandomIndexWriter(random, dirs[0][0], newIndexWriterConfig( + TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); // create and open a taxonomy writer TaxonomyWriter tw = new LuceneTaxonomyWriter(dirs[0][1], OpenMode.CREATE); @@ -206,15 +207,14 @@ new CategoryListParams(new Term("$composers", "Composers"))); seedIndex(iw, tw, iParams); - iw.commit(); + IndexReader ir = iw.getReader(); tw.commit(); // prepare index reader and taxonomy. TaxonomyReader tr = new LuceneTaxonomyReader(dirs[0][1]); - IndexReader ir = IndexReader.open(dirs[0][0]); // prepare searcher to search against - IndexSearcher searcher = new IndexSearcher(ir); + IndexSearcher searcher = newSearcher(ir); FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher); @@ -229,14 +229,15 @@ searcher.close(); iw.close(); tw.close(); + FacetTestUtils.closeIndexTaxonomyDirs(dirs, 1); } @Test public void testSomeSameSomeDifferent() throws Exception { Directory[][] dirs = getDirs(); // create and open an index writer - IndexWriter iw = new IndexWriter(dirs[0][0], new IndexWriterConfig( - TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))); + RandomIndexWriter iw = new RandomIndexWriter(random, dirs[0][0], newIndexWriterConfig( + TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); // create and open a taxonomy writer TaxonomyWriter tw = new LuceneTaxonomyWriter(dirs[0][1], OpenMode.CREATE); @@ -251,15 +252,14 @@ seedIndex(iw, tw, iParams); - iw.commit(); + IndexReader ir = iw.getReader(); tw.commit(); // prepare index reader and taxonomy. TaxonomyReader tr = new LuceneTaxonomyReader(dirs[0][1]); - IndexReader ir = IndexReader.open(dirs[0][0]); // prepare searcher to search against - IndexSearcher searcher = new IndexSearcher(ir); + IndexSearcher searcher = newSearcher(ir); FacetsCollector facetsCollector = performSearch(iParams, tr, ir, searcher); @@ -274,6 +274,7 @@ searcher.close(); iw.close(); tw.close(); + FacetTestUtils.closeIndexTaxonomyDirs(dirs, 1); } private Directory[][] getDirs() throws IOException { @@ -358,7 +359,7 @@ return facetsCollector; } - private void seedIndex(IndexWriter iw, TaxonomyWriter tw, + private void seedIndex(RandomIndexWriter iw, TaxonomyWriter tw, FacetIndexingParams iParams) throws IOException, CorruptIndexException { FacetTestUtils.add(iParams, iw, tw, "Author", "Mark Twain"); FacetTestUtils.add(iParams, iw, tw, "Author", "Stephen King"); Index: modules/facet/src/test/org/apache/lucene/facet/search/BaseTestTopK.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/BaseTestTopK.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/search/BaseTestTopK.java (working copy) @@ -6,7 +6,7 @@ import org.apache.lucene.DocumentBuilder.DocumentBuilderException; import org.apache.lucene.index.CorruptIndexException; -import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.facet.FacetTestBase; import org.apache.lucene.facet.index.params.FacetIndexingParams; @@ -48,7 +48,7 @@ private int nextInt; @Override - protected void populateIndex(IndexWriter iw, TaxonomyWriter taxo, + protected void populateIndex(RandomIndexWriter iw, TaxonomyWriter taxo, FacetIndexingParams iParams) throws IOException, DocumentBuilderException, CorruptIndexException { currDoc = -1; Index: modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java (working copy) @@ -108,6 +108,7 @@ ++partition; } readers[0].close(); + FacetTestUtils.closeIndexTaxonomyDirs(dirs, 1); tmpFile.delete(); } Index: modules/facet/src/test/org/apache/lucene/facet/search/CategoryListIteratorTest.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/CategoryListIteratorTest.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/search/CategoryListIteratorTest.java (working copy) @@ -1,22 +1,23 @@ package org.apache.lucene.facet.search; import java.io.IOException; +import java.io.Reader; import java.util.HashSet; import java.util.Set; -import org.apache.lucene.analysis.core.KeywordAnalyzer; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.MockAnalyzer; +import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; 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.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.Payload; +import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; -import org.apache.lucene.store.RAMDirectory; import org.junit.Test; import org.apache.lucene.util.LuceneTestCase; @@ -95,20 +96,20 @@ @Test public void testPayloadIntDecodingIterator() throws Exception { - Directory dir = new RAMDirectory(); + Directory dir = newDirectory(); DataTokenStream dts = new DataTokenStream("1",new SortingIntEncoder( new UniqueValuesIntEncoder(new DGapIntEncoder(new VInt8IntEncoder())))); - IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new KeywordAnalyzer())); + RandomIndexWriter writer = new RandomIndexWriter(random, dir, newIndexWriterConfig(TEST_VERSION_CURRENT, + new MockAnalyzer(random, MockTokenizer.KEYWORD, false))); for (int i = 0; i < data.length; i++) { dts.setIdx(i); Document doc = new Document(); doc.add(new Field("f", dts)); writer.addDocument(doc); } - writer.commit(); + IndexReader reader = writer.getReader(); writer.close(); - IndexReader reader = IndexReader.open(dir, true); CategoryListIterator cli = new PayloadIntDecodingIterator(reader, new Term( "f","1"), dts.encoder.createMatchingDecoder()); cli.init(); @@ -127,6 +128,7 @@ } assertEquals("Missing categories!",10,totalCategories); reader.close(); + dir.close(); } /** @@ -139,12 +141,22 @@ */ @Test public void testPayloadIteratorWithInvalidDoc() throws Exception { - Directory dir = new RAMDirectory(); + Directory dir = newDirectory(); DataTokenStream dts = new DataTokenStream("1",new SortingIntEncoder( new UniqueValuesIntEncoder(new DGapIntEncoder(new VInt8IntEncoder())))); DataTokenStream dts2 = new DataTokenStream("2",new SortingIntEncoder( new UniqueValuesIntEncoder(new DGapIntEncoder(new VInt8IntEncoder())))); - IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new KeywordAnalyzer())); + // this test requires that no payloads ever be randomly present! + final Analyzer noPayloadsAnalyzer = new Analyzer() { + @Override + public TokenStream tokenStream(String fieldName, Reader reader) { + return new MockTokenizer(reader, MockTokenizer.KEYWORD, false); + } + }; + // TODO: test is wired to LogMP... maybe its just the test that is sensitive to docids??? + // (if it gets TieredMP, it will fail) + RandomIndexWriter writer = new RandomIndexWriter(random, dir, + newIndexWriterConfig(TEST_VERSION_CURRENT, noPayloadsAnalyzer).setMergePolicy(newLogMergePolicy())); for (int i = 0; i < data.length; i++) { dts.setIdx(i); Document doc = new Document(); @@ -170,10 +182,9 @@ } - writer.commit(); + IndexReader reader = writer.getReader(); writer.close(); - IndexReader reader = IndexReader.open(dir, true); CategoryListIterator cli = new PayloadIntDecodingIterator(reader, new Term( "f","1"), dts.encoder.createMatchingDecoder()); cli.init(); @@ -202,6 +213,7 @@ // Ok.. went through the first 4 docs, now lets try the 6th doc (docid 5) assertFalse("Doc #6 (docid=5) should not have a payload!",cli.skipTo(5)); reader.close(); + dir.close(); } } Index: modules/facet/src/test/org/apache/lucene/facet/search/TestFacetsAccumulatorWithComplement.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/TestFacetsAccumulatorWithComplement.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/search/TestFacetsAccumulatorWithComplement.java (working copy) @@ -100,8 +100,6 @@ } private void doTestComplements() throws Exception { - assertTrue("Would like to test this with deletions!",indexReader.hasDeletions()); - assertTrue("Would like to test this with deletions!",indexReader.numDeletedDocs()>0); Query q = new MatchAllDocsQuery(); //new TermQuery(new Term(TEXT,"white")); if (VERBOSE) { System.out.println("Query: "+q); Index: modules/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java (working copy) @@ -4,22 +4,21 @@ import java.util.ArrayList; import java.util.List; -import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.Field.Index; import org.apache.lucene.document.Field.Store; import org.apache.lucene.document.Field.TermVector; import org.apache.lucene.index.CorruptIndexException; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriterConfig.OpenMode; +import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; import org.apache.lucene.store.Directory; -import org.apache.lucene.store.RAMDirectory; import org.junit.Test; import org.apache.lucene.util.LuceneTestCase; @@ -70,8 +69,8 @@ Integer.MAX_VALUE }; for (int partitionSize : partitionSizes) { - Directory iDir = new RAMDirectory(); - Directory tDir = new RAMDirectory(); + Directory iDir = newDirectory(); + Directory tDir = newDirectory(); if (VERBOSE) { System.out.println("Partition Size: " + partitionSize); @@ -85,9 +84,9 @@ } }; - IndexWriter iw = new IndexWriter(iDir, - new IndexWriterConfig(TEST_VERSION_CURRENT, - new StandardAnalyzer(TEST_VERSION_CURRENT)).setOpenMode(OpenMode.CREATE)); + RandomIndexWriter iw = new RandomIndexWriter(random, iDir, + newIndexWriterConfig(TEST_VERSION_CURRENT, + new MockAnalyzer(random)).setOpenMode(OpenMode.CREATE)); TaxonomyWriter tw = new LuceneTaxonomyWriter(tDir); prvt_add(iParams, iw, tw, "a", "b"); prvt_add(iParams, iw, tw, "a", "b", "1"); @@ -106,12 +105,12 @@ prvt_add(iParams, iw, tw, "a", "d"); prvt_add(iParams, iw, tw, "a", "e"); - iw.commit(); + IndexReader ir = iw.getReader(); iw.close(); tw.commit(); tw.close(); - IndexSearcher is = new IndexSearcher(iDir); + IndexSearcher is = newSearcher(ir); LuceneTaxonomyReader tr = new LuceneTaxonomyReader(tDir); // Get all of the documents and run the query, then do different @@ -320,11 +319,15 @@ assertFalse("Shouldn't have found anything for a FacetRequest " + "of a facet that doesn't exist in the index.", hasDoctor); assertEquals("Shouldn't have found more than seven request.", 7, facetResults.size()); + ir.close(); + tr.close(); + iDir.close(); + tDir.close(); } } - private void prvt_add(DefaultFacetIndexingParams iParams, IndexWriter iw, + private void prvt_add(DefaultFacetIndexingParams iParams, RandomIndexWriter iw, TaxonomyWriter tw, String... strings) throws IOException, CorruptIndexException { ArrayList cps = new ArrayList(); Index: modules/facet/src/test/org/apache/lucene/facet/search/TestScoredDocIdCollector.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/TestScoredDocIdCollector.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/search/TestScoredDocIdCollector.java (working copy) @@ -59,8 +59,6 @@ @Test public void testConstantScore() throws Exception { // test that constant score works well - assertTrue("Would like to test this with deletions!",indexReader.hasDeletions()); - assertTrue("Would like to test this with deletions!",indexReader.numDeletedDocs()>0); Query q = new TermQuery(new Term(CONTENT_FIELD, "white")); if (VERBOSE) { Index: modules/facet/src/test/org/apache/lucene/facet/search/sampling/BaseSampleTestTopK.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/sampling/BaseSampleTestTopK.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/search/sampling/BaseSampleTestTopK.java (working copy) @@ -101,6 +101,7 @@ } } } + closeAll(); } } Index: modules/facet/src/test/org/apache/lucene/facet/search/association/AssociationsFacetRequestTest.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/association/AssociationsFacetRequestTest.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/search/association/AssociationsFacetRequestTest.java (working copy) @@ -3,19 +3,18 @@ import java.util.List; 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.search.IndexSearcher; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.store.Directory; -import org.apache.lucene.store.RAMDirectory; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.analysis.core.KeywordAnalyzer; +import org.apache.lucene.analysis.MockAnalyzer; +import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; import org.apache.lucene.facet.enhancements.EnhancementsDocumentBuilder; import org.apache.lucene.facet.enhancements.association.AssociationEnhancement; @@ -53,8 +52,9 @@ /** Test for associations */ public class AssociationsFacetRequestTest extends LuceneTestCase { - private static Directory dir = new RAMDirectory(); - private static Directory taxoDir = new RAMDirectory(); + private static Directory dir; + private static IndexReader reader; + private static Directory taxoDir; private static final CategoryPath aint = new CategoryPath("int", "a"); private static final CategoryPath bint = new CategoryPath("int", "b"); @@ -63,8 +63,11 @@ @BeforeClass public static void beforeClassAssociationsFacetRequestTest() throws Exception { + dir = newDirectory(); + taxoDir = newDirectory(); // preparations - index, taxonomy, content - IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new KeywordAnalyzer())); + RandomIndexWriter writer = new RandomIndexWriter(random, dir, newIndexWriterConfig(TEST_VERSION_CURRENT, + new MockAnalyzer(random, MockTokenizer.KEYWORD, false))); TaxonomyWriter taxoWriter = new LuceneTaxonomyWriter(taxoDir); @@ -87,18 +90,22 @@ } taxoWriter.close(); + reader = writer.getReader(); writer.close(); } @AfterClass public static void afterClassAssociationsFacetRequestTest() throws Exception { + reader.close(); + reader = null; dir.close(); + dir = null; taxoDir.close(); + taxoDir = null; } @Test public void testIntSumAssociation() throws Exception { - IndexReader reader = IndexReader.open(dir, true); LuceneTaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir); // facet requests for two facets @@ -110,7 +117,8 @@ FacetsCollector fc = new FacetsCollector(fsp, reader, taxo); - new IndexSearcher(reader).search(q, fc); + IndexSearcher searcher = newSearcher(reader); + searcher.search(q, fc); List res = fc.getFacetResults(); assertNotNull("No results!",res); @@ -118,14 +126,12 @@ assertEquals("Wrong count for category 'a'!",200, (int) res.get(0).getFacetResultNode().getValue()); assertEquals("Wrong count for category 'b'!",150, (int) res.get(1).getFacetResultNode().getValue()); + searcher.close(); taxo.close(); - reader.close(); } @Test public void testFloatSumAssociation() throws Exception { - - IndexReader reader = IndexReader.open(dir, true); LuceneTaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir); // facet requests for two facets @@ -137,7 +143,8 @@ FacetsCollector fc = new FacetsCollector(fsp, reader, taxo); - new IndexSearcher(reader).search(q, fc); + IndexSearcher searcher = newSearcher(reader); + searcher.search(q, fc); List res = fc.getFacetResults(); assertNotNull("No results!",res); @@ -145,8 +152,8 @@ assertEquals("Wrong count for category 'a'!",50f, (float) res.get(0).getFacetResultNode().getValue(), 0.00001); assertEquals("Wrong count for category 'b'!",10f, (float) res.get(1).getFacetResultNode().getValue(), 0.00001); + searcher.close(); taxo.close(); - reader.close(); } @Test @@ -154,7 +161,6 @@ // Same category list cannot be aggregated by two different aggregators. If // you want to do that, you need to separate the categories into two // category list (you'll still have one association list). - IndexReader reader = IndexReader.open(dir, true); LuceneTaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir); // facet requests for two facets @@ -168,13 +174,16 @@ FacetsCollector fc = new FacetsCollector(fsp, reader, taxo); - new IndexSearcher(reader).search(q, fc); + IndexSearcher searcher = newSearcher(reader); + searcher.search(q, fc); try { fc.getFacetResults(); fail("different aggregators for same category list should not be supported"); } catch (RuntimeException e) { // ok - expected } + searcher.close(); + taxo.close(); } } Index: modules/facet/src/test/org/apache/lucene/facet/search/TestTopKResultsHandler.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/TestTopKResultsHandler.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/search/TestTopKResultsHandler.java (working copy) @@ -140,6 +140,7 @@ assertEquals(6.0, parentRes.getValue(), Double.MIN_VALUE); frn = resultNodesAsArray(parentRes); assertEquals(1.0, frn[0].getValue(), Double.MIN_VALUE); + closeAll(); } } @@ -234,6 +235,7 @@ assertEquals("Shouldn't have found anything for a FacetRequest " + "of a facet that doesn't exist in the index.", 0, facetResults.size()); + closeAll(); } } } Index: modules/facet/src/test/org/apache/lucene/facet/search/DrillDownTest.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/search/DrillDownTest.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/search/DrillDownTest.java (working copy) @@ -3,15 +3,16 @@ import java.io.IOException; import java.util.ArrayList; -import org.apache.lucene.analysis.core.KeywordAnalyzer; +import org.apache.lucene.analysis.MockAnalyzer; +import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.Field.Index; import org.apache.lucene.document.Field.Store; import org.apache.lucene.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.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; @@ -19,7 +20,6 @@ import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.Directory; import org.apache.lucene.store.LockObtainFailedException; -import org.apache.lucene.store.RAMDirectory; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -58,6 +58,8 @@ private FacetSearchParams nonDefaultParams; private static IndexReader reader; private static LuceneTaxonomyReader taxo; + private static Directory dir; + private static Directory taxoDir; public DrillDownTest() throws IOException { PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(); @@ -71,10 +73,11 @@ } @BeforeClass public static void createIndexes() throws CorruptIndexException, LockObtainFailedException, IOException { - Directory dir = new RAMDirectory(); - IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new KeywordAnalyzer())); + dir = newDirectory(); + RandomIndexWriter writer = new RandomIndexWriter(random, dir, + newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.KEYWORD, false))); - Directory taxoDir = new RAMDirectory(); + taxoDir = newDirectory(); TaxonomyWriter taxoWriter = new LuceneTaxonomyWriter(taxoDir); for (int i = 0; i < 100; i++) { @@ -98,10 +101,9 @@ } taxoWriter.close(); - writer.commit(); + reader = writer.getReader(); writer.close(); - reader = IndexReader.open(dir, true); taxo = new LuceneTaxonomyReader(taxoDir); } @@ -127,7 +129,7 @@ @Test public void testQuery() throws IOException { - IndexSearcher searcher = new IndexSearcher(reader); + IndexSearcher searcher = newSearcher(reader); // Making sure the query yields 25 documents with the facet "a" Query q = DrillDown.query(defaultParams, new CategoryPath("a")); @@ -155,7 +157,7 @@ @Test public void testQueryImplicitDefaultParams() throws IOException { - IndexSearcher searcher = new IndexSearcher(reader); + IndexSearcher searcher = newSearcher(reader); // Create the base query to start with Query q = DrillDown.query(defaultParams, new CategoryPath("a")); @@ -178,11 +180,16 @@ public static void closeIndexes() throws IOException { if (reader != null) { reader.close(); + reader = null; } if (taxo != null) { taxo.close(); + taxo = null; } + + dir.close(); + taxoDir.close(); } } Index: modules/facet/src/test/org/apache/lucene/facet/index/streaming/CategoryParentsStreamTest.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/index/streaming/CategoryParentsStreamTest.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/index/streaming/CategoryParentsStreamTest.java (working copy) @@ -3,7 +3,7 @@ import java.io.IOException; import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.store.RAMDirectory; +import org.apache.lucene.store.Directory; import org.junit.Test; import org.apache.lucene.facet.FacetException; @@ -49,8 +49,9 @@ */ @Test public void testStreamDefaultParams() throws IOException { + Directory directory = newDirectory(); TaxonomyWriter taxonomyWriter = new LuceneTaxonomyWriter( - new RAMDirectory()); + directory); CategoryParentsStream stream = new CategoryParentsStream( new CategoryAttributesStream(categoryContainer), taxonomyWriter, new DefaultFacetIndexingParams()); @@ -63,6 +64,7 @@ assertEquals("Wrong number of tokens", 6, nTokens); taxonomyWriter.close(); + directory.close(); } /** @@ -74,8 +76,9 @@ */ @Test public void testStreamNonTopLevelParams() throws IOException { + Directory directory = newDirectory(); final TaxonomyWriter taxonomyWriter = new LuceneTaxonomyWriter( - new RAMDirectory()); + directory); FacetIndexingParams indexingParams = new DefaultFacetIndexingParams() { @Override protected OrdinalPolicy fixedOrdinalPolicy() { @@ -102,6 +105,7 @@ assertEquals("Wrong number of tokens", 4, nTokens); taxonomyWriter.close(); + directory.close(); } /** @@ -113,7 +117,8 @@ */ @Test public void testNoRetainableAttributes() throws IOException, FacetException { - TaxonomyWriter taxonomyWriter = new LuceneTaxonomyWriter(new RAMDirectory()); + Directory directory = newDirectory(); + TaxonomyWriter taxonomyWriter = new LuceneTaxonomyWriter(directory); new CategoryParentsStream(new CategoryAttributesStream(categoryContainer), taxonomyWriter, new DefaultFacetIndexingParams()); @@ -133,6 +138,8 @@ } assertEquals("Wrong number of tokens with attributes", 1, nAttributes); + taxonomyWriter.close(); + directory.close(); } /** @@ -144,8 +151,9 @@ */ @Test public void testRetainableAttributes() throws IOException, FacetException { + Directory directory = newDirectory(); TaxonomyWriter taxonomyWriter = new LuceneTaxonomyWriter( - new RAMDirectory()); + directory); FacetIndexingParams indexingParams = new DefaultFacetIndexingParams(); new CategoryParentsStream(new CategoryAttributesStream( @@ -176,6 +184,7 @@ assertEquals("Wrong number of tokens with attributes", 3, nAttributes); taxonomyWriter.close(); + directory.close(); } private final class MyCategoryListTokenizer extends CategoryListTokenizer { Index: modules/facet/src/test/org/apache/lucene/facet/index/streaming/CategoryTokenizerTest.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/index/streaming/CategoryTokenizerTest.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/index/streaming/CategoryTokenizerTest.java (working copy) @@ -7,7 +7,7 @@ import java.util.Set; import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; -import org.apache.lucene.store.RAMDirectory; +import org.apache.lucene.store.Directory; import org.junit.Test; import org.apache.lucene.facet.index.CategoryContainerTestBase; @@ -46,8 +46,9 @@ */ @Test public void testTokensDefaultParams() throws IOException { + Directory directory = newDirectory(); TaxonomyWriter taxonomyWriter = new LuceneTaxonomyWriter( - new RAMDirectory()); + directory); DefaultFacetIndexingParams indexingParams = new DefaultFacetIndexingParams(); CategoryTokenizer tokenizer = new CategoryTokenizer( new CategoryAttributesStream(categoryContainer), @@ -73,6 +74,7 @@ assertEquals("Wrong number of tokens", 3, nTokens); taxonomyWriter.close(); + directory.close(); } /** @@ -83,8 +85,9 @@ */ @Test public void testLongCategoryPath() throws IOException { + Directory directory = newDirectory(); TaxonomyWriter taxonomyWriter = new LuceneTaxonomyWriter( - new RAMDirectory()); + directory); List longCategory = new ArrayList(); longCategory.add(new CategoryPath("one", "two", "three", "four", @@ -107,5 +110,6 @@ assertFalse("Unexpected token", tokenizer.incrementToken()); taxonomyWriter.close(); + directory.close(); } } Index: modules/facet/src/test/org/apache/lucene/facet/index/FacetsPayloadProcessorProviderTest.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/index/FacetsPayloadProcessorProviderTest.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/index/FacetsPayloadProcessorProviderTest.java (working copy) @@ -4,15 +4,15 @@ import java.util.ArrayList; import java.util.List; -import org.apache.lucene.analysis.core.WhitespaceAnalyzer; +import org.apache.lucene.analysis.MockAnalyzer; +import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; 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.search.IndexSearcher; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.store.Directory; -import org.apache.lucene.store.RAMDirectory; import org.junit.Test; import org.apache.lucene.util.LuceneTestCase; @@ -49,23 +49,27 @@ @Test public void testTaxonomyMergeUtils() throws Exception { - Directory dir = new RAMDirectory(); - Directory taxDir = new RAMDirectory(); + Directory dir = newDirectory(); + Directory taxDir = newDirectory(); buildIndexWithFacets(dir, taxDir, true); - Directory dir1 = new RAMDirectory(); - Directory taxDir1 = new RAMDirectory(); + Directory dir1 = newDirectory(); + Directory taxDir1 = newDirectory(); buildIndexWithFacets(dir1, taxDir1, false); TaxonomyMergeUtils.merge(dir, taxDir, dir1, taxDir1); verifyResults(dir1, taxDir1); + dir1.close(); + taxDir1.close(); + dir.close(); + taxDir.close(); } private void verifyResults(Directory dir, Directory taxDir) throws IOException { IndexReader reader1 = IndexReader.open(dir); LuceneTaxonomyReader taxReader = new LuceneTaxonomyReader(taxDir); - IndexSearcher searcher = new IndexSearcher(reader1); + IndexSearcher searcher = newSearcher(reader1); FacetSearchParams fsp = new FacetSearchParams(); fsp.addFacetRequest(new CountFacetRequest(new CategoryPath("tag"), NUM_DOCS)); FacetsCollector collector = new FacetsCollector(fsp, reader1, taxReader); @@ -81,11 +85,14 @@ } assertEquals(NUM_DOCS ,weight); } + reader1.close(); + taxReader.close(); } private void buildIndexWithFacets(Directory dir, Directory taxDir, boolean asc) throws IOException { - IndexWriterConfig config = new IndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)); - IndexWriter writer = new IndexWriter(dir, config); + IndexWriterConfig config = newIndexWriterConfig(TEST_VERSION_CURRENT, + new MockAnalyzer(random, MockTokenizer.WHITESPACE, false)); + RandomIndexWriter writer = new RandomIndexWriter(random, dir, config); LuceneTaxonomyWriter taxonomyWriter = new LuceneTaxonomyWriter(taxDir); for (int i = 1; i <= NUM_DOCS; i++) { Index: modules/facet/src/test/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicyTest.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicyTest.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicyTest.java (working copy) @@ -1,6 +1,6 @@ package org.apache.lucene.facet.index.categorypolicy; -import org.apache.lucene.store.RAMDirectory; +import org.apache.lucene.store.Directory; import org.junit.Test; import org.apache.lucene.util.LuceneTestCase; @@ -46,8 +46,9 @@ @Test public void testNonTopLevelOrdinalPolicy() throws Exception { + Directory dir = newDirectory(); TaxonomyWriter taxonomy = null; - taxonomy = new LuceneTaxonomyWriter(new RAMDirectory()); + taxonomy = new LuceneTaxonomyWriter(dir); int[] topLevelOrdinals = new int[10]; String[] topLevelStrings = new String[10]; @@ -85,6 +86,8 @@ // check illegal ordinal assertFalse("Should not add illegal ordinal", ordinalPolicy.shouldAdd(100000)); + taxonomy.close(); + dir.close(); } } Index: modules/facet/src/test/org/apache/lucene/facet/index/categorypolicy/PathPolicyTest.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/index/categorypolicy/PathPolicyTest.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/index/categorypolicy/PathPolicyTest.java (working copy) @@ -1,6 +1,6 @@ package org.apache.lucene.facet.index.categorypolicy; -import org.apache.lucene.store.RAMDirectory; +import org.apache.lucene.store.Directory; import org.junit.Test; import org.apache.lucene.util.LuceneTestCase; @@ -52,8 +52,9 @@ @Test public void testNonTopLevelPathPolicy() throws Exception { + Directory dir = newDirectory(); TaxonomyWriter taxonomy = null; - taxonomy = new LuceneTaxonomyWriter(new RAMDirectory()); + taxonomy = new LuceneTaxonomyWriter(dir); CategoryPath[] topLevelPaths = new CategoryPath[10]; String[] topLevelStrings = new String[10]; @@ -88,5 +89,7 @@ + nonTopLevelPaths[i], pathPolicy.shouldAdd(nonTopLevelPaths[i])); } + taxonomy.close(); + dir.close(); } } Index: modules/facet/src/test/org/apache/lucene/facet/enhancements/TwoEnhancementsTest.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/enhancements/TwoEnhancementsTest.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/enhancements/TwoEnhancementsTest.java (working copy) @@ -4,14 +4,13 @@ import java.util.Arrays; import java.util.List; -import org.apache.lucene.analysis.core.WhitespaceAnalyzer; +import org.apache.lucene.analysis.MockAnalyzer; +import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; 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.store.Directory; -import org.apache.lucene.store.RAMDirectory; import org.junit.Test; import org.apache.lucene.util.LuceneTestCase; @@ -45,8 +44,8 @@ @Test public void testTwoEmptyAndNonEmptyByteArrays() throws Exception { - Directory indexDir = new RAMDirectory(); - Directory taxoDir = new RAMDirectory(); + Directory indexDir = newDirectory(); + Directory taxoDir = newDirectory(); EnhancementsIndexingParams indexingParams = new DefaultEnhancementsIndexingParams( @@ -57,8 +56,8 @@ List categoryPaths = new ArrayList(); categoryPaths.add(new CategoryPath("a", "b")); - IndexWriter indexWriter = new IndexWriter(indexDir, new IndexWriterConfig( - TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))); + RandomIndexWriter indexWriter = new RandomIndexWriter(random, indexDir, newIndexWriterConfig( + TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); TaxonomyWriter taxo = new LuceneTaxonomyWriter(taxoDir); // a category document builder will add the categories to a document @@ -67,9 +66,9 @@ indexWriter.addDocument(new EnhancementsDocumentBuilder(taxo, indexingParams).setCategoryPaths(categoryPaths).build(doc)); + IndexReader indexReader = indexWriter.getReader(); indexWriter.close(); - IndexReader indexReader = IndexReader.open(indexDir); Term term = DrillDown.term(indexingParams, new CategoryPath("a","b")); EnhancementsPayloadIterator iterator = new EnhancementsPayloadIterator( indexingParams.getCategoryEnhancements(), indexReader, term); @@ -82,13 +81,17 @@ .getCategoryData(new CategoryEnhancementDummy3()); assertTrue("Bad array returned for CategoryEnhancementDummy3", Arrays .equals(dummy3, CategoryEnhancementDummy3.CATEGORY_TOKEN_BYTES)); + indexReader.close(); + indexDir.close(); + taxo.close(); + taxoDir.close(); } @Test public void testTwoNonEmptyByteArrays() throws Exception { // add document with a category containing data for both enhancements - Directory indexDir = new RAMDirectory(); - Directory taxoDir = new RAMDirectory(); + Directory indexDir = newDirectory(); + Directory taxoDir = newDirectory(); EnhancementsIndexingParams indexingParams = new DefaultEnhancementsIndexingParams( @@ -98,8 +101,8 @@ List categoryPaths = new ArrayList(); categoryPaths.add(new CategoryPath("a", "b")); - IndexWriter indexWriter = new IndexWriter(indexDir, new IndexWriterConfig( - TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))); + RandomIndexWriter indexWriter = new RandomIndexWriter(random, indexDir, newIndexWriterConfig( + TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); TaxonomyWriter taxo = new LuceneTaxonomyWriter(taxoDir); // a category document builder will add the categories to a document @@ -108,9 +111,9 @@ indexWriter.addDocument(new EnhancementsDocumentBuilder(taxo, indexingParams).setCategoryPaths(categoryPaths).build(doc)); + IndexReader indexReader = indexWriter.getReader(); indexWriter.close(); - IndexReader indexReader = IndexReader.open(indexDir); Term term = DrillDown.term(indexingParams, new CategoryPath("a","b")); EnhancementsPayloadIterator iterator = new EnhancementsPayloadIterator( indexingParams.getCategoryEnhancements(), indexReader, term); @@ -125,5 +128,9 @@ .getCategoryData(new CategoryEnhancementDummy3()); assertTrue("Bad array returned for CategoryEnhancementDummy3", Arrays .equals(dummy3, CategoryEnhancementDummy3.CATEGORY_TOKEN_BYTES)); + indexReader.close(); + taxo.close(); + indexDir.close(); + taxoDir.close(); } } Index: modules/facet/src/test/org/apache/lucene/facet/enhancements/EnhancementsPayloadIteratorTest.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/enhancements/EnhancementsPayloadIteratorTest.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/enhancements/EnhancementsPayloadIteratorTest.java (working copy) @@ -5,7 +5,6 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; -import org.apache.lucene.store.RAMDirectory; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -46,8 +45,8 @@ @BeforeClass public static void buildAssociationIndex() throws Exception { // create Directories for the search index and for the taxonomy index - indexDir = new RAMDirectory(); - taxoDir = new RAMDirectory(); + indexDir = newDirectory(); + taxoDir = newDirectory(); // index the sample documents if (VERBOSE) { @@ -73,6 +72,7 @@ assertTrue("Missing instance of tags/lucene in doc 1", iterator.setdoc(1)); assoc = (Integer) iterator.getCategoryData(associationEnhancement); assertEquals("Unexpected association value for tags/lucene in doc 1", 1, assoc, 1E-5); + indexReader.close(); } @Test @@ -84,6 +84,7 @@ assertTrue("Unexpected failure of init()", iterator.init()); assertFalse("Unexpected payload for root/a/f2 in doc 0", iterator.setdoc(0)); assertFalse("Unexpected instance of root/a/f2 in doc 1", iterator.setdoc(1)); + indexReader.close(); } @Test @@ -98,11 +99,14 @@ float assoc = Float.intBitsToFloat((Integer) iterator .getCategoryData(associationEnhancement)); assertEquals("Unexpected association value for genre/computing in doc 1", 0.34f, assoc, 0.001); + indexReader.close(); } @AfterClass public static void closeDirectories() throws IOException { indexDir.close(); + indexDir = null; taxoDir.close(); + taxoDir = null; } } Index: modules/facet/src/test/org/apache/lucene/facet/enhancements/association/CustomAssociationPropertyTest.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/enhancements/association/CustomAssociationPropertyTest.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/enhancements/association/CustomAssociationPropertyTest.java (working copy) @@ -1,12 +1,11 @@ package org.apache.lucene.facet.enhancements.association; -import org.apache.lucene.analysis.core.KeywordAnalyzer; +import org.apache.lucene.analysis.MockAnalyzer; +import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; 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.store.Directory; -import org.apache.lucene.store.RAMDirectory; import org.junit.Test; import org.apache.lucene.util.LuceneTestCase; @@ -55,10 +54,11 @@ EnhancementsIndexingParams iParams = new DefaultEnhancementsIndexingParams( new AssociationEnhancement()); - Directory iDir = new RAMDirectory(); - Directory tDir = new RAMDirectory(); + Directory iDir = newDirectory(); + Directory tDir = newDirectory(); - IndexWriter w = new IndexWriter(iDir, new IndexWriterConfig(TEST_VERSION_CURRENT, new KeywordAnalyzer())); + RandomIndexWriter w = new RandomIndexWriter(random, iDir, + newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.KEYWORD, false))); LuceneTaxonomyWriter taxoW = new LuceneTaxonomyWriter(tDir); CategoryContainer cc = new CategoryContainer(); @@ -72,9 +72,9 @@ builder.setCategories(cc); w.addDocument(builder.build(new Document())); taxoW.close(); + IndexReader reader = w.getReader(); w.close(); - IndexReader reader = IndexReader.open(iDir); LuceneTaxonomyReader taxo = new LuceneTaxonomyReader(tDir); String field = iParams.getCategoryListParams(new CategoryPath("0")).getTerm().field(); AssociationsPayloadIterator api = new AssociationsPayloadIterator(reader, field); @@ -93,5 +93,10 @@ } assertTrue("No categories found for doc #0", flag); + + reader.close(); + taxo.close(); + iDir.close(); + tDir.close(); } } Index: modules/facet/src/test/org/apache/lucene/facet/FacetTestBase.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/FacetTestBase.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/FacetTestBase.java (working copy) @@ -11,7 +11,8 @@ import org.apache.lucene.DocumentBuilder.DocumentBuilderException; import org.apache.lucene.analysis.Analyzer; -import org.apache.lucene.analysis.core.WhitespaceAnalyzer; +import org.apache.lucene.analysis.MockAnalyzer; +import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.Field.Index; @@ -20,21 +21,19 @@ import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.index.MultiFields; +import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.store.Directory; -import org.apache.lucene.store.FSDirectory; -import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.Bits; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util._TestUtil; import org.apache.lucene.facet.index.CategoryDocumentBuilder; import org.apache.lucene.facet.index.params.CategoryListParams; import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams; @@ -131,15 +130,15 @@ } if (onDisk) { - File indexFile = new File(TEMP_DIR,"index"); - indexDir = FSDirectory.open(indexFile); - taxoDir = FSDirectory.open(new File(indexFile,"facets")); + File indexFile = _TestUtil.getTempDir("index"); + indexDir = newFSDirectory(indexFile); + taxoDir = newFSDirectory(new File(indexFile,"facets")); } else { - indexDir = new RAMDirectory(); - taxoDir = new RAMDirectory(); + indexDir = newDirectory(); + taxoDir = newDirectory(); } - IndexWriter iw = new IndexWriter(indexDir, new IndexWriterConfig(TEST_VERSION_CURRENT, getAnalyzer())); + RandomIndexWriter iw = new RandomIndexWriter(random, indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, getAnalyzer())); TaxonomyWriter taxo = new LuceneTaxonomyWriter(taxoDir, OpenMode.CREATE); populateIndex(iw, taxo, getFacetIndexingParams(partitionSize)); @@ -153,7 +152,7 @@ // prepare for searching taxoReader = new LuceneTaxonomyReader(taxoDir); indexReader = IndexReader.open(indexDir); - searcher = new IndexSearcher(indexReader); + searcher = newSearcher(indexReader); } /** Returns a default facet indexing params */ @@ -187,7 +186,7 @@ * Populate the test index+taxonomy for this test. *

Subclasses can override this to test different scenarios */ - protected void populateIndex(IndexWriter iw, TaxonomyWriter taxo, FacetIndexingParams iParams) + protected void populateIndex(RandomIndexWriter iw, TaxonomyWriter taxo, FacetIndexingParams iParams) throws IOException, DocumentBuilderException, CorruptIndexException { // add test documents int numDocsToIndex = numDocsToIndex(); @@ -211,7 +210,9 @@ indexReader = null; searcher.close(); searcher = null; + indexDir.close(); indexDir = null; + taxoDir.close(); taxoDir = null; } @@ -220,7 +221,7 @@ * Sub classes should override in order to test with different analyzer. */ protected Analyzer getAnalyzer() { - return new WhitespaceAnalyzer(TEST_VERSION_CURRENT); + return new MockAnalyzer(random, MockTokenizer.WHITESPACE, false); } /** convenience method: convert sub results to an array */ @@ -233,7 +234,7 @@ } /** utility Create a dummy document with specified categories and content */ - protected final void indexDoc(FacetIndexingParams iParams, IndexWriter iw, + protected final void indexDoc(FacetIndexingParams iParams, RandomIndexWriter iw, TaxonomyWriter tw, String content, List categories) throws IOException, CorruptIndexException { Document d = new Document(); Index: modules/facet/src/test/org/apache/lucene/facet/util/TestScoredDocIDsUtils.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/util/TestScoredDocIDsUtils.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/util/TestScoredDocIDsUtils.java (working copy) @@ -1,16 +1,17 @@ package org.apache.lucene.facet.util; import java.io.IOException; +import java.util.Random; -import org.apache.lucene.analysis.core.KeywordAnalyzer; +import org.apache.lucene.analysis.MockAnalyzer; +import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.Field.Index; import org.apache.lucene.document.Field.Store; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.MultiFields; +import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; @@ -18,7 +19,6 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; import org.apache.lucene.store.Directory; -import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.Bits; import org.apache.lucene.util.OpenBitSet; import org.apache.lucene.util.OpenBitSetDISI; @@ -61,19 +61,22 @@ ScoredDocIDs scoredDocIDs = ScoredDocIdsUtils.createScoredDocIds(bits, n); - IndexReader reader = createReaderWithNDocs(n); + Directory dir = newDirectory(); + IndexReader reader = createReaderWithNDocs(random, n, dir); try { assertEquals(n - verify.cardinality(), ScoredDocIdsUtils.getComplementSet(scoredDocIDs, reader).size()); } finally { reader.close(); + dir.close(); } } @Test public void testAllDocs() throws Exception { int maxDoc = 3; - IndexReader reader = createReaderWithNDocs(maxDoc); + Directory dir = newDirectory(); + IndexReader reader = createReaderWithNDocs(random, maxDoc, dir); try { ScoredDocIDs all = ScoredDocIdsUtils.createAllDocsScoredDocIDs(reader); assertEquals("invalid size", maxDoc, all.size()); @@ -95,6 +98,7 @@ assertEquals(2, docIDsIter.advance(0)); } finally { reader.close(); + dir.close(); } } @@ -119,7 +123,8 @@ } }; - IndexReader reader = createReaderWithNDocs(N_DOCS, docFactory); + Directory dir = newDirectory(); + IndexReader reader = createReaderWithNDocs(random, N_DOCS, docFactory, dir); try { int numErasedDocs = reader.numDeletedDocs(); @@ -142,7 +147,9 @@ // Get all 'alpha' documents ScoredDocIdCollector collector = ScoredDocIdCollector.create(reader.maxDoc(), false); Query q = new TermQuery(new Term(DocumentFactory.field, DocumentFactory.alphaTxt)); - new IndexSearcher(reader).search(q, collector); + IndexSearcher searcher = newSearcher(reader); + searcher.search(q, collector); + searcher.close(); ScoredDocIDs scoredDocIds = collector.getScoredDocIDs(); OpenBitSet resultSet = new OpenBitSetDISI(scoredDocIds.getDocIDs().iterator(), reader.maxDoc()); @@ -171,6 +178,7 @@ } } finally { reader.close(); + dir.close(); } } @@ -178,8 +186,9 @@ * Creates an index with n documents, this method is meant for testing purposes ONLY * Node that this reader is NOT read-only and document can be deleted. */ - static IndexReader createReaderWithNDocs(int nDocs) throws IOException { - return createReaderWithNDocs(nDocs, new DocumentFactory(nDocs)); + // TODO: this comment seems out of date... the reader is read-only... + static IndexReader createReaderWithNDocs(Random random, int nDocs, Directory directory) throws IOException { + return createReaderWithNDocs(random, nDocs, new DocumentFactory(nDocs), directory); } private static class DocumentFactory { @@ -217,23 +226,21 @@ } } - static IndexReader createReaderWithNDocs(int nDocs, DocumentFactory docFactory) throws IOException { - Directory ramDir = new RAMDirectory(); - + static IndexReader createReaderWithNDocs(Random random, int nDocs, DocumentFactory docFactory, Directory dir) throws IOException { // Create the index - IndexWriter writer = new IndexWriter(ramDir, new IndexWriterConfig(TEST_VERSION_CURRENT, new KeywordAnalyzer())); + RandomIndexWriter writer = new RandomIndexWriter(random, dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, + new MockAnalyzer(random, MockTokenizer.KEYWORD, false))); for (int docNum = 0; docNum < nDocs; docNum++) { writer.addDocument(docFactory.getDoc(docNum)); } - writer.commit(); writer.close(); // Delete documents marked for deletion - IndexReader reader = IndexReader.open(ramDir, false); + IndexReader reader = IndexReader.open(dir, false); reader.deleteDocuments(new Term(DocumentFactory.field, DocumentFactory.delTxt)); reader.close(); // Open a fresh read-only reader with the deletions in place - return IndexReader.open(ramDir, true); + return IndexReader.open(dir, true); } } Index: modules/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java (working copy) @@ -158,13 +158,14 @@ */ @Test public void testWriter() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); fillTaxonomy(tw); // Also check TaxonomyWriter.getSize() - see that the taxonomy's size // is what we expect it to be. assertEquals(expectedCategories.length, tw.getSize()); tw.close(); + indexDir.close(); } /** testWriterTwice is exactly like testWriter, except that after adding @@ -173,7 +174,7 @@ */ @Test public void testWriterTwice() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); fillTaxonomy(tw); // run fillTaxonomy again - this will try to add the same categories @@ -184,6 +185,7 @@ // extraneous categories were created: assertEquals(expectedCategories.length, tw.getSize()); tw.close(); + indexDir.close(); } /** testWriterTwice2 is similar to testWriterTwice, except that the index @@ -194,7 +196,7 @@ */ @Test public void testWriterTwice2() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); fillTaxonomy(tw); tw.close(); @@ -206,6 +208,7 @@ fillTaxonomy(tw); assertEquals(expectedCategories.length, tw.getSize()); tw.close(); + indexDir.close(); } /** @@ -217,7 +220,7 @@ */ @Test public void testWriterTwice3() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); // First, create and fill the taxonomy TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); fillTaxonomy(tw); @@ -239,6 +242,7 @@ tw.commit(); assertEquals(expectedCategories.length+1, tw.getSize()); tw.close(); + indexDir.close(); } /** Another set of tests for the writer, which don't use an array and @@ -248,7 +252,7 @@ */ @Test public void testWriterSimpler() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); assertEquals(1, tw.getSize()); // the root only // Test that adding a new top-level category works @@ -283,6 +287,7 @@ assertEquals(9, tw.getSize()); tw.close(); + indexDir.close(); } /** Test writing an empty index, and seeing that a reader finds in it @@ -291,7 +296,7 @@ */ @Test public void testRootOnly() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); // right after opening the index, it should already contain the // root, so have size 1: @@ -303,6 +308,7 @@ assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getParent(0)); assertEquals(0, tr.getOrdinal(new CategoryPath())); tr.close(); + indexDir.close(); } /** The following test is exactly the same as testRootOnly, except we @@ -312,7 +318,7 @@ */ @Test public void testRootOnly2() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); tw.commit(); TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); @@ -322,6 +328,7 @@ assertEquals(0, tr.getOrdinal(new CategoryPath())); tw.close(); tr.close(); + indexDir.close(); } /** Basic tests for TaxonomyReader's category <=> ordinal transformations @@ -331,7 +338,7 @@ */ @Test public void testReaderBasic() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); fillTaxonomy(tw); tw.close(); @@ -373,6 +380,7 @@ assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getOrdinal(new CategoryPath("Author", "Jules Verne"))); tr.close(); + indexDir.close(); } /** Tests for TaxonomyReader's getParent() method. @@ -389,7 +397,7 @@ @Test public void testReaderParent() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); fillTaxonomy(tw); tw.close(); @@ -436,6 +444,7 @@ } tr.close(); + indexDir.close(); } /** @@ -453,7 +462,7 @@ */ @Test public void testWriterParent1() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); fillTaxonomy(tw); tw.close(); @@ -464,11 +473,12 @@ tw.close(); tr.close(); + indexDir.close(); } @Test public void testWriterParent2() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); fillTaxonomy(tw); tw.commit(); @@ -478,6 +488,7 @@ tw.close(); tr.close(); + indexDir.close(); } private void checkWriterParent(TaxonomyReader tr, TaxonomyWriter tw) throws Exception { @@ -530,7 +541,7 @@ */ @Test public void testReaderParentArray() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); fillTaxonomy(tw); tw.close(); @@ -541,6 +552,7 @@ assertEquals(tr.getParent(i), parents[i]); } tr.close(); + indexDir.close(); } /** @@ -550,7 +562,7 @@ */ @Test public void testChildrenArrays() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); fillTaxonomy(tw); tw.close(); @@ -601,6 +613,7 @@ } } tr.close(); + indexDir.close(); } /** @@ -613,7 +626,7 @@ */ @Test public void testChildrenArraysInvariants() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); fillTaxonomy(tw); tw.close(); @@ -685,6 +698,7 @@ } tr.close(); + indexDir.close(); } /** @@ -692,7 +706,7 @@ */ @Test public void testChildrenArraysGrowth() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); tw.addCategory(new CategoryPath("hi", "there")); tw.commit(); @@ -722,6 +736,7 @@ assertTrue(Arrays.equals(new int[] { -1, -1, -1, 2, 1 }, ca.getOlderSiblingArray())); tw.close(); tr.close(); + indexDir.close(); } /** @@ -731,7 +746,7 @@ @Ignore public void testTaxonomyReaderRefreshRaces() throws Exception { // compute base child arrays - after first chunk, and after the other - Directory indexDirBase = new RAMDirectory(); + Directory indexDirBase = newDirectory(); TaxonomyWriter twBase = new LuceneTaxonomyWriter(indexDirBase); twBase.addCategory(new CategoryPath("a", "0")); final CategoryPath abPath = new CategoryPath("a", "b"); @@ -757,6 +772,7 @@ for (int retry=0; retry<100; retry++) { assertConsistentYoungestChild(abPath, abOrd, abYoungChildBase1, abYoungChildBase2, retry); } + indexDirBase.close(); } private void assertConsistentYoungestChild(final CategoryPath abPath, @@ -848,7 +864,7 @@ */ @Test public void testSeparateReaderAndWriter() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); tw.commit(); TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); @@ -910,11 +926,12 @@ assertEquals(3, tr.getSize()); tw.close(); tr.close(); + indexDir.close(); } @Test public void testSeparateReaderAndWriter2() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); tw.commit(); TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); @@ -940,6 +957,7 @@ assertEquals(2, tr.getSize()); // still root only... tw.close(); tr.close(); + indexDir.close(); } /** @@ -948,6 +966,7 @@ */ @Test public void testWriterLock() throws Exception { + // native fslock impl gets angry if we use it, so use RAMDirectory explicitly. Directory indexDir = new RAMDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); tw.addCategory(new CategoryPath("hi", "there")); @@ -975,6 +994,8 @@ tr.refresh(); assertEquals(3, tr.getOrdinal(new CategoryPath("hey"))); tr.close(); + tw.close(); + indexDir.close(); } /** @@ -1032,13 +1053,14 @@ */ @Test public void testWriterCheckPaths() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); fillTaxonomyCheckPaths(tw); // Also check TaxonomyWriter.getSize() - see that the taxonomy's size // is what we expect it to be. assertEquals(expectedCategories.length, tw.getSize()); tw.close(); + indexDir.close(); } /** @@ -1050,7 +1072,7 @@ */ @Test public void testWriterCheckPaths2() throws Exception { - Directory indexDir = new RAMDirectory(); + Directory indexDir = newDirectory(); TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); fillTaxonomy(tw); checkPaths(tw); @@ -1063,6 +1085,7 @@ fillTaxonomy(tw); checkPaths(tw); tw.close(); + indexDir.close(); } // TODO (Facet): test multiple readers, one writer. Have the multiple readers Index: modules/facet/src/test/org/apache/lucene/facet/taxonomy/lucene/TestAddTaxonomies.java =================================================================== --- modules/facet/src/test/org/apache/lucene/facet/taxonomy/lucene/TestAddTaxonomies.java (revision 1141246) +++ modules/facet/src/test/org/apache/lucene/facet/taxonomy/lucene/TestAddTaxonomies.java (working copy) @@ -3,9 +3,9 @@ import java.io.File; import org.apache.lucene.store.Directory; -import org.apache.lucene.store.RAMDirectory; import org.junit.Test; +import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.TaxonomyReader; @@ -36,16 +36,16 @@ @Test public void test1() throws Exception { - Directory dir1 = new RAMDirectory(); + Directory dir1 = newDirectory(); LuceneTaxonomyWriter tw1 = new LuceneTaxonomyWriter(dir1); tw1.addCategory(new CategoryPath("Author", "Mark Twain")); tw1.addCategory(new CategoryPath("Animals", "Dog")); - Directory dir2 = new RAMDirectory(); + Directory dir2 = newDirectory(); LuceneTaxonomyWriter tw2 = new LuceneTaxonomyWriter(dir2); tw2.addCategory(new CategoryPath("Author", "Rob Pike")); tw2.addCategory(new CategoryPath("Aardvarks", "Bob")); tw2.close(); - Directory dir3 = new RAMDirectory(); + Directory dir3 = newDirectory(); LuceneTaxonomyWriter tw3 = new LuceneTaxonomyWriter(dir3); tw3.addCategory(new CategoryPath("Author", "Zebra Smith")); tw3.addCategory(new CategoryPath("Aardvarks", "Bob")); @@ -93,6 +93,11 @@ assertEquals(5, map1[3]); assertEquals(7, map1[4]); assertEquals(6, map1[5]); + + tr.close(); + dir1.close(); + dir2.close(); + dir3.close(); } // A more comprehensive and big random test. @@ -113,8 +118,8 @@ Directory copydirs[] = new Directory[ntaxonomies]; for (int i=0; i1) { for (int i=0; i