add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / instantiated / src / test / org / apache / lucene / store / instantiated / TestUnoptimizedReaderOnConstructor.java
1 package org.apache.lucene.store.instantiated;
2
3 /*
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  */
17
18 import java.io.IOException;
19
20 import org.apache.lucene.index.IndexReader;
21 import org.apache.lucene.index.IndexWriter;
22 import org.apache.lucene.index.IndexWriterConfig;
23 import org.apache.lucene.index.IndexWriterConfig.OpenMode;
24 import org.apache.lucene.store.Directory;
25 import org.apache.lucene.util.LuceneTestCase;
26 import org.apache.lucene.analysis.MockAnalyzer;
27 import org.apache.lucene.document.Document;
28 import org.apache.lucene.document.Field;
29
30 /**
31  * @since 2009-mar-30 13:15:49
32  */
33 public class TestUnoptimizedReaderOnConstructor extends LuceneTestCase {
34
35   public void test() throws Exception {
36     Directory dir = newDirectory();
37     IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
38     addDocument(iw, "Hello, world!");
39     addDocument(iw, "All work and no play makes jack a dull boy");
40     iw.close();
41
42     iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.APPEND));
43     addDocument(iw, "Hello, tellus!");
44     addDocument(iw, "All work and no play makes danny a dull boy");
45     iw.close();
46
47     iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.APPEND));
48     addDocument(iw, "Hello, earth!");
49     addDocument(iw, "All work and no play makes wendy a dull girl");
50     iw.close();
51
52     IndexReader unoptimizedReader = IndexReader.open(dir, false);
53     unoptimizedReader.deleteDocument(2);
54
55     try {
56      new InstantiatedIndex(unoptimizedReader);
57     } catch (Exception e) {
58       fail("No exceptions when loading an unoptimized reader!");
59     }
60
61     // todo some assertations.
62     unoptimizedReader.close();
63     dir.close();
64   }
65
66   private void addDocument(IndexWriter iw, String text) throws IOException {
67     Document doc = new Document();
68     doc.add(new Field("field", text, Field.Store.NO, Field.Index.ANALYZED));
69     iw.addDocument(doc);
70   }
71 }