lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1664421 [6/6] - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/analysis/ lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/ lucene/analysis/common/src/test/org/apache/lucene/analysis/ar/ lucene/analysis/common/src/te...
Date Thu, 05 Mar 2015 17:09:14 GMT
Modified: lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java?rev=1664421&r1=1664420&r2=1664421&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java
Thu Mar  5 17:09:12 2015
@@ -11,6 +11,7 @@ import java.util.Map;
 import java.util.Random;
 import java.util.Set;
 
+import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
@@ -26,6 +27,7 @@ import org.apache.lucene.index.Term;
 import org.apache.lucene.search.spell.Dictionary;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.LuceneTestCase;
 import org.junit.Test;
 
@@ -113,7 +115,8 @@ public class DocumentDictionaryTest exte
   @Test
   public void testEmptyReader() throws IOException {
     Directory dir = newDirectory();
-    IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
+    Analyzer analyzer = new MockAnalyzer(random());
+    IndexWriterConfig iwc = newIndexWriterConfig(analyzer);
     iwc.setMergePolicy(newLogMergePolicy());
     // Make sure the index is created?
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
@@ -127,14 +130,14 @@ public class DocumentDictionaryTest exte
     assertEquals(inputIterator.weight(), 0);
     assertNull(inputIterator.payload());
     
-    ir.close();
-    dir.close();
+    IOUtils.close(ir, analyzer, dir);
   }
   
   @Test
   public void testBasic() throws IOException {
     Directory dir = newDirectory();
-    IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
+    Analyzer analyzer = new MockAnalyzer(random());
+    IndexWriterConfig iwc = newIndexWriterConfig(analyzer);
     iwc.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
     Map.Entry<List<String>, Map<String, Document>> res = generateIndexDocuments(atLeast(1000),
true, false);
@@ -162,14 +165,14 @@ public class DocumentDictionaryTest exte
     }
     assertTrue(docs.isEmpty());
     
-    ir.close();
-    dir.close();
+    IOUtils.close(ir, analyzer, dir);
   }
  
   @Test
   public void testWithoutPayload() throws IOException {
     Directory dir = newDirectory();
-    IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
+    Analyzer analyzer = new MockAnalyzer(random());
+    IndexWriterConfig iwc = newIndexWriterConfig(analyzer);
     iwc.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
     Map.Entry<List<String>, Map<String, Document>> res = generateIndexDocuments(atLeast(1000),
false, false);
@@ -198,14 +201,14 @@ public class DocumentDictionaryTest exte
     
     assertTrue(docs.isEmpty());
     
-    ir.close();
-    dir.close();
+    IOUtils.close(ir, analyzer, dir);
   }
   
   @Test
   public void testWithContexts() throws IOException {
     Directory dir = newDirectory();
-    IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
+    Analyzer analyzer = new MockAnalyzer(random());
+    IndexWriterConfig iwc = newIndexWriterConfig(analyzer);
     iwc.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
     Map.Entry<List<String>, Map<String, Document>> res = generateIndexDocuments(atLeast(1000),
true, true);
@@ -239,14 +242,14 @@ public class DocumentDictionaryTest exte
     }
     assertTrue(docs.isEmpty());
     
-    ir.close();
-    dir.close();
+    IOUtils.close(ir, analyzer, dir);
   }
   
   @Test
   public void testWithDeletions() throws IOException {
     Directory dir = newDirectory();
-    IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
+    Analyzer analyzer = new MockAnalyzer(random());
+    IndexWriterConfig iwc = newIndexWriterConfig(analyzer);
     iwc.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
     Map.Entry<List<String>, Map<String, Document>> res = generateIndexDocuments(atLeast(1000),
false, false);
@@ -296,14 +299,14 @@ public class DocumentDictionaryTest exte
     }
     assertTrue(docs.isEmpty());
     
-    ir.close();
-    dir.close();
+    IOUtils.close(ir, analyzer, dir);
   }
 
   @Test
   public void testMultiValuedField() throws IOException {
     Directory dir = newDirectory();
-    IndexWriterConfig iwc = newIndexWriterConfig(random(), new MockAnalyzer(random()));
+    Analyzer analyzer = new MockAnalyzer(random());
+    IndexWriterConfig iwc = newIndexWriterConfig(random(), analyzer);
     iwc.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
 
@@ -325,8 +328,7 @@ public class DocumentDictionaryTest exte
       assertTrue(inputIterator.contexts().equals(nextSuggestion.contexts));
     }
     assertFalse(suggestionsIter.hasNext());
-    ir.close();
-    dir.close();
+    IOUtils.close(ir, analyzer, dir);
   }
 
   private List<Suggestion> indexMultiValuedDocuments(int numDocs, RandomIndexWriter
writer) throws IOException {

Modified: lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java?rev=1664421&r1=1664420&r2=1664421&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java
Thu Mar  5 17:09:12 2015
@@ -26,6 +26,7 @@ import java.util.Map;
 import java.util.Random;
 import java.util.Set;
 
+import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
@@ -45,6 +46,7 @@ import org.apache.lucene.queries.functio
 import org.apache.lucene.search.spell.Dictionary;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.LuceneTestCase;
 import org.junit.Test;
 
@@ -85,7 +87,8 @@ public class DocumentValueSourceDictiona
   @Test
   public void testEmptyReader() throws IOException {
     Directory dir = newDirectory();
-    IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
+    Analyzer analyzer = new MockAnalyzer(random());
+    IndexWriterConfig iwc = newIndexWriterConfig(analyzer);
     iwc.setMergePolicy(newLogMergePolicy());
     // Make sure the index is created?
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
@@ -99,14 +102,14 @@ public class DocumentValueSourceDictiona
     assertEquals(inputIterator.weight(), 0);
     assertNull(inputIterator.payload());
 
-    ir.close();
-    dir.close();
+    IOUtils.close(ir, analyzer, dir);
   }
   
   @Test
   public void testBasic() throws IOException {
     Directory dir = newDirectory();
-    IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
+    Analyzer analyzer = new MockAnalyzer(random());
+    IndexWriterConfig iwc = newIndexWriterConfig(analyzer);
     iwc.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
     Map<String, Document> docs = generateIndexDocuments(atLeast(100));
@@ -131,14 +134,14 @@ public class DocumentValueSourceDictiona
       assertTrue(inputIterator.payload().equals(doc.getField(PAYLOAD_FIELD_NAME).binaryValue()));
     }
     assertTrue(docs.isEmpty());
-    ir.close();
-    dir.close();
+    IOUtils.close(ir, analyzer, dir);
   }
   
   @Test
   public void testWithContext() throws IOException {
     Directory dir = newDirectory();
-    IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
+    Analyzer analyzer = new MockAnalyzer(random());
+    IndexWriterConfig iwc = newIndexWriterConfig(analyzer);
     iwc.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
     Map<String, Document> docs = generateIndexDocuments(atLeast(100));
@@ -168,14 +171,14 @@ public class DocumentValueSourceDictiona
       assertEquals(originalCtxs, inputIterator.contexts());
     }
     assertTrue(docs.isEmpty());
-    ir.close();
-    dir.close();
+    IOUtils.close(ir, analyzer, dir);
   }
 
   @Test
   public void testWithoutPayload() throws IOException {
     Directory dir = newDirectory();
-    IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
+    Analyzer analyzer = new MockAnalyzer(random());
+    IndexWriterConfig iwc = newIndexWriterConfig(analyzer);
     iwc.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
     Map<String, Document> docs = generateIndexDocuments(atLeast(100));
@@ -200,14 +203,14 @@ public class DocumentValueSourceDictiona
       assertEquals(inputIterator.payload(), null);
     }
     assertTrue(docs.isEmpty());
-    ir.close();
-    dir.close();
+    IOUtils.close(ir, analyzer, dir);
   }
   
   @Test
   public void testWithDeletions() throws IOException {
     Directory dir = newDirectory();
-    IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
+    Analyzer analyzer = new MockAnalyzer(random());
+    IndexWriterConfig iwc = newIndexWriterConfig(analyzer);
     iwc.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
     Map<String, Document> docs = generateIndexDocuments(atLeast(100));
@@ -253,15 +256,14 @@ public class DocumentValueSourceDictiona
       assertTrue(inputIterator.payload().equals(doc.getField(PAYLOAD_FIELD_NAME).binaryValue()));
     }
     assertTrue(docs.isEmpty());
-    ir.close();
-    dir.close();
+    IOUtils.close(ir, analyzer, dir);
   }
   
   @Test
   public void testWithValueSource() throws IOException {
-    
     Directory dir = newDirectory();
-    IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
+    Analyzer analyzer = new MockAnalyzer(random());
+    IndexWriterConfig iwc = newIndexWriterConfig(analyzer);
     iwc.setMergePolicy(newLogMergePolicy());
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
     Map<String, Document> docs = generateIndexDocuments(atLeast(100));
@@ -282,8 +284,7 @@ public class DocumentValueSourceDictiona
       assertTrue(inputIterator.payload().equals(doc.getField(PAYLOAD_FIELD_NAME).binaryValue()));
     }
     assertTrue(docs.isEmpty());
-    ir.close();
-    dir.close();
+    IOUtils.close(ir, analyzer, dir);
   }
   
 }

Modified: lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java?rev=1664421&r1=1664420&r2=1664421&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java
Thu Mar  5 17:09:12 2015
@@ -43,6 +43,7 @@ import org.apache.lucene.search.suggest.
 import org.apache.lucene.search.suggest.Lookup.LookupResult;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.TestUtil;
 import org.junit.Test;
@@ -117,6 +118,7 @@ public class AnalyzingInfixSuggesterTest
     testConstructorDefaults(suggester, keys, a, false, true);
     
     suggester.close();
+    a.close();
   }
 
   private void testConstructorDefaults(AnalyzingInfixSuggester suggester, Input[] keys, Analyzer
a, 
@@ -158,6 +160,7 @@ public class AnalyzingInfixSuggesterTest
     assertEquals(new BytesRef("foobaz"), results.get(0).payload);
     assertEquals(2, suggester.getCount());
     suggester.close();
+    a.close();
   }
 
   /** Used to return highlighted result; see {@link
@@ -239,6 +242,7 @@ public class AnalyzingInfixSuggesterTest
     assertEquals(10, results.get(0).value);
     assertEquals(new BytesRef("foobaz"), results.get(0).payload);
     suggester.close();
+    a.close();
   }
 
   public String toString(List<LookupHighlightFragment> fragments) {
@@ -320,6 +324,7 @@ public class AnalyzingInfixSuggesterTest
       suggester = new AnalyzingInfixSuggester(newFSDirectory(tempDir), a, a, minPrefixLength,
false);
     }
     suggester.close();
+    a.close();
   }
 
   public void testHighlight() throws Exception {
@@ -335,6 +340,7 @@ public class AnalyzingInfixSuggesterTest
     assertEquals("a penny saved is a penny earned", results.get(0).key);
     assertEquals("a <b>penn</b>y saved is a <b>penn</b>y earned",
results.get(0).highlightKey);
     suggester.close();
+    a.close();
   }
 
   public void testHighlightCaseChange() throws Exception {
@@ -367,6 +373,7 @@ public class AnalyzingInfixSuggesterTest
     assertEquals("a Penny saved is a penny earned", results.get(0).key);
     assertEquals("a <b>Penny</b> saved is a <b>penny</b> earned",
results.get(0).highlightKey);
     suggester.close();
+    a.close();
   }
 
   public void testDoubleClose() throws Exception {
@@ -379,6 +386,7 @@ public class AnalyzingInfixSuggesterTest
     suggester.build(new InputArrayIterator(keys));
     suggester.close();
     suggester.close();
+    a.close();
   }
 
   public void testSuggestStopFilter() throws Exception {
@@ -413,6 +421,7 @@ public class AnalyzingInfixSuggesterTest
     assertEquals("a bob for apples", results.get(0).key);
     assertEquals("a bob for <b>a</b>pples", results.get(0).highlightKey);
     suggester.close();
+    IOUtils.close(suggester, indexAnalyzer, queryAnalyzer);
   }
 
   public void testEmptyAtStart() throws Exception {
@@ -456,6 +465,7 @@ public class AnalyzingInfixSuggesterTest
     assertEquals(new BytesRef("foobaz"), results.get(0).payload);
 
     suggester.close();
+    a.close();
   }
 
   public void testBothExactAndPrefix() throws Exception {
@@ -472,6 +482,7 @@ public class AnalyzingInfixSuggesterTest
     assertEquals(10, results.get(0).value);
     assertEquals(new BytesRef("foobaz"), results.get(0).payload);
     suggester.close();
+    a.close();
   }
 
   private static String randomText() {
@@ -741,6 +752,7 @@ public class AnalyzingInfixSuggesterTest
 
     lookupThread.finish();
     suggester.close();
+    a.close();
   }
 
   private static String hilite(boolean lastPrefix, String[] inputTerms, String[] queryTerms)
{
@@ -856,6 +868,7 @@ public class AnalyzingInfixSuggesterTest
     assertEquals(10, results.get(1).value);
     assertEquals(new BytesRef("foobaz"), results.get(1).payload);
     suggester.close();
+    a.close();
   }
 
   public void testNRTWithParallelAdds() throws IOException, InterruptedException {
@@ -896,6 +909,7 @@ public class AnalyzingInfixSuggesterTest
     assertEquals("python", results.get(0).key);
 
     suggester.close();
+    a.close();
   }
 
   private class IndexDocument implements Runnable {
@@ -1153,6 +1167,7 @@ public class AnalyzingInfixSuggesterTest
       assertTrue(result.contexts.contains(new BytesRef("baz")));
 
       suggester.close();
+      a.close();
     }
   }
 
@@ -1170,6 +1185,7 @@ public class AnalyzingInfixSuggesterTest
 
     dir.close();
     suggester.close();
+    a.close();
   }
 
   private String pfmToString(AnalyzingInfixSuggester suggester, String surface, String prefix)
throws IOException {

Modified: lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java?rev=1664421&r1=1664420&r2=1664421&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java
Thu Mar  5 17:09:12 2015
@@ -53,6 +53,7 @@ import org.apache.lucene.search.suggest.
 import org.apache.lucene.search.suggest.InputArrayIterator;
 import org.apache.lucene.util.AttributeFactory;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.LineFileDocs;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.TestUtil;
@@ -71,7 +72,8 @@ public class AnalyzingSuggesterTest exte
         new Input("barbara", 1)
     );
 
-    AnalyzingSuggester suggester = new AnalyzingSuggester(new MockAnalyzer(random(), MockTokenizer.KEYWORD,
false));
+    Analyzer analyzer = new MockAnalyzer(random(), MockTokenizer.KEYWORD, false);
+    AnalyzingSuggester suggester = new AnalyzingSuggester(analyzer);
     suggester.build(new InputArrayIterator(keys));
     
     // top N of 2, but only foo is available
@@ -104,6 +106,8 @@ public class AnalyzingSuggesterTest exte
     assertEquals(10, results.get(1).value, 0.01F);
     assertEquals("barbara", results.get(2).key.toString());
     assertEquals(6, results.get(2).value, 0.01F);
+    
+    analyzer.close();
   }
   
   public void testKeywordWithPayloads() throws Exception {
@@ -115,7 +119,8 @@ public class AnalyzingSuggesterTest exte
       new Input("bar", 8, new BytesRef("should also be deduplicated")),
       new Input("barbara", 6, new BytesRef("for all the fish")));
     
-    AnalyzingSuggester suggester = new AnalyzingSuggester(new MockAnalyzer(random(), MockTokenizer.KEYWORD,
false));
+    Analyzer analyzer = new MockAnalyzer(random(), MockTokenizer.KEYWORD, false);
+    AnalyzingSuggester suggester = new AnalyzingSuggester(analyzer);
     suggester.build(new InputArrayIterator(keys));
     for (int i = 0; i < 2; i++) {
       // top N of 2, but only foo is available
@@ -156,6 +161,7 @@ public class AnalyzingSuggesterTest exte
       assertEquals(6, results.get(2).value, 0.01F);
       assertEquals(new BytesRef("for all the fish"), results.get(2).payload);
     }
+    analyzer.close();
   }
   
   public void testRandomRealisticKeys() throws IOException {
@@ -173,7 +179,9 @@ public class AnalyzingSuggesterTest exte
           mapping.put(title, Long.valueOf(randomWeight));
       }
     }
-    AnalyzingSuggester analyzingSuggester = new AnalyzingSuggester(new MockAnalyzer(random()),
new MockAnalyzer(random()),
+    Analyzer indexAnalyzer = new MockAnalyzer(random());
+    Analyzer queryAnalyzer = new MockAnalyzer(random());
+    AnalyzingSuggester analyzingSuggester = new AnalyzingSuggester(indexAnalyzer, queryAnalyzer,
         AnalyzingSuggester.EXACT_FIRST | AnalyzingSuggester.PRESERVE_SEP, 256, -1, random().nextBoolean());
     boolean doPayloads = random().nextBoolean();
     if (doPayloads) {
@@ -198,7 +206,7 @@ public class AnalyzingSuggesterTest exte
       }
     }
     
-    lineFile.close();
+    IOUtils.close(lineFile, indexAnalyzer, queryAnalyzer);
   }
   
   // TODO: more tests
@@ -232,6 +240,8 @@ public class AnalyzingSuggesterTest exte
     assertEquals(1, results.size());
     assertEquals("the ghost of christmas past", results.get(0).key.toString());
     assertEquals(50, results.get(0).value, 0.01F);
+    
+    standard.close();
   }
 
   public void testEmpty() throws Exception {
@@ -241,6 +251,7 @@ public class AnalyzingSuggesterTest exte
 
     List<LookupResult> result = suggester.lookup("a", false, 20);
     assertTrue(result.isEmpty());
+    standard.close();
   }
 
   public void testNoSeps() throws Exception {
@@ -265,6 +276,7 @@ public class AnalyzingSuggesterTest exte
     // complete to "abcd", which has higher weight so should
     // appear first:
     assertEquals("abcd", r.get(0).key.toString());
+    a.close();
   }
 
   public void testGraphDups() throws Exception {
@@ -330,6 +342,7 @@ public class AnalyzingSuggesterTest exte
     assertEquals(50, results.get(0).value);
     assertEquals("wi fi network is fast", results.get(1).key);
     assertEquals(10, results.get(1).value);
+    analyzer.close();
   }
 
   public void testInputPathRequired() throws Exception {
@@ -388,6 +401,7 @@ public class AnalyzingSuggesterTest exte
     suggester.build(new InputArrayIterator(keys));
     List<LookupResult> results = suggester.lookup("ab x", false, 1);
     assertTrue(results.size() == 1);
+    analyzer.close();
   }
 
   private static Token token(String term, int posInc, int posLength) {
@@ -492,6 +506,7 @@ public class AnalyzingSuggesterTest exte
         }
       }
     }
+    a.close();
   }
 
   public void testNonExactFirst() throws Exception {
@@ -529,6 +544,7 @@ public class AnalyzingSuggesterTest exte
         }
       }
     }
+    a.close();
   }
   
   // Holds surface form separately:
@@ -867,6 +883,7 @@ public class AnalyzingSuggesterTest exte
         }
       }
     }
+    a.close();
   }
 
   public void testMaxSurfaceFormsPerAnalyzedForm() throws Exception {
@@ -881,6 +898,7 @@ public class AnalyzingSuggesterTest exte
     assertEquals(60, results.get(0).value);
     assertEquals("a ", results.get(1).key);
     assertEquals(50, results.get(1).value);
+    a.close();
   }
 
   public void testQueueExhaustion() throws Exception {
@@ -895,6 +913,7 @@ public class AnalyzingSuggesterTest exte
         }));
 
     suggester.lookup("a", false, 4);
+    a.close();
   }
 
   public void testExactFirstMissingResult() throws Exception {
@@ -941,6 +960,7 @@ public class AnalyzingSuggesterTest exte
     assertEquals(4, results.get(1).value);
     assertEquals("a b", results.get(2).key);
     assertEquals(3, results.get(2).value);
+    a.close();
   }
 
   public void testDupSurfaceFormsMissingResults() throws Exception {
@@ -999,6 +1019,7 @@ public class AnalyzingSuggesterTest exte
     assertEquals(6, results.get(0).value);
     assertEquals("nellie", results.get(1).key);
     assertEquals(5, results.get(1).value);
+    a.close();
   }
 
   public void testDupSurfaceFormsMissingResults2() throws Exception {
@@ -1068,6 +1089,7 @@ public class AnalyzingSuggesterTest exte
     assertEquals(6, results.get(0).value);
     assertEquals("b", results.get(1).key);
     assertEquals(5, results.get(1).value);
+    a.close();
   }
 
   public void test0ByteKeys() throws Exception {
@@ -1113,6 +1135,8 @@ public class AnalyzingSuggesterTest exte
           new Input("a a", 50),
           new Input("a b", 50),
         }));
+    
+    a.close();
   }
 
   public void testDupSurfaceFormsMissingResults3() throws Exception {
@@ -1126,6 +1150,7 @@ public class AnalyzingSuggesterTest exte
           new Input("a b", 5),
         }));
     assertEquals("[a a/7, a c/6, a b/5]", suggester.lookup("a", false, 3).toString());
+    a.close();
   }
 
   public void testEndingSpace() throws Exception {
@@ -1137,6 +1162,7 @@ public class AnalyzingSuggesterTest exte
         }));
     assertEquals("[isla de muerta/8, i love lucy/7]", suggester.lookup("i", false, 3).toString());
     assertEquals("[i love lucy/7]", suggester.lookup("i ", false, 3).toString());
+    a.close();
   }
 
   public void testTooManyExpansions() throws Exception {
@@ -1166,6 +1192,7 @@ public class AnalyzingSuggesterTest exte
     AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, 0, 256, 1, true);
     suggester.build(new InputArrayIterator(new Input[] {new Input("a", 1)}));
     assertEquals("[a/1]", suggester.lookup("a", false, 1).toString());
+    a.close();
   }
   
   public void testIllegalLookupArgument() throws Exception {
@@ -1186,6 +1213,7 @@ public class AnalyzingSuggesterTest exte
     } catch (IllegalArgumentException e) {
       // expected
     }
+    a.close();
   }
 
   static final Iterable<Input> shuffle(Input...values) {
@@ -1209,5 +1237,6 @@ public class AnalyzingSuggesterTest exte
     } catch (IllegalArgumentException iae) {
       // expected
     }
+    a.close();
   }
 }

Modified: lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/FuzzySuggesterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/FuzzySuggesterTest.java?rev=1664421&r1=1664420&r2=1664421&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/FuzzySuggesterTest.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/FuzzySuggesterTest.java
Thu Mar  5 17:09:12 2015
@@ -72,6 +72,7 @@ public class FuzzySuggesterTest extends
       assertEquals("foo bar boo far", results.get(0).key.toString());
       assertEquals(12, results.get(0).value, 0.01F);  
     }
+    analyzer.close();
   }
   
   public void testNonLatinRandomEdits() throws IOException {
@@ -93,6 +94,7 @@ public class FuzzySuggesterTest extends
       assertEquals("фуу бар буу фар", results.get(0).key.toString());
       assertEquals(12, results.get(0).value, 0.01F);
     }
+    analyzer.close();
   }
 
   /** this is basically the WFST test ported to KeywordAnalyzer. so it acts the same */
@@ -104,7 +106,8 @@ public class FuzzySuggesterTest extends
         new Input("barbara", 6)
     };
     
-    FuzzySuggester suggester = new FuzzySuggester(new MockAnalyzer(random(), MockTokenizer.KEYWORD,
false));
+    Analyzer analyzer = new MockAnalyzer(random(), MockTokenizer.KEYWORD, false);
+    FuzzySuggester suggester = new FuzzySuggester(analyzer);
     suggester.build(new InputArrayIterator(keys));
     
     List<LookupResult> results = suggester.lookup(TestUtil.stringToCharSequence("bariar",
random()), false, 2);
@@ -166,6 +169,8 @@ public class FuzzySuggesterTest extends
     assertEquals(10, results.get(1).value, 0.01F);
     assertEquals("barbara", results.get(2).key.toString());
     assertEquals(6, results.get(2).value, 0.01F);
+    
+    analyzer.close();
   }
   
   /**
@@ -197,6 +202,8 @@ public class FuzzySuggesterTest extends
     assertEquals(1, results.size());
     assertEquals("the ghost of christmas past", results.get(0).key.toString());
     assertEquals(50, results.get(0).value, 0.01F);
+    
+    standard.close();
   }
 
   public void testNoSeps() throws Exception {
@@ -221,6 +228,7 @@ public class FuzzySuggesterTest extends
     // complete to "abcd", which has higher weight so should
     // appear first:
     assertEquals("abcd", r.get(0).key.toString());
+    a.close();
   }
 
   public void testGraphDups() throws Exception {
@@ -286,14 +294,17 @@ public class FuzzySuggesterTest extends
     assertEquals(50, results.get(0).value);
     assertEquals("wi fi network is fast", results.get(1).key);
     assertEquals(10, results.get(1).value);
+    analyzer.close();
   }
 
   public void testEmpty() throws Exception {
-    FuzzySuggester suggester = new FuzzySuggester(new MockAnalyzer(random(), MockTokenizer.KEYWORD,
false));
+    Analyzer analyzer = new MockAnalyzer(random(), MockTokenizer.KEYWORD, false);
+    FuzzySuggester suggester = new FuzzySuggester(analyzer);
     suggester.build(new InputArrayIterator(new Input[0]));
 
     List<LookupResult> result = suggester.lookup("a", false, 20);
     assertTrue(result.isEmpty());
+    analyzer.close();
   }
 
   public void testInputPathRequired() throws Exception {
@@ -352,6 +363,7 @@ public class FuzzySuggesterTest extends
     suggester.build(new InputArrayIterator(keys));
     List<LookupResult> results = suggester.lookup("ab x", false, 1);
     assertTrue(results.size() == 1);
+    analyzer.close();
   }
 
   private static Token token(String term, int posInc, int posLength) {
@@ -451,6 +463,7 @@ public class FuzzySuggesterTest extends
         }
       }
     }
+    a.close();
   }
 
   public void testNonExactFirst() throws Exception {
@@ -488,6 +501,7 @@ public class FuzzySuggesterTest extends
         }
       }
     }
+    a.close();
   }
   
   // Holds surface form separately:
@@ -820,6 +834,7 @@ public class FuzzySuggesterTest extends
         assertEquals(matches.get(hit).value, r.get(hit).value, 0f);
       }
     }
+    a.close();
   }
 
   public void testMaxSurfaceFormsPerAnalyzedForm() throws Exception {
@@ -841,6 +856,7 @@ public class FuzzySuggesterTest extends
     assertEquals(60, results.get(0).value);
     assertEquals("a ", results.get(1).key);
     assertEquals(50, results.get(1).value);
+    a.close();
   }
 
   public void testEditSeps() throws Exception {
@@ -861,6 +877,7 @@ public class FuzzySuggesterTest extends
     assertEquals("[foo bar baz/50]", suggester.lookup("foobarbaz", false, 5).toString());
     assertEquals("[barbaz/60, barbazfoo/10]", suggester.lookup("bar baz", false, 5).toString());
     assertEquals("[barbazfoo/10]", suggester.lookup("bar baz foo", false, 5).toString());
+    a.close();
   }
   
   @SuppressWarnings("fallthrough")
@@ -1003,6 +1020,7 @@ public class FuzzySuggesterTest extends
       }
       assertEquals(expected.size(), actual.size());
     }
+    a.close();
   }
 
   private List<LookupResult> slowFuzzyMatch(int prefixLen, int maxEdits, boolean allowTransposition,
List<Input> answers, String frag) {

Modified: lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java?rev=1664421&r1=1664420&r2=1664421&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java
Thu Mar  5 17:09:12 2015
@@ -95,6 +95,7 @@ public class TestFreeTextSuggester exten
       is.close();
       assertEquals(2, sug.getCount());
     }
+    a.close();
   }
 
   public void testIllegalByteDuringBuild() throws Exception {
@@ -103,13 +104,15 @@ public class TestFreeTextSuggester exten
     Iterable<Input> keys = AnalyzingSuggesterTest.shuffle(
         new Input("foo\u001ebar baz", 50)
     );
-    FreeTextSuggester sug = new FreeTextSuggester(new MockAnalyzer(random()));
+    Analyzer analyzer = new MockAnalyzer(random());
+    FreeTextSuggester sug = new FreeTextSuggester(analyzer);
     try {
       sug.build(new InputArrayIterator(keys));
       fail("did not hit expected exception");
     } catch (IllegalArgumentException iae) {
       // expected
     }
+    analyzer.close();
   }
 
   public void testIllegalByteDuringQuery() throws Exception {
@@ -118,7 +121,8 @@ public class TestFreeTextSuggester exten
     Iterable<Input> keys = AnalyzingSuggesterTest.shuffle(
         new Input("foo bar baz", 50)
     );
-    FreeTextSuggester sug = new FreeTextSuggester(new MockAnalyzer(random()));
+    Analyzer analyzer = new MockAnalyzer(random());
+    FreeTextSuggester sug = new FreeTextSuggester(analyzer);
     sug.build(new InputArrayIterator(keys));
 
     try {
@@ -127,6 +131,7 @@ public class TestFreeTextSuggester exten
     } catch (IllegalArgumentException iae) {
       // expected
     }
+    analyzer.close();
   }
 
   @Ignore
@@ -134,7 +139,8 @@ public class TestFreeTextSuggester exten
     final LineFileDocs lfd = new LineFileDocs(null, "/lucenedata/enwiki/enwiki-20120502-lines-1k.txt",
false);
     // Skip header:
     lfd.nextDoc();
-    FreeTextSuggester sug = new FreeTextSuggester(new MockAnalyzer(random()));
+    Analyzer analyzer = new MockAnalyzer(random());
+    FreeTextSuggester sug = new FreeTextSuggester(analyzer);
     sug.build(new InputIterator() {
 
         private int count;
@@ -190,6 +196,7 @@ public class TestFreeTextSuggester exten
         System.out.println("  " + result);
       }
     }
+    analyzer.close();
   }
 
   // Make sure you can suggest based only on unigram model:
@@ -204,6 +211,7 @@ public class TestFreeTextSuggester exten
     // Sorts first by count, descending, second by term, ascending
     assertEquals("bar/0.22 baz/0.11 bee/0.11 blah/0.11 boo/0.11",
                  toString(sug.lookup("b", 10)));
+    a.close();
   }
 
   // Make sure the last token is not duplicated
@@ -216,6 +224,7 @@ public class TestFreeTextSuggester exten
     sug.build(new InputArrayIterator(keys));
     assertEquals("foo bar/1.00",
                  toString(sug.lookup("foo b", 10)));
+    a.close();
   }
 
   // Lookup of just empty string produces unicode only matches:
@@ -232,6 +241,7 @@ public class TestFreeTextSuggester exten
     } catch (IllegalArgumentException iae) {
       // expected
     }
+    a.close();
   }
 
   // With one ending hole, ShingleFilter produces "of _" and
@@ -259,6 +269,7 @@ public class TestFreeTextSuggester exten
     // prop 0.5:
     assertEquals("oz/0.20",
                  toString(sug.lookup("wizard o", 10)));
+    a.close();
   }
 
   // If the number of ending holes exceeds the ngrams window
@@ -282,6 +293,7 @@ public class TestFreeTextSuggester exten
     sug.build(new InputArrayIterator(keys));
     assertEquals("",
                  toString(sug.lookup("wizard of of", 10)));
+    a.close();
   }
 
   private static Comparator<LookupResult> byScoreThenKey = new Comparator<LookupResult>()
{
@@ -578,6 +590,7 @@ public class TestFreeTextSuggester exten
 
       assertEquals(expected.toString(), actual.toString());
     }
+    a.close();
   }
 
   private static String getZipfToken(String[] tokens) {

Modified: lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java?rev=1664421&r1=1664420&r2=1664421&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java
Thu Mar  5 17:09:12 2015
@@ -29,6 +29,7 @@ import org.apache.lucene.document.Field;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.InfoStream;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.NullInfoStream;
@@ -49,6 +50,7 @@ public class RandomIndexWriter implement
   private double flushAtFactor = 1.0;
   private boolean getReaderCalled;
   private final Codec codec; // sugar
+  private final Analyzer analyzer; // only if WE created it (then we close it)
 
   /** Returns an indexwriter that randomly mixes up thread scheduling (by yielding at test
points) */
   public static IndexWriter mockIndexWriter(Directory dir, IndexWriterConfig conf, Random
r) throws IOException {
@@ -73,7 +75,7 @@ public class RandomIndexWriter implement
 
   /** create a RandomIndexWriter with a random config: Uses MockAnalyzer */
   public RandomIndexWriter(Random r, Directory dir) throws IOException {
-    this(r, dir, LuceneTestCase.newIndexWriterConfig(r, new MockAnalyzer(r)));
+    this(r, dir, LuceneTestCase.newIndexWriterConfig(r, new MockAnalyzer(r)), true);
   }
   
   /** create a RandomIndexWriter with a random config */
@@ -83,10 +85,19 @@ public class RandomIndexWriter implement
   
   /** create a RandomIndexWriter with the provided config */
   public RandomIndexWriter(Random r, Directory dir, IndexWriterConfig c) throws IOException
{
+    this(r, dir, c, false);
+  }
+      
+  private RandomIndexWriter(Random r, Directory dir, IndexWriterConfig c, boolean closeAnalyzer)
throws IOException {
     // TODO: this should be solved in a different way; Random should not be shared (!).
     this.r = new Random(r.nextLong());
     w = mockIndexWriter(dir, c, r);
     flushAt = TestUtil.nextInt(r, 10, 1000);
+    if (closeAnalyzer) {
+      analyzer = w.getAnalyzer();
+    } else {
+      analyzer = null;
+    }
     codec = w.getConfig().getCodec();
     if (LuceneTestCase.VERBOSE) {
       System.out.println("RIW dir=" + dir + " config=" + w.getConfig());
@@ -361,7 +372,7 @@ public class RandomIndexWriter implement
         w.commit();
       }
     }
-    w.close();
+    IOUtils.close(w, analyzer);
   }
 
   /**

Modified: lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/BaseExplanationTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/BaseExplanationTestCase.java?rev=1664421&r1=1664420&r2=1664421&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/BaseExplanationTestCase.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/BaseExplanationTestCase.java
Thu Mar  5 17:09:12 2015
@@ -17,6 +17,7 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
+import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
@@ -51,6 +52,7 @@ public abstract class BaseExplanationTes
   protected static IndexSearcher searcher;
   protected static IndexReader reader;
   protected static Directory directory;
+  protected static Analyzer analyzer;
   
   public static final String KEY = "KEY";
   // boost on this field is the same as the iterator for the doc
@@ -65,12 +67,15 @@ public abstract class BaseExplanationTes
     reader = null;
     directory.close();
     directory = null;
+    analyzer.close();
+    analyzer = null;
   }
   
   @BeforeClass
   public static void beforeClassTestExplanations() throws Exception {
     directory = newDirectory();
-    RandomIndexWriter writer= new RandomIndexWriter(random(), directory, newIndexWriterConfig(new
MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
+    analyzer = new MockAnalyzer(random());
+    RandomIndexWriter writer= new RandomIndexWriter(random(), directory, newIndexWriterConfig(analyzer).setMergePolicy(newLogMergePolicy()));
     for (int i = 0; i < docFields.length; i++) {
       Document doc = new Document();
       doc.add(newStringField(KEY, ""+i, Field.Store.NO));

Modified: lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/util/LineFileDocs.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/util/LineFileDocs.java?rev=1664421&r1=1664420&r2=1664421&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/util/LineFileDocs.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/util/LineFileDocs.java
Thu Mar  5 17:09:12 2015
@@ -73,10 +73,8 @@ public class LineFileDocs implements Clo
 
   @Override
   public synchronized void close() throws IOException {
-    if (reader != null) {
-      reader.close();
-      reader = null;
-    }
+    IOUtils.close(reader, threadDocs);
+    reader = null;
   }
   
   private long randomSeekPos(Random random, long size) {
@@ -205,7 +203,7 @@ public class LineFileDocs implements Clo
     }
   }
 
-  private final ThreadLocal<DocState> threadDocs = new ThreadLocal<>();
+  private final CloseableThreadLocal<DocState> threadDocs = new CloseableThreadLocal<>();
 
   /** Note: Document instance is re-used per-thread */
   public Document nextDoc() throws IOException {



Mime
View raw message