1 package org.apache.lucene.index;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import org.apache.lucene.analysis.MockAnalyzer;
21 import org.apache.lucene.analysis.MockTokenizer;
22 import org.apache.lucene.document.Document;
23 import org.apache.lucene.document.Field;
24 import org.apache.lucene.search.IndexSearcher;
25 import org.apache.lucene.search.TermRangeQuery;
26 import org.apache.lucene.store.AlreadyClosedException;
27 import org.apache.lucene.store.Directory;
28 import org.apache.lucene.util.LuceneTestCase;
29 import org.apache.lucene.util._TestUtil;
31 public class TestReaderClosed extends LuceneTestCase {
32 private IndexSearcher searcher;
33 private IndexReader reader;
34 private Directory dir;
37 public void setUp() throws Exception {
40 RandomIndexWriter writer = new RandomIndexWriter(random, dir,
41 newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.KEYWORD, false))
42 .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000)));
44 Document doc = new Document();
45 Field field = newField("field", "", Field.Store.NO, Field.Index.NOT_ANALYZED);
48 // we generate aweful prefixes: good for testing.
49 // but for preflex codec, the test can be very slow, so use less iterations.
50 int num = atLeast(10);
51 for (int i = 0; i < num; i++) {
52 field.setValue(_TestUtil.randomUnicodeString(random, 10));
53 writer.addDocument(doc);
55 reader = writer.getReader();
56 searcher = newSearcher(reader);
60 public void test() throws Exception {
61 TermRangeQuery query = new TermRangeQuery("field", "a", "z", true, true);
62 searcher.search(query, 5);
66 searcher.search(query, 5);
67 } catch (AlreadyClosedException ace) {
72 public void tearDown() throws Exception {