1 package org.apache.lucene.store.instantiated;
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 import java.io.IOException;
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;
31 * @since 2009-mar-30 13:15:49
33 public class TestUnoptimizedReaderOnConstructor extends LuceneTestCase {
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");
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");
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");
52 IndexReader unoptimizedReader = IndexReader.open(dir, false);
53 unoptimizedReader.deleteDocument(2);
56 new InstantiatedIndex(unoptimizedReader);
57 } catch (Exception e) {
58 fail("No exceptions when loading an unoptimized reader!");
61 // todo some assertations.
62 unoptimizedReader.close();
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));