コード例 #1
0
  public void testRefCounts1() throws IOException {
    Directory dir1 = getDir1(random());
    Directory dir2 = getDir2(random());
    LeafReader ir1, ir2;
    // close subreaders, ParallelReader will not change refCounts, but close on its own close
    ParallelLeafReader pr =
        new ParallelLeafReader(
            ir1 = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dir1)),
            ir2 = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dir2)));

    // check RefCounts
    assertEquals(1, ir1.getRefCount());
    assertEquals(1, ir2.getRefCount());
    pr.close();
    assertEquals(0, ir1.getRefCount());
    assertEquals(0, ir2.getRefCount());
    dir1.close();
    dir2.close();
  }
コード例 #2
0
  public void testIncompatibleIndexes() throws IOException {
    // two documents:
    Directory dir1 = getDir1(random());

    // one document only:
    Directory dir2 = newDirectory();
    IndexWriter w2 = new IndexWriter(dir2, newIndexWriterConfig(new MockAnalyzer(random())));
    Document d3 = new Document();

    d3.add(newTextField("f3", "v1", Field.Store.YES));
    w2.addDocument(d3);
    w2.close();

    LeafReader ir1 = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dir1));
    LeafReader ir2 = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dir2));

    try {
      new ParallelLeafReader(ir1, ir2);
      fail("didn't get exptected exception: indexes don't have same number of documents");
    } catch (IllegalArgumentException e) {
      // expected exception
    }

    try {
      new ParallelLeafReader(
          random().nextBoolean(), new LeafReader[] {ir1, ir2}, new LeafReader[] {ir1, ir2});
      fail("didn't get expected exception: indexes don't have same number of documents");
    } catch (IllegalArgumentException e) {
      // expected exception
    }
    // check RefCounts
    assertEquals(1, ir1.getRefCount());
    assertEquals(1, ir2.getRefCount());
    ir1.close();
    ir2.close();
    dir1.close();
    dir2.close();
  }
コード例 #3
0
 public void testRefCounts2() throws IOException {
   Directory dir1 = getDir1(random());
   Directory dir2 = getDir2(random());
   LeafReader ir1 = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dir1));
   LeafReader ir2 = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dir2));
   // don't close subreaders, so ParallelReader will increment refcounts
   ParallelLeafReader pr = new ParallelLeafReader(false, ir1, ir2);
   // check RefCounts
   assertEquals(2, ir1.getRefCount());
   assertEquals(2, ir2.getRefCount());
   pr.close();
   assertEquals(1, ir1.getRefCount());
   assertEquals(1, ir2.getRefCount());
   ir1.close();
   ir2.close();
   assertEquals(0, ir1.getRefCount());
   assertEquals(0, ir2.getRefCount());
   dir1.close();
   dir2.close();
 }