~ubuntu-branches/ubuntu/trusty/pylucene/trusty

« back to all changes in this revision

Viewing changes to lucene-java-3.5.0/lucene/src/test/org/apache/lucene/index/TestReaderClosed.java

  • Committer: Package Import Robot
  • Author(s): Dmitry Nezhevenko
  • Date: 2012-04-23 16:43:55 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120423164355-grqtepnwtecdjfk2
Tags: 3.5.0-1
* New maintainer (closes: 670179)
* New upstream release
* Switch to dpkg-source 3.0 (quilt) format
* Switch to machine-readable debian/copyright
* Bump debian/compat to 8, drop debian/pycompat
* Switch from cdbs to dh
* Add watch file
* Build for all supported versions of python2 (closes: 581198, 632240)
* Rename binary package to python-lucene (closes: 581197)
* Add -dbg package

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.apache.lucene.index;
 
2
 
 
3
/**
 
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
 
10
 *
 
11
 *     http://www.apache.org/licenses/LICENSE-2.0
 
12
 *
 
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.
 
18
 */
 
19
 
 
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;
 
30
 
 
31
public class TestReaderClosed extends LuceneTestCase {
 
32
  private IndexSearcher searcher;
 
33
  private IndexReader reader;
 
34
  private Directory dir;
 
35
 
 
36
  @Override
 
37
  public void setUp() throws Exception {
 
38
    super.setUp();
 
39
    dir = newDirectory();
 
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)));
 
43
    
 
44
    Document doc = new Document();
 
45
    Field field = newField("field", "", Field.Store.NO, Field.Index.NOT_ANALYZED);
 
46
    doc.add(field);
 
47
 
 
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);
 
54
    }
 
55
    reader = writer.getReader();
 
56
    searcher = newSearcher(reader);
 
57
    writer.close();
 
58
  }
 
59
  
 
60
  public void test() throws Exception {
 
61
    TermRangeQuery query = new TermRangeQuery("field", "a", "z", true, true);
 
62
    searcher.search(query, 5);
 
63
    searcher.close();
 
64
    reader.close();
 
65
    try {
 
66
      searcher.search(query, 5);
 
67
    } catch (AlreadyClosedException ace) {
 
68
      // expected
 
69
    }
 
70
  }
 
71
  
 
72
  public void tearDown() throws Exception {
 
73
    dir.close();
 
74
    super.tearDown();
 
75
  }
 
76
}