lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject cvs commit: jakarta-lucene/src/test/org/apache/lucene/index TestCompoundFile.java TestIndexReader.java TestDoc.java
Date Thu, 23 Oct 2003 02:02:06 GMT
ehatcher    2003/10/22 19:02:06

  Modified:    src/test/org/apache/lucene/index TestCompoundFile.java
                        TestIndexReader.java TestDoc.java
  Log:
  change tests to use new sys property
  
  Revision  Changes    Path
  1.3       +8 -17     jakarta-lucene/src/test/org/apache/lucene/index/TestCompoundFile.java
  
  Index: TestCompoundFile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/index/TestCompoundFile.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestCompoundFile.java	13 Oct 2003 14:31:38 -0000	1.2
  +++ TestCompoundFile.java	23 Oct 2003 02:02:06 -0000	1.3
  @@ -55,17 +55,16 @@
    */
   
   import java.io.IOException;
  +import java.io.File;
   
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   import junit.textui.TestRunner;
  -
  -import org.apache.lucene.store.*;
  -import org.apache.lucene.analysis.WhitespaceAnalyzer;
  -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.store.OutputStream;
  +import org.apache.lucene.store.Directory;
  +import org.apache.lucene.store.InputStream;
  +import org.apache.lucene.store.FSDirectory;
  +import org.apache.lucene.store._TestHelper;
   
   
   /**
  @@ -92,20 +91,12 @@
       }
   
   
  -    public TestCompoundFile() {
  -        super();
  -    }
  -
  -    public TestCompoundFile(String name) {
  -        super(name);
  -    }
  -
       private Directory dir;
   
   
       public void setUp() throws IOException {
           //dir = new RAMDirectory();
  -        dir = FSDirectory.getDirectory("testIndex", true);
  +        dir = FSDirectory.getDirectory(new File(System.getProperty("tempDir"), "testIndex"),
true);
       }
   
   
  
  
  
  1.5       +46 -48    jakarta-lucene/src/test/org/apache/lucene/index/TestIndexReader.java
  
  Index: TestIndexReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/index/TestIndexReader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestIndexReader.java	25 Sep 2003 21:42:53 -0000	1.4
  +++ TestIndexReader.java	23 Oct 2003 02:02:06 -0000	1.5
  @@ -58,12 +58,7 @@
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   import junit.textui.TestRunner;
  -import junit.framework.TestResult;
   
  -import org.apache.lucene.search.IndexSearcher;
  -import org.apache.lucene.search.Searcher;
  -import org.apache.lucene.search.Hits;
  -import org.apache.lucene.search.TermQuery;
   import org.apache.lucene.store.Directory;
   import org.apache.lucene.store.RAMDirectory;
   import org.apache.lucene.store.FSDirectory;
  @@ -74,6 +69,7 @@
   
   import java.util.Collection;
   import java.io.IOException;
  +import java.io.File;
   
   public class TestIndexReader extends TestCase
   {
  @@ -85,7 +81,7 @@
   //        TestRunner.run (new TestIndexReader("testDeleteReaderReaderConflict"));
   //        TestRunner.run (new TestIndexReader("testFilesOpenClose"));
       }
  -    
  +
       public TestIndexReader(String name) {
           super(name);
       }
  @@ -149,15 +145,15 @@
           assertTrue(fieldNames.contains("unindexed"));
       }
   
  -    
  -    private void assertTermDocsCount(String msg, 
  -                                     IndexReader reader, 
  +
  +    private void assertTermDocsCount(String msg,
  +                                     IndexReader reader,
                                        Term term,
  -                                     int expected) 
  +                                     int expected)
       throws IOException
       {
           TermDocs tdocs = null;
  -        
  +
           try {
               tdocs = reader.termDocs(term);
               assertNotNull(msg + ", null TermDocs", tdocs);
  @@ -166,21 +162,20 @@
                   count++;
               }
               assertEquals(msg + ", count mismatch", expected, count);
  -            
  +
           } finally {
  -            if (tdocs != null) 
  +            if (tdocs != null)
                   try { tdocs.close(); } catch (Exception e) { }
           }
  -        
  +
       }
   
  -    
  +
   
       public void testBasicDelete() throws IOException
       {
           Directory dir = new RAMDirectory();
  -        //Directory dir = FSDirectory.getDirectory("testIndex", true);
  -            
  +
           IndexWriter writer = null;
           IndexReader reader = null;
           Term searchTerm = new Term("content", "aaa");
  @@ -192,7 +187,7 @@
               addDoc(writer, searchTerm.text());
           }
           writer.close();
  -        
  +
           // OPEN READER AT THIS POINT - this should fix the view of the
           // index at the point of having 100 "aaa" documents and 0 "bbb"
           reader = IndexReader.open(dir);
  @@ -216,12 +211,12 @@
       }
   
   
  -    
  +
       public void testDeleteReaderWriterConflict() throws IOException
       {
           //Directory dir = new RAMDirectory();
  -        Directory dir = FSDirectory.getDirectory("testIndex", true);
  -            
  +        Directory dir = getDirectory(true);
  +
           Term searchTerm = new Term("content", "aaa");
           Term searchTerm2 = new Term("content", "bbb");
   
  @@ -232,7 +227,7 @@
               addDoc(writer, searchTerm.text());
           }
           writer.close();
  -        
  +
           // OPEN READER AT THIS POINT - this should fix the view of the
           // index at the point of having 100 "aaa" documents and 0 "bbb"
           IndexReader reader = IndexReader.open(dir);
  @@ -247,7 +242,7 @@
           {
               addDoc(writer, searchTerm2.text());
           }
  -        
  +
           // REQUEST OPTIMIZATION
           // This causes a new segment to become current for all subsequent
           // searchers. Because of this, deletions made via a previously open
  @@ -261,8 +256,8 @@
           assertEquals("first docFreq", 0, reader.docFreq(searchTerm2));
           assertTermDocsCount("first reader", reader, searchTerm, 100);
           assertTermDocsCount("first reader", reader, searchTerm2, 0);
  -        
  -        
  +
  +
           // DELETE DOCUMENTS CONTAINING TERM: aaa
           // NOTE: the reader was created when only "aaa" documents were in
           int deleted = 0;
  @@ -272,8 +267,8 @@
           } catch (IOException e) {
               /* success */
           }
  -        
  -        // Re-open index reader and try again. This time it should see 
  +
  +        // Re-open index reader and try again. This time it should see
           // the new data.
           reader.close();
           reader = IndexReader.open(dir);
  @@ -281,7 +276,7 @@
           assertEquals("first docFreq", 100, reader.docFreq(searchTerm2));
           assertTermDocsCount("first reader", reader, searchTerm, 100);
           assertTermDocsCount("first reader", reader, searchTerm2, 100);
  -        
  +
           deleted = reader.delete(searchTerm);
           assertEquals("deleted count", 100, deleted);
           assertEquals("deleted docFreq", 100, reader.docFreq(searchTerm));
  @@ -299,39 +294,42 @@
           reader.close();
       }
   
  -    public void testFilesOpenClose() throws IOException 
  +  private Directory getDirectory(boolean create) throws IOException {
  +    return FSDirectory.getDirectory(new File(System.getProperty("tempDir"), "testIndex"),
create);
  +  }
  +
  +  public void testFilesOpenClose() throws IOException
       {
           // Create initial data set
  -        Directory dir = FSDirectory.getDirectory("testIndex", true);
  +        Directory dir = getDirectory(true);
           IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
           addDoc(writer, "test");
           writer.close();
           dir.close();
  -        
  +
           // Try to erase the data - this ensures that the writer closed all files
  -        dir = FSDirectory.getDirectory("testIndex", true);
  -        
  -        // Now create the data set again, just as before 
  +        dir = getDirectory(true);
  +
  +        // Now create the data set again, just as before
           writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
           addDoc(writer, "test");
           writer.close();
           dir.close();
  -        
  +
           // Now open existing directory and test that reader closes all files
  -        dir = FSDirectory.getDirectory("testIndex", false);
  +        dir = getDirectory(false);
           IndexReader reader1 = IndexReader.open(dir);
           reader1.close();
           dir.close();
  -        
  +
           // The following will fail if reader did not close all files
  -        dir = FSDirectory.getDirectory("testIndex", true);
  +        dir = getDirectory(true);
       }
  -    
  -    
  +
  +
       public void testDeleteReaderReaderConflict() throws IOException
       {
  -//        Directory dir = new RAMDirectory();
  -        Directory dir = FSDirectory.getDirectory("testIndex", true);
  +        Directory dir = getDirectory(true);
   
           Term searchTerm1 = new Term("content", "aaa");
           Term searchTerm2 = new Term("content", "bbb");
  @@ -359,7 +357,7 @@
           assertTermDocsCount("first opened", reader1, searchTerm1, 100);
           assertTermDocsCount("first opened", reader1, searchTerm2, 100);
           assertTermDocsCount("first opened", reader1, searchTerm3, 100);
  -        
  +
           IndexReader reader2 = IndexReader.open(dir);
           assertEquals("first opened", 100, reader2.docFreq(searchTerm1));
           assertEquals("first opened", 100, reader2.docFreq(searchTerm2));
  @@ -388,8 +386,8 @@
           assertTermDocsCount("after delete 1", reader1, searchTerm1, 100);
           assertTermDocsCount("after delete 1", reader1, searchTerm2, 100);
           assertTermDocsCount("after delete 1", reader1, searchTerm3, 100);
  -        
  -        
  +
  +
           // ATTEMPT TO DELETE FROM STALE READER
           // delete documents containing term: bbb
           try {
  @@ -398,7 +396,7 @@
           } catch (IOException e) {
               /* success */
           }
  -        
  +
           // RECREATE READER AND TRY AGAIN
           reader1.close();
           reader1 = IndexReader.open(dir);
  @@ -417,7 +415,7 @@
           assertTermDocsCount("deleted 2", reader1, searchTerm2, 0);
           assertTermDocsCount("deleted 2", reader1, searchTerm3, 100);
           reader1.close();
  -        
  +
           // Open another reader to confirm that everything is deleted
           reader2 = IndexReader.open(dir);
           assertEquals("reopened 2", 100, reader2.docFreq(searchTerm1));
  @@ -427,7 +425,7 @@
           assertTermDocsCount("reopened 2", reader2, searchTerm2, 0);
           assertTermDocsCount("reopened 2", reader2, searchTerm3, 100);
           reader2.close();
  -        
  +
           dir.close();
       }
   
  
  
  
  1.2       +32 -32    jakarta-lucene/src/test/org/apache/lucene/index/TestDoc.java
  
  Index: TestDoc.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/index/TestDoc.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestDoc.java	25 Sep 2003 22:01:51 -0000	1.1
  +++ TestDoc.java	23 Oct 2003 02:02:06 -0000	1.2
  @@ -75,79 +75,79 @@
    * @version $Id$
    */
   public class TestDoc extends TestCase {
  -    
  +
       /** Main for running test case by itself. */
       public static void main(String args[]) {
           TestRunner.run (new TestSuite(TestDoc.class));
       }
  -    
  -    
  +
  +
       private File workDir;
       private File indexDir;
       private LinkedList files;
  -    
  -    
  -    /** Set the test case. This test case needs 
  +
  +
  +    /** Set the test case. This test case needs
        *  a few text files created in the current working directory.
        */
       public void setUp() throws IOException {
  -        workDir = new File("TestDoc");
  +        workDir = new File(System.getProperty("tempDir"),"TestDoc");
           workDir.mkdirs();
  -        
  +
           indexDir = new File(workDir, "testIndex");
           indexDir.mkdirs();
  -        
  +
           Directory directory = FSDirectory.getDirectory(indexDir, true);
           directory.close();
  -        
  +
           files = new LinkedList();
  -        files.add(createFile("test.txt", 
  +        files.add(createFile("test.txt",
               "This is the first test file"
           ));
  -        
  +
           files.add(createFile("test2.txt",
               "This is the second test file"
           ));
       }
  -    
  +
       private File createFile(String name, String text) throws IOException {
           FileWriter fw = null;
           PrintWriter pw = null;
  -        
  +
           try {
               File f = new File(workDir, name);
               if (f.exists()) f.delete();
  -            
  +
               fw = new FileWriter(f);
               pw = new PrintWriter(fw);
               pw.println(text);
               return f;
  -            
  +
           } finally {
               if (pw != null) pw.close();
               if (fw != null) fw.close();
           }
       }
  -    
  -    
  +
  +
       /** This test executes a number of merges and compares the contents of
        *  the segments created when using compound file or not using one.
  -     *  
  +     *
        *  TODO: the original test used to print the segment contents to System.out
        *        for visual validation. To have the same effect, a new method
  -     *        checkSegment(String name, ...) should be created that would 
  +     *        checkSegment(String name, ...) should be created that would
        *        assert various things about the segment.
        */
       public void testIndexAndMerge() throws Exception {
         StringWriter sw = new StringWriter();
         PrintWriter out = new PrintWriter(sw, true);
  -      
  +
         Directory directory = FSDirectory.getDirectory(indexDir, true);
         directory.close();
   
         indexDoc("one", "test.txt");
         printSegment(out, "one");
  -      
  +
         indexDoc("two", "test2.txt");
         printSegment(out, "two");
   
  @@ -164,16 +164,16 @@
         sw.close();
         String multiFileOutput = sw.getBuffer().toString();
         System.out.println(multiFileOutput);
  -      
  +
         sw = new StringWriter();
         out = new PrintWriter(sw, true);
  -      
  +
         directory = FSDirectory.getDirectory(indexDir, true);
         directory.close();
   
         indexDoc("one", "test.txt");
         printSegment(out, "one");
  -      
  +
         indexDoc("two", "test2.txt");
         printSegment(out, "two");
   
  @@ -193,9 +193,9 @@
         assertEquals(multiFileOutput, singleFileOutput);
      }
   
  -   
  +
      private void indexDoc(String segment, String fileName)
  -   throws Exception 
  +   throws Exception
      {
         Directory directory = FSDirectory.getDirectory(indexDir, false);
         Analyzer analyzer = new SimpleAnalyzer();
  @@ -210,7 +210,7 @@
         directory.close();
      }
   
  -   
  +
      private void merge(String seg1, String seg2, String merged, boolean useCompoundFile)
      throws Exception {
         Directory directory = FSDirectory.getDirectory(indexDir, false);
  @@ -218,9 +218,9 @@
         SegmentReader r1 = new SegmentReader(new SegmentInfo(seg1, 1, directory));
         SegmentReader r2 = new SegmentReader(new SegmentInfo(seg2, 1, directory));
   
  -      SegmentMerger merger = 
  +      SegmentMerger merger =
           new SegmentMerger(directory, merged, useCompoundFile);
  -        
  +
         merger.add(r1);
         merger.add(r2);
         merger.merge();
  @@ -228,7 +228,7 @@
         directory.close();
      }
   
  -   
  +
      private void printSegment(PrintWriter out, String segment)
      throws Exception {
         Directory directory = FSDirectory.getDirectory(indexDir, false);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message