Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
36   89   6   6
0   63   0.17   6
6     1  
1    
 
  TestMultiReader       Line # 26 36 6 100% 1.0
 
  (4)
 
1    package org.apache.lucene.index;
2   
3    /**
4    * Copyright 2004 The Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18   
19    import junit.framework.TestCase;
20    import org.apache.lucene.document.Document;
21    import org.apache.lucene.store.Directory;
22    import org.apache.lucene.store.RAMDirectory;
23   
24    import java.io.IOException;
25   
 
26    public class TestMultiReader extends TestCase {
27    private Directory dir = new RAMDirectory();
28    private Document doc1 = new Document();
29    private Document doc2 = new Document();
30    private SegmentReader reader1;
31    private SegmentReader reader2;
32    private SegmentReader [] readers = new SegmentReader[2];
33    private SegmentInfos sis = new SegmentInfos();
34   
 
35  4 toggle public TestMultiReader(String s) {
36  4 super(s);
37    }
38   
 
39  4 toggle protected void setUp() throws IOException {
40  4 DocHelper.setupDoc(doc1);
41  4 DocHelper.setupDoc(doc2);
42  4 DocHelper.writeDoc(dir, "seg-1", doc1);
43  4 DocHelper.writeDoc(dir, "seg-2", doc2);
44  4 sis.write(dir);
45  4 reader1 = SegmentReader.get(new SegmentInfo("seg-1", 1, dir));
46  4 reader2 = SegmentReader.get(new SegmentInfo("seg-2", 1, dir));
47  4 readers[0] = reader1;
48  4 readers[1] = reader2;
49    }
50   
 
51  1 toggle public void test() {
52  1 assertTrue(dir != null);
53  1 assertTrue(reader1 != null);
54  1 assertTrue(reader2 != null);
55  1 assertTrue(sis != null);
56    }
57   
 
58  1 toggle public void testDocument() throws IOException {
59  1 sis.read(dir);
60  1 MultiReader reader = new MultiReader(dir, sis, false, readers);
61  1 assertTrue(reader != null);
62  1 Document newDoc1 = reader.document(0);
63  1 assertTrue(newDoc1 != null);
64  1 assertTrue(DocHelper.numFields(newDoc1) == DocHelper.numFields(doc1) - DocHelper.unstored.size());
65  1 Document newDoc2 = reader.document(1);
66  1 assertTrue(newDoc2 != null);
67  1 assertTrue(DocHelper.numFields(newDoc2) == DocHelper.numFields(doc2) - DocHelper.unstored.size());
68  1 TermFreqVector vector = reader.getTermFreqVector(0, DocHelper.TEXT_FIELD_2_KEY);
69  1 assertTrue(vector != null);
70  1 TestSegmentReader.checkNorms(reader);
71    }
72   
 
73  1 toggle public void testUndeleteAll() throws IOException {
74  1 sis.read(dir);
75  1 MultiReader reader = new MultiReader(dir, sis, false, readers);
76  1 assertTrue(reader != null);
77  1 assertEquals( 2, reader.numDocs() );
78  1 reader.deleteDocument(0);
79  1 assertEquals( 1, reader.numDocs() );
80  1 reader.undeleteAll();
81  1 assertEquals( 2, reader.numDocs() );
82    }
83   
84   
 
85  1 toggle public void testTermVectors() {
86  1 MultiReader reader = new MultiReader(dir, sis, false, readers);
87  1 assertTrue(reader != null);
88    }
89    }