Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
40   120   11   4
0   80   0.28   10
10     1.1  
1    
 
  TestRemoteSearchable       Line # 34 40 11 100% 1.0
 
  (5)
 
1    package org.apache.lucene.search;
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   
21    import java.rmi.Naming;
22    import java.rmi.registry.LocateRegistry;
23   
24    import org.apache.lucene.index.Term;
25    import org.apache.lucene.index.IndexWriter;
26    import org.apache.lucene.store.RAMDirectory;
27    import org.apache.lucene.analysis.SimpleAnalyzer;
28    import org.apache.lucene.document.Document;
29    import org.apache.lucene.document.Field;
30   
31    /**
32    * @version $Id: TestRemoteSearchable.java 384407 2006-03-09 02:42:13Z yonik $
33    */
 
34    public class TestRemoteSearchable extends TestCase {
 
35  5 toggle public TestRemoteSearchable(String name) {
36  5 super(name);
37    }
38   
 
39  5 toggle private static Searchable getRemote() throws Exception {
40  5 try {
41  5 return lookupRemote();
42    } catch (Throwable e) {
43  1 startServer();
44  1 return lookupRemote();
45    }
46    }
47   
 
48  6 toggle private static Searchable lookupRemote() throws Exception {
49  6 return (Searchable)Naming.lookup("//localhost/Searchable");
50    }
51   
 
52  1 toggle private static void startServer() throws Exception {
53    // construct an index
54  1 RAMDirectory indexStore = new RAMDirectory();
55  1 IndexWriter writer = new IndexWriter(indexStore,new SimpleAnalyzer(),true);
56  1 Document doc = new Document();
57  1 doc.add(new Field("test", "test text", Field.Store.YES, Field.Index.TOKENIZED));
58  1 writer.addDocument(doc);
59  1 writer.optimize();
60  1 writer.close();
61   
62    // publish it
63  1 LocateRegistry.createRegistry(1099);
64  1 Searchable local = new IndexSearcher(indexStore);
65  1 RemoteSearchable impl = new RemoteSearchable(local);
66  1 Naming.rebind("//localhost/Searchable", impl);
67    }
68   
 
69  3 toggle private static void search(Query query) throws Exception {
70    // try to search the published index
71  3 Searchable[] searchables = { getRemote() };
72  3 Searcher searcher = new MultiSearcher(searchables);
73  3 Hits result = searcher.search(query);
74   
75  3 assertEquals(1, result.length());
76  3 assertEquals("test text", result.doc(0).get("test"));
77    }
78   
 
79  1 toggle public void testTermQuery() throws Exception {
80  1 search(new TermQuery(new Term("test", "test")));
81    }
82   
 
83  1 toggle public void testBooleanQuery() throws Exception {
84  1 BooleanQuery query = new BooleanQuery();
85  1 query.add(new TermQuery(new Term("test", "test")), BooleanClause.Occur.MUST);
86  1 search(query);
87    }
88   
 
89  1 toggle public void testPhraseQuery() throws Exception {
90  1 PhraseQuery query = new PhraseQuery();
91  1 query.add(new Term("test", "test"));
92  1 query.add(new Term("test", "text"));
93  1 search(query);
94    }
95   
96    // Tests bug fix at http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20290
 
97  1 toggle public void testQueryFilter() throws Exception {
98    // try to search the published index
99  1 Searchable[] searchables = { getRemote() };
100  1 Searcher searcher = new MultiSearcher(searchables);
101  1 Hits hits = searcher.search(
102    new TermQuery(new Term("test", "text")),
103    new QueryFilter(new TermQuery(new Term("test", "test"))));
104  1 assertEquals(1, hits.length());
105  1 Hits nohits = searcher.search(
106    new TermQuery(new Term("test", "text")),
107    new QueryFilter(new TermQuery(new Term("test", "non-existent-term"))));
108  1 assertEquals(0, nohits.length());
109    }
110   
 
111  1 toggle public void testConstantScoreQuery() throws Exception {
112    // try to search the published index
113  1 Searchable[] searchables = { getRemote() };
114  1 Searcher searcher = new MultiSearcher(searchables);
115  1 Hits hits = searcher.search(
116    new ConstantScoreQuery(new QueryFilter(
117    new TermQuery(new Term("test", "test")))));
118  1 assertEquals(1, hits.length());
119    }
120    }