You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2010/08/14 16:11:41 UTC

svn commit: r985494 - in /lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search: TestCachingWrapperFilter.java spans/TestPayloadSpans.java spans/TestSpans.java

Author: rmuir
Date: Sat Aug 14 14:11:41 2010
New Revision: 985494

URL: http://svn.apache.org/viewvc?rev=985494&view=rev
Log:
LUCENE-2598: backport these 3 tests now that the other improvements to them are backported

Modified:
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java?rev=985494&r1=985493&r2=985494&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java Sat Aug 14 14:11:41 2010
@@ -20,8 +20,6 @@ package org.apache.lucene.search;
 import java.util.Random;
 import java.io.IOException;
 
-import org.apache.lucene.analysis.KeywordAnalyzer;
-import org.apache.lucene.analysis.WhitespaceAnalyzer;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.document.Document;
@@ -43,7 +41,7 @@ public class TestCachingWrapperFilter ex
   }
 
   public void testCachingWorks() throws Exception {
-    Directory dir = new MockRAMDirectory();
+    Directory dir = newDirectory(rand);
     RandomIndexWriter writer = new RandomIndexWriter(rand, dir);
     writer.close();
 
@@ -65,10 +63,11 @@ public class TestCachingWrapperFilter ex
     assertFalse("second time", filter.wasCalled());
 
     reader.close();
+    dir.close();
   }
   
   public void testNullDocIdSet() throws Exception {
-    Directory dir = new MockRAMDirectory();
+    Directory dir = newDirectory(rand);
     RandomIndexWriter writer = new RandomIndexWriter(rand, dir);
     writer.close();
 
@@ -86,10 +85,11 @@ public class TestCachingWrapperFilter ex
     assertSame(DocIdSet.EMPTY_DOCIDSET, cacher.getDocIdSet(reader));
     
     reader.close();
+    dir.close();
   }
   
   public void testNullDocIdSetIterator() throws Exception {
-    Directory dir = new MockRAMDirectory();
+    Directory dir = newDirectory(rand);
     RandomIndexWriter writer = new RandomIndexWriter(rand, dir);
     writer.close();
 
@@ -112,6 +112,7 @@ public class TestCachingWrapperFilter ex
     assertSame(DocIdSet.EMPTY_DOCIDSET, cacher.getDocIdSet(reader));
     
     reader.close();
+    dir.close();
   }
   
   private static void assertDocIdSetCacheable(IndexReader reader, Filter filter, boolean shouldCacheable) throws IOException {
@@ -129,7 +130,7 @@ public class TestCachingWrapperFilter ex
   }
   
   public void testIsCacheAble() throws Exception {
-    Directory dir = new MockRAMDirectory();
+    Directory dir = newDirectory(rand);
     RandomIndexWriter writer = new RandomIndexWriter(rand, dir);
     writer.addDocument(new Document());
     writer.close();
@@ -151,10 +152,11 @@ public class TestCachingWrapperFilter ex
     }, true);
 
     reader.close();
+    dir.close();
   }
 
   public void testEnforceDeletions() throws Exception {
-    Directory dir = new MockRAMDirectory();
+    Directory dir = newDirectory(rand);
     RandomIndexWriter writer = new RandomIndexWriter(rand, dir);
 
     // NOTE: cannot use writer.getReader because RIW (on
@@ -266,6 +268,9 @@ public class TestCachingWrapperFilter ex
 
     // doesn't count as a miss
     assertEquals(missCount, filter.missCount);
+    reader.close();
+    writer.close();
+    dir.close();
   }
 
   private static IndexReader refreshReader(IndexReader reader) throws IOException {

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java?rev=985494&r1=985493&r2=985494&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java Sat Aug 14 14:11:41 2010
@@ -45,8 +45,8 @@ import org.apache.lucene.search.TermQuer
 import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.search.payloads.PayloadHelper;
 import org.apache.lucene.search.payloads.PayloadSpanUtil;
+import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.LockObtainFailedException;
-import org.apache.lucene.store.MockRAMDirectory;
 import org.apache.lucene.util.LuceneTestCase;
 
 public class TestPayloadSpans extends LuceneTestCase {
@@ -54,6 +54,7 @@ public class TestPayloadSpans extends Lu
   private Similarity similarity = new DefaultSimilarity();
   protected IndexReader indexReader;
   private IndexReader closeIndexReader;
+  private Directory directory;
   private Random rand;
 
   public TestPayloadSpans(String s) {
@@ -112,7 +113,7 @@ public class TestPayloadSpans extends Lu
     SpanQuery spq = new SpanNearQuery(clauses, 5, true);
     SpanNotQuery snq = new SpanNotQuery(spq, new SpanTermQuery(new Term(PayloadHelper.FIELD, "two")));
 
-    MockRAMDirectory directory = new MockRAMDirectory();
+    Directory directory = newDirectory(rand);
     RandomIndexWriter writer = new RandomIndexWriter(rand, directory,
                                                      newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new PayloadAnalyzer()).setSimilarity(similarity));
 
@@ -125,6 +126,7 @@ public class TestPayloadSpans extends Lu
 
     checkSpans(snq.getSpans(reader), 1,new int[]{2});
     reader.close();
+    directory.close();
   }
   
   public void testNestedSpans() throws Exception {
@@ -181,6 +183,7 @@ public class TestPayloadSpans extends Lu
     assertTrue("spans is null and it shouldn't be", spans != null);
     checkSpans(spans, 2, new int[]{3,3});
     closeIndexReader.close();
+    directory.close();
   }
   
   public void testFirstClauseWithoutPayload() throws Exception {
@@ -212,6 +215,7 @@ public class TestPayloadSpans extends Lu
     assertTrue("spans is null and it shouldn't be", spans != null);
     checkSpans(spans, 1, new int[]{3});
     closeIndexReader.close();
+    directory.close();
   }
   
   public void testHeavilyNestedSpanQuery() throws Exception {
@@ -248,11 +252,12 @@ public class TestPayloadSpans extends Lu
     assertTrue("spans is null and it shouldn't be", spans != null);
     checkSpans(spans, 2, new int[]{8, 8});
     closeIndexReader.close();
+    directory.close();
   }
   
   public void testShrinkToAfterShortestMatch() throws CorruptIndexException,
       LockObtainFailedException, IOException {
-    MockRAMDirectory directory = new MockRAMDirectory();
+    Directory directory = newDirectory(rand);
     RandomIndexWriter writer = new RandomIndexWriter(rand, directory,
                                                      newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new TestPayloadAnalyzer()));
 
@@ -285,11 +290,12 @@ public class TestPayloadSpans extends Lu
     assertTrue(payloadSet.contains("a:Noise:10"));
     assertTrue(payloadSet.contains("k:Noise:11"));
     reader.close();
+    directory.close();
   }
   
   public void testShrinkToAfterShortestMatch2() throws CorruptIndexException,
       LockObtainFailedException, IOException {
-    MockRAMDirectory directory = new MockRAMDirectory();
+    Directory directory = newDirectory(rand);
     RandomIndexWriter writer = new RandomIndexWriter(rand, directory,
                                                      newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new TestPayloadAnalyzer()));
 
@@ -320,11 +326,12 @@ public class TestPayloadSpans extends Lu
     assertTrue(payloadSet.contains("a:Noise:10"));
     assertTrue(payloadSet.contains("k:Noise:11"));
     reader.close();
+    directory.close();
   }
   
   public void testShrinkToAfterShortestMatch3() throws CorruptIndexException,
       LockObtainFailedException, IOException {
-    MockRAMDirectory directory = new MockRAMDirectory();
+    Directory directory = newDirectory(rand);
     RandomIndexWriter writer = new RandomIndexWriter(rand, directory,
                                                      newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new TestPayloadAnalyzer()));
 
@@ -361,10 +368,11 @@ public class TestPayloadSpans extends Lu
     assertTrue(payloadSet.contains("a:Noise:10"));
     assertTrue(payloadSet.contains("k:Noise:11"));
     reader.close();
+    directory.close();
   }
   
   public void testPayloadSpanUtil() throws Exception {
-    MockRAMDirectory directory = new MockRAMDirectory();
+    Directory directory = newDirectory(rand);
     RandomIndexWriter writer = new RandomIndexWriter(rand, directory,
                                                      newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new PayloadAnalyzer()).setSimilarity(similarity));
 
@@ -386,6 +394,7 @@ public class TestPayloadSpans extends Lu
         System.out.println(new String(bytes));
     }
     reader.close();
+    directory.close();
   }
 
   private void checkSpans(Spans spans, int expectedNumSpans, int expectedNumPayloads,
@@ -422,7 +431,7 @@ public class TestPayloadSpans extends Lu
   }
   
   private IndexSearcher getSearcher() throws Exception {
-    MockRAMDirectory directory = new MockRAMDirectory();
+    directory = newDirectory(rand);
     String[] docs = new String[]{"xx rr yy mm  pp","xx yy mm rr pp", "nopayload qq ss pp np", "one two three four five six seven eight nine ten eleven", "nine one two three four five six seven eight eleven ten"};
     RandomIndexWriter writer = new RandomIndexWriter(rand, directory,
                                                      newIndexWriterConfig(rand, TEST_VERSION_CURRENT, new PayloadAnalyzer()).setSimilarity(similarity));

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java?rev=985494&r1=985493&r2=985494&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java Sat Aug 14 14:11:41 2010
@@ -39,19 +39,22 @@ import org.apache.lucene.document.Field;
 import org.apache.lucene.util.LuceneTestCase;
 import java.io.IOException;
 import java.util.Collections;
+import java.util.Random;
 
 public class TestSpans extends LuceneTestCase {
   private IndexSearcher searcher;
   private IndexReader reader;
   private Directory directory;
-
+  private Random random;
+  
   public static final String field = "field";
 
   @Override
   protected void setUp() throws Exception {
     super.setUp();
-    directory = new MockRAMDirectory();
-    RandomIndexWriter writer= new RandomIndexWriter(newRandom(), directory);
+    random = newRandom();
+    directory = newDirectory(random);
+    RandomIndexWriter writer= new RandomIndexWriter(random, directory);
     for (int i = 0; i < docFields.length; i++) {
       Document doc = new Document();
       doc.add(new Field(field, docFields[i], Field.Store.YES, Field.Index.ANALYZED));
@@ -461,8 +464,8 @@ public class TestSpans extends LuceneTes
 
   // LUCENE-1404
   public void testNPESpanQuery() throws Throwable {
-    final Directory dir = new MockRAMDirectory();
-    final IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
+    final Directory dir = newDirectory(random);
+    final IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random,
         TEST_VERSION_CURRENT, new StandardAnalyzer(
         TEST_VERSION_CURRENT, Collections.emptySet())));