org.apache.lucene.store.Directory

Here are the examples of the java api class org.apache.lucene.store.Directory taken from open source projects.

1. BaseCompoundFormatTestCase#testDoubleClose()

Project: lucene-solr
File: BaseCompoundFormatTestCase.java
// test that a second call to close() behaves according to Closeable
public void testDoubleClose() throws IOException {
    final String testfile = "_123.test";
    Directory dir = newDirectory();
    SegmentInfo si = newSegmentInfo(dir, "_123");
    try (IndexOutput out = dir.createOutput(testfile, IOContext.DEFAULT)) {
        CodecUtil.writeIndexHeader(out, "Foo", 0, si.getId(), "suffix");
        out.writeInt(3);
        CodecUtil.writeFooter(out);
    }
    si.setFiles(Collections.singleton(testfile));
    si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
    Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
    assertEquals(1, cfs.listAll().length);
    cfs.close();
    // second close should not throw exception
    cfs.close();
    dir.close();
}

2. TestDocValuesIndexing#testTypeChangeViaAddIndexesIR2()

Project: lucene-solr
File: TestDocValuesIndexing.java
public void testTypeChangeViaAddIndexesIR2() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter writer = new IndexWriter(dir, conf);
    Document doc = new Document();
    doc.add(new NumericDocValuesField("dv", 0L));
    writer.addDocument(doc);
    writer.close();
    Directory dir2 = newDirectory();
    conf = newIndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter writer2 = new IndexWriter(dir2, conf);
    DirectoryReader reader = DirectoryReader.open(dir);
    TestUtil.addIndexesSlowly(writer2, reader);
    reader.close();
    Document doc2 = new Document();
    doc2.add(new SortedDocValuesField("dv", new BytesRef("foo")));
    expectThrows(IllegalArgumentException.class, () -> {
        writer2.addDocument(doc2);
    });
    writer2.close();
    dir2.close();
    dir.close();
}

3. TestDocValuesIndexing#testTypeChangeViaAddIndexes2()

Project: lucene-solr
File: TestDocValuesIndexing.java
public void testTypeChangeViaAddIndexes2() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter writer = new IndexWriter(dir, conf);
    Document doc = new Document();
    doc.add(new NumericDocValuesField("dv", 0L));
    writer.addDocument(doc);
    writer.close();
    Directory dir2 = newDirectory();
    conf = newIndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter writer2 = new IndexWriter(dir2, conf);
    writer2.addIndexes(dir);
    Document doc2 = new Document();
    doc2.add(new SortedDocValuesField("dv", new BytesRef("foo")));
    expectThrows(IllegalArgumentException.class, () -> {
        writer2.addDocument(doc2);
    });
    writer2.close();
    dir2.close();
    dir.close();
}

4. TestDocValuesIndexing#testTypeChangeViaAddIndexes()

Project: lucene-solr
File: TestDocValuesIndexing.java
public void testTypeChangeViaAddIndexes() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter writer = new IndexWriter(dir, conf);
    Document doc = new Document();
    doc.add(new NumericDocValuesField("dv", 0L));
    writer.addDocument(doc);
    writer.close();
    Directory dir2 = newDirectory();
    conf = newIndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter writer2 = new IndexWriter(dir2, conf);
    doc = new Document();
    doc.add(new SortedDocValuesField("dv", new BytesRef("foo")));
    writer2.addDocument(doc);
    expectThrows(IllegalArgumentException.class, () -> {
        writer2.addIndexes(dir);
    });
    writer2.close();
    dir.close();
    dir2.close();
}

5. TestSearcherTaxonomyManager#testReplaceTaxonomyNRT()

Project: lucene-solr
File: TestSearcherTaxonomyManager.java
public void testReplaceTaxonomyNRT() throws Exception {
    Directory dir = newDirectory();
    Directory taxoDir = newDirectory();
    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
    DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir);
    Directory taxoDir2 = newDirectory();
    DirectoryTaxonomyWriter tw2 = new DirectoryTaxonomyWriter(taxoDir2);
    tw2.close();
    SearcherTaxonomyManager mgr = new SearcherTaxonomyManager(w, true, null, tw);
    w.addDocument(new Document());
    tw.replaceTaxonomy(taxoDir2);
    taxoDir2.close();
    expectThrows(IllegalStateException.class, () -> {
        mgr.maybeRefresh();
    });
    w.close();
    IOUtils.close(mgr, tw, taxoDir, dir);
}

6. TestOrdinalMappingLeafReader#testTaxonomyMergeUtils()

Project: lucene-solr
File: TestOrdinalMappingLeafReader.java
@Test
public void testTaxonomyMergeUtils() throws Exception {
    Directory srcIndexDir = newDirectory();
    Directory srcTaxoDir = newDirectory();
    buildIndexWithFacets(srcIndexDir, srcTaxoDir, true);
    Directory targetIndexDir = newDirectory();
    Directory targetTaxoDir = newDirectory();
    buildIndexWithFacets(targetIndexDir, targetTaxoDir, false);
    IndexWriter destIndexWriter = new IndexWriter(targetIndexDir, newIndexWriterConfig(null));
    DirectoryTaxonomyWriter destTaxoWriter = new DirectoryTaxonomyWriter(targetTaxoDir);
    try {
        TaxonomyMergeUtils.merge(srcIndexDir, srcTaxoDir, new MemoryOrdinalMap(), destIndexWriter, destTaxoWriter, facetConfig);
    } finally {
        IOUtils.close(destIndexWriter, destTaxoWriter);
    }
    verifyResults(targetIndexDir, targetTaxoDir);
    IOUtils.close(targetIndexDir, targetTaxoDir, srcIndexDir, srcTaxoDir);
}

7. TestPKIndexSplitter#checkSplitting()

Project: lucene-solr
File: TestPKIndexSplitter.java
private void checkSplitting(Directory dir, Term splitTerm, int leftCount, int rightCount) throws Exception {
    Directory dir1 = newDirectory();
    Directory dir2 = newDirectory();
    PKIndexSplitter splitter = new PKIndexSplitter(dir, dir1, dir2, splitTerm, newIndexWriterConfig(new MockAnalyzer(random())), newIndexWriterConfig(new MockAnalyzer(random())));
    splitter.split();
    IndexReader ir1 = DirectoryReader.open(dir1);
    IndexReader ir2 = DirectoryReader.open(dir2);
    assertEquals(leftCount, ir1.numDocs());
    assertEquals(rightCount, ir2.numDocs());
    checkContents(ir1, "1");
    checkContents(ir2, "2");
    ir1.close();
    ir2.close();
    dir1.close();
    dir2.close();
}

8. TestParallelLeafReader#testRefCounts2()

Project: lucene-solr
File: TestParallelLeafReader.java
public void testRefCounts2() throws IOException {
    Directory dir1 = getDir1(random());
    Directory dir2 = getDir2(random());
    LeafReader ir1 = getOnlyLeafReader(DirectoryReader.open(dir1));
    LeafReader ir2 = getOnlyLeafReader(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();
}

9. TestParallelLeafReader#testRefCounts1()

Project: lucene-solr
File: TestParallelLeafReader.java
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 = getOnlyLeafReader(DirectoryReader.open(dir1)), ir2 = getOnlyLeafReader(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();
}

10. TestParallelLeafReader#testFieldNames()

Project: lucene-solr
File: TestParallelLeafReader.java
public void testFieldNames() throws Exception {
    Directory dir1 = getDir1(random());
    Directory dir2 = getDir2(random());
    ParallelLeafReader pr = new ParallelLeafReader(getOnlyLeafReader(DirectoryReader.open(dir1)), getOnlyLeafReader(DirectoryReader.open(dir2)));
    FieldInfos fieldInfos = pr.getFieldInfos();
    assertEquals(4, fieldInfos.size());
    assertNotNull(fieldInfos.fieldInfo("f1"));
    assertNotNull(fieldInfos.fieldInfo("f2"));
    assertNotNull(fieldInfos.fieldInfo("f3"));
    assertNotNull(fieldInfos.fieldInfo("f4"));
    pr.close();
    dir1.close();
    dir2.close();
}

11. TestParallelCompositeReader#testIncompatibleIndexes2()

Project: lucene-solr
File: TestParallelCompositeReader.java
public void testIncompatibleIndexes2() throws IOException {
    Directory dir1 = getDir1(random());
    Directory dir2 = getInvalidStructuredDir2(random());
    DirectoryReader ir1 = DirectoryReader.open(dir1), ir2 = DirectoryReader.open(dir2);
    CompositeReader[] readers = new CompositeReader[] { ir1, ir2 };
    expectThrows(IllegalArgumentException.class, () -> {
        new ParallelCompositeReader(readers);
    });
    expectThrows(IllegalArgumentException.class, () -> {
        new ParallelCompositeReader(random().nextBoolean(), readers, readers);
    });
    assertEquals(1, ir1.getRefCount());
    assertEquals(1, ir2.getRefCount());
    ir1.close();
    ir2.close();
    assertEquals(0, ir1.getRefCount());
    assertEquals(0, ir2.getRefCount());
    dir1.close();
    dir2.close();
}

12. TestParallelCompositeReader#testRefCounts2()

Project: lucene-solr
File: TestParallelCompositeReader.java
public void testRefCounts2() throws IOException {
    Directory dir1 = getDir1(random());
    Directory dir2 = getDir2(random());
    DirectoryReader ir1 = DirectoryReader.open(dir1);
    DirectoryReader ir2 = DirectoryReader.open(dir2);
    // don't close subreaders, so ParallelReader will increment refcounts
    ParallelCompositeReader pr = new ParallelCompositeReader(false, ir1, ir2);
    IndexReader psub1 = pr.getSequentialSubReaders().get(0);
    // check RefCounts
    assertEquals(2, ir1.getRefCount());
    assertEquals(2, ir2.getRefCount());
    assertEquals("refCount must be 1, as the synthetic reader was created by ParallelCompositeReader", 1, psub1.getRefCount());
    pr.close();
    assertEquals(1, ir1.getRefCount());
    assertEquals(1, ir2.getRefCount());
    assertEquals("refcount must be 0 because parent was closed", 0, psub1.getRefCount());
    ir1.close();
    ir2.close();
    assertEquals(0, ir1.getRefCount());
    assertEquals(0, ir2.getRefCount());
    assertEquals("refcount should not change anymore", 0, psub1.getRefCount());
    dir1.close();
    dir2.close();
}

13. TestParallelCompositeReader#testRefCounts1()

Project: lucene-solr
File: TestParallelCompositeReader.java
public void testRefCounts1() throws IOException {
    Directory dir1 = getDir1(random());
    Directory dir2 = getDir2(random());
    DirectoryReader ir1, ir2;
    // close subreaders, ParallelReader will not change refCounts, but close on its own close
    ParallelCompositeReader pr = new ParallelCompositeReader(ir1 = DirectoryReader.open(dir1), ir2 = DirectoryReader.open(dir2));
    IndexReader psub1 = pr.getSequentialSubReaders().get(0);
    // check RefCounts
    assertEquals(1, ir1.getRefCount());
    assertEquals(1, ir2.getRefCount());
    assertEquals(1, psub1.getRefCount());
    pr.close();
    assertEquals(0, ir1.getRefCount());
    assertEquals(0, ir2.getRefCount());
    assertEquals(0, psub1.getRefCount());
    dir1.close();
    dir2.close();
}

14. TestTermVectors#testFullMergeAddIndexesReader()

Project: lucene-solr
File: TestTermVectors.java
public void testFullMergeAddIndexesReader() throws Exception {
    Directory[] input = new Directory[] { newDirectory(), newDirectory() };
    Directory target = newDirectory();
    for (Directory dir : input) {
        createDir(dir);
    }
    IndexWriter writer = createWriter(target);
    for (Directory dir : input) {
        DirectoryReader r = DirectoryReader.open(dir);
        TestUtil.addIndexesSlowly(writer, r);
        r.close();
    }
    writer.forceMerge(1);
    writer.close();
    verifyIndex(target);
    IOUtils.close(target, input[0], input[1]);
}

15. TestSwappedIndexFiles#test()

Project: lucene-solr
File: TestSwappedIndexFiles.java
public void test() throws Exception {
    Directory dir1 = newDirectory();
    Directory dir2 = newDirectory();
    // Disable CFS 80% of the time so we can truncate individual files, but the other 20% of the time we test truncation of .cfs/.cfe too:
    boolean useCFS = random().nextInt(5) == 1;
    // Use LineFileDocs so we (hopefully) get most Lucene features
    // tested, e.g. IntPoint was recently added to it:
    LineFileDocs docs = new LineFileDocs(random());
    Document doc = docs.nextDoc();
    long seed = random().nextLong();
    indexOneDoc(seed, dir1, doc, useCFS);
    indexOneDoc(seed, dir2, doc, useCFS);
    swapFiles(dir1, dir2);
    dir1.close();
    dir2.close();
}

16. TestStressIndexing2#testRandom()

Project: lucene-solr
File: TestStressIndexing2.java
public void testRandom() throws Throwable {
    Directory dir1 = newMaybeVirusCheckingDirectory();
    Directory dir2 = newMaybeVirusCheckingDirectory();
    // mergeFactor=2; maxBufferedDocs=2; Map docs = indexRandom(1, 3, 2, dir1);
    boolean doReaderPooling = random().nextBoolean();
    Map<String, Document> docs = indexRandom(5, 3, 100, dir1, doReaderPooling);
    indexSerial(random(), docs, dir2);
    // verifying verify
    // verifyEquals(dir1, dir1, "id");
    // verifyEquals(dir2, dir2, "id");
    verifyEquals(dir1, dir2, "id");
    dir1.close();
    dir2.close();
}

17. BaseCompoundFormatTestCase#testResourceNameInsideCompoundFile()

Project: lucene-solr
File: BaseCompoundFormatTestCase.java
// LUCENE-6311: make sure the resource name inside a compound file confesses that it's inside a compound file
public void testResourceNameInsideCompoundFile() throws Exception {
    Directory dir = newDirectory();
    String subFile = "_123.xyz";
    SegmentInfo si = newSegmentInfo(dir, "_123");
    createSequenceFile(dir, subFile, (byte) 0, 10, si.getId(), "suffix");
    si.setFiles(Collections.singletonList(subFile));
    si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
    Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
    IndexInput in = cfs.openInput(subFile, IOContext.DEFAULT);
    String desc = in.toString();
    assertTrue("resource description hides that it's inside a compound file: " + desc, desc.contains("[slice=" + subFile + "]"));
    cfs.close();
    dir.close();
}

18. BaseCompoundFormatTestCase#testReadPastEOF()

Project: lucene-solr
File: BaseCompoundFormatTestCase.java
public void testReadPastEOF() throws IOException {
    Directory dir = newDirectory();
    Directory cr = createLargeCFS(dir);
    IndexInput is = cr.openInput("_123.f2", newIOContext(random()));
    is.seek(is.length() - 10);
    byte b[] = new byte[100];
    is.readBytes(b, 0, 10);
    // Single byte read past end of file
    expectThrows(IOException.class, () -> {
        is.readByte();
    });
    is.seek(is.length() - 10);
    // Block read past end of file
    expectThrows(IOException.class, () -> {
        is.readBytes(b, 0, 50);
    });
    is.close();
    cr.close();
    dir.close();
}

19. BaseCompoundFormatTestCase#testFileNotFound()

Project: lucene-solr
File: BaseCompoundFormatTestCase.java
public void testFileNotFound() throws IOException {
    Directory dir = newDirectory();
    Directory cr = createLargeCFS(dir);
    // Open bogus file
    expectThrows(IOException.class, () -> {
        cr.openInput("bogus", newIOContext(random()));
    });
    cr.close();
    dir.close();
}

20. BaseCompoundFormatTestCase#testClonedStreamsClosing()

Project: lucene-solr
File: BaseCompoundFormatTestCase.java
public void testClonedStreamsClosing() throws IOException {
    Directory dir = newDirectory();
    Directory cr = createLargeCFS(dir);
    // basic clone
    IndexInput expected = dir.openInput("_123.f11", newIOContext(random()));
    IndexInput one = cr.openInput("_123.f11", newIOContext(random()));
    IndexInput two = one.clone();
    assertSameStreams("basic clone one", expected, one);
    expected.seek(0);
    assertSameStreams("basic clone two", expected, two);
    // Now close the compound reader
    cr.close();
    expected.close();
    dir.close();
}

21. BaseCompoundFormatTestCase#testMakeLockDisabled()

Project: lucene-solr
File: BaseCompoundFormatTestCase.java
// test that cfs reader is read-only
public void testMakeLockDisabled() throws IOException {
    final String testfile = "_123.test";
    Directory dir = newDirectory();
    IndexOutput out = dir.createOutput(testfile, IOContext.DEFAULT);
    out.writeInt(3);
    out.close();
    SegmentInfo si = newSegmentInfo(dir, "_123");
    si.setFiles(Collections.emptyList());
    si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
    Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
    expectThrows(UnsupportedOperationException.class, () -> {
        cfs.obtainLock("foobar");
    });
    cfs.close();
    dir.close();
}

22. BaseCompoundFormatTestCase#testSyncDisabled()

Project: lucene-solr
File: BaseCompoundFormatTestCase.java
// test that cfs reader is read-only
public void testSyncDisabled() throws IOException {
    final String testfile = "_123.test";
    Directory dir = newDirectory();
    IndexOutput out = dir.createOutput(testfile, IOContext.DEFAULT);
    out.writeInt(3);
    out.close();
    SegmentInfo si = newSegmentInfo(dir, "_123");
    si.setFiles(Collections.emptyList());
    si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
    Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
    expectThrows(UnsupportedOperationException.class, () -> {
        cfs.sync(Collections.singleton(testfile));
    });
    cfs.close();
    dir.close();
}

23. BaseCompoundFormatTestCase#testRenameFileDisabled()

Project: lucene-solr
File: BaseCompoundFormatTestCase.java
// test that cfs reader is read-only
public void testRenameFileDisabled() throws IOException {
    final String testfile = "_123.test";
    Directory dir = newDirectory();
    IndexOutput out = dir.createOutput(testfile, IOContext.DEFAULT);
    out.writeInt(3);
    out.close();
    SegmentInfo si = newSegmentInfo(dir, "_123");
    si.setFiles(Collections.emptyList());
    si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
    Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
    expectThrows(UnsupportedOperationException.class, () -> {
        cfs.rename(testfile, "bogus");
    });
    cfs.close();
    dir.close();
}

24. BaseCompoundFormatTestCase#testDeleteFileDisabled()

Project: lucene-solr
File: BaseCompoundFormatTestCase.java
// test that cfs reader is read-only
public void testDeleteFileDisabled() throws IOException {
    final String testfile = "_123.test";
    Directory dir = newDirectory();
    IndexOutput out = dir.createOutput(testfile, IOContext.DEFAULT);
    out.writeInt(3);
    out.close();
    SegmentInfo si = newSegmentInfo(dir, "_123");
    si.setFiles(Collections.emptyList());
    si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
    Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
    expectThrows(UnsupportedOperationException.class, () -> {
        cfs.deleteFile(testfile);
    });
    cfs.close();
    dir.close();
}

25. BaseCompoundFormatTestCase#testCreateOutputDisabled()

Project: lucene-solr
File: BaseCompoundFormatTestCase.java
// test that cfs reader is read-only
public void testCreateOutputDisabled() throws IOException {
    Directory dir = newDirectory();
    SegmentInfo si = newSegmentInfo(dir, "_123");
    si.setFiles(Collections.emptyList());
    si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
    Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
    expectThrows(UnsupportedOperationException.class, () -> {
        cfs.createOutput("bogus", IOContext.DEFAULT);
    });
    cfs.close();
    dir.close();
}

26. BaseCompoundFormatTestCase#testTwoFiles()

Project: lucene-solr
File: BaseCompoundFormatTestCase.java
/** 
   * This test creates compound file based on two files.
   */
public void testTwoFiles() throws IOException {
    String files[] = { "_123.d1", "_123.d2" };
    Directory dir = newDirectory();
    SegmentInfo si = newSegmentInfo(dir, "_123");
    createSequenceFile(dir, files[0], (byte) 0, 15, si.getId(), "suffix");
    createSequenceFile(dir, files[1], (byte) 0, 114, si.getId(), "suffix");
    si.setFiles(Arrays.asList(files));
    si.getCodec().compoundFormat().write(dir, si, IOContext.DEFAULT);
    Directory cfs = si.getCodec().compoundFormat().getCompoundReader(dir, si, IOContext.DEFAULT);
    for (String file : files) {
        IndexInput expected = dir.openInput(file, newIOContext(random()));
        IndexInput actual = cfs.openInput(file, newIOContext(random()));
        assertSameStreams(file, expected, actual);
        assertSameSeekBehavior(file, expected, actual);
        expected.close();
        actual.close();
    }
    cfs.close();
    dir.close();
}

27. RAMDirectoryFactoryTest#dotestOpenReturnsTheSameForSamePath()

Project: lucene-solr
File: RAMDirectoryFactoryTest.java
private void dotestOpenReturnsTheSameForSamePath() throws IOException {
    final Directory directory = new RAMDirectory();
    RAMDirectoryFactory factory = new RAMDirectoryFactory() {

        @Override
        protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) {
            return directory;
        }
    };
    String path = "/fake/path";
    Directory dir1 = factory.get(path, DirContext.DEFAULT, DirectoryFactory.LOCK_TYPE_SINGLE);
    Directory dir2 = factory.get(path, DirContext.DEFAULT, DirectoryFactory.LOCK_TYPE_SINGLE);
    assertEquals("RAMDirectoryFactory should not create new instance of RefCntRamDirectory " + "every time open() is called for the same path", dir1, dir2);
    factory.release(dir1);
    factory.release(dir2);
    factory.close();
}

28. TestTermVectors#testFullMergeAddIndexesDir()

Project: lucene-solr
File: TestTermVectors.java
public void testFullMergeAddIndexesDir() throws Exception {
    Directory[] input = new Directory[] { newDirectory(), newDirectory() };
    Directory target = newDirectory();
    for (Directory dir : input) {
        createDir(dir);
    }
    IndexWriter writer = createWriter(target);
    writer.addIndexes(input);
    writer.forceMerge(1);
    writer.close();
    verifyIndex(target);
    IOUtils.close(target, input[0], input[1]);
}

29. IndexCopierTest#wrapForWriteWithIndexPath()

Project: jackrabbit-oak
File: IndexCopierTest.java
@Test
public void wrapForWriteWithIndexPath() throws Exception {
    assumeNotWindows();
    Directory remote = new CloseSafeDir();
    IndexCopier copier = new IndexCopier(sameThreadExecutor(), getWorkDir());
    builder.setProperty(IndexConstants.INDEX_PATH, "foo");
    IndexDefinition defn = new IndexDefinition(root, builder.getNodeState());
    Directory dir = copier.wrapForWrite(defn, remote, false);
    byte[] t1 = writeFile(dir, "t1");
    dir.close();
    readAndAssert(remote, "t1", t1);
    //Work dir must be empty post close
    File indexDir = copier.getIndexDir(defn, "foo");
    List<File> files = new ArrayList<File>(FileUtils.listFiles(indexDir, null, true));
    Set<String> fileNames = Sets.newHashSet();
    for (File f : files) {
        fileNames.add(f.getName());
    }
    assertThat(fileNames, contains("t1"));
}

30. IndexCopierTest#wrapForWriteWithoutIndexPath()

Project: jackrabbit-oak
File: IndexCopierTest.java
@Test
public void wrapForWriteWithoutIndexPath() throws Exception {
    assumeNotWindows();
    Directory remote = new CloseSafeDir();
    IndexCopier copier = new IndexCopier(sameThreadExecutor(), getWorkDir());
    IndexDefinition defn = new IndexDefinition(root, builder.getNodeState());
    Directory dir = copier.wrapForWrite(defn, remote, false);
    byte[] t1 = writeFile(dir, "t1");
    dir.close();
    readAndAssert(remote, "t1", t1);
    //Work dir must be empty post close
    assertArrayEquals(FileUtils.EMPTY_FILE_ARRAY, copier.getIndexWorkDir().listFiles());
}

31. IndexCopierTest#nonExistentFile()

Project: jackrabbit-oak
File: IndexCopierTest.java
@Test
public void nonExistentFile() throws Exception {
    Directory baseDir = new RAMDirectory();
    IndexDefinition defn = new IndexDefinition(root, builder.getNodeState());
    CollectingExecutor executor = new CollectingExecutor();
    IndexCopier c1 = new RAMIndexCopier(baseDir, executor, getWorkDir(), true);
    Directory remote = new RAMDirectory();
    Directory wrapped = c1.wrapForRead("/foo", defn, remote);
    try {
        wrapped.openInput("foo.txt", IOContext.DEFAULT);
        fail();
    } catch (FileNotFoundException ignore) {
    }
    assertEquals(0, executor.commands.size());
}

32. IndexCopierTest#basicTest()

Project: jackrabbit-oak
File: IndexCopierTest.java
@Test
public void basicTest() throws Exception {
    Directory baseDir = new RAMDirectory();
    IndexDefinition defn = new IndexDefinition(root, builder.getNodeState());
    IndexCopier c1 = new RAMIndexCopier(baseDir, sameThreadExecutor(), getWorkDir());
    Directory remote = new RAMDirectory();
    Directory wrapped = c1.wrapForRead("/foo", defn, remote);
    byte[] t1 = writeFile(remote, "t1");
    byte[] t2 = writeFile(remote, "t2");
    assertEquals(2, wrapped.listAll().length);
    assertTrue(wrapped.fileExists("t1"));
    assertTrue(wrapped.fileExists("t2"));
    assertEquals(t1.length, wrapped.fileLength("t1"));
    assertEquals(t2.length, wrapped.fileLength("t2"));
    readAndAssert(wrapped, "t1", t1);
    //t1 should now be added to testDir
    assertTrue(baseDir.fileExists("t1"));
}

33. TestMixedDirectory#testMixedDirectoryAndPolicy()

Project: hadoop-mapreduce
File: TestMixedDirectory.java
public void testMixedDirectoryAndPolicy() throws IOException {
    Directory readDir = new RAMDirectory();
    updateIndex(readDir, 0, numDocsPerUpdate, new KeepOnlyLastCommitDeletionPolicy());
    verify(readDir, numDocsPerUpdate);
    IndexOutput out = readDir.createOutput("_" + (numDocsPerUpdate / maxBufferedDocs + 2) + ".cfs");
    out.writeInt(0);
    out.close();
    Directory writeDir = new RAMDirectory();
    Directory mixedDir = new MixedDirectory(readDir, writeDir);
    updateIndex(mixedDir, numDocsPerUpdate, numDocsPerUpdate, new MixedDeletionPolicy());
    verify(readDir, numDocsPerUpdate);
    verify(mixedDir, 2 * numDocsPerUpdate);
}

34. TestMixedDirectory#testMixedDirectoryAndPolicy()

Project: hadoop-common
File: TestMixedDirectory.java
public void testMixedDirectoryAndPolicy() throws IOException {
    Directory readDir = new RAMDirectory();
    updateIndex(readDir, 0, numDocsPerUpdate, new KeepOnlyLastCommitDeletionPolicy());
    verify(readDir, numDocsPerUpdate);
    IndexOutput out = readDir.createOutput("_" + (numDocsPerUpdate / maxBufferedDocs + 2) + ".cfs");
    out.writeInt(0);
    out.close();
    Directory writeDir = new RAMDirectory();
    Directory mixedDir = new MixedDirectory(readDir, writeDir);
    updateIndex(mixedDir, numDocsPerUpdate, numDocsPerUpdate, new MixedDeletionPolicy());
    verify(readDir, numDocsPerUpdate);
    verify(mixedDir, 2 * numDocsPerUpdate);
}

35. TestMixedDirectory#testMixedDirectoryAndPolicy()

Project: hadoop-20
File: TestMixedDirectory.java
public void testMixedDirectoryAndPolicy() throws IOException {
    Directory readDir = new RAMDirectory();
    updateIndex(readDir, 0, numDocsPerUpdate, new KeepOnlyLastCommitDeletionPolicy());
    verify(readDir, numDocsPerUpdate);
    IndexOutput out = readDir.createOutput("_" + (numDocsPerUpdate / maxBufferedDocs + 2) + ".cfs");
    out.writeInt(0);
    out.close();
    Directory writeDir = new RAMDirectory();
    Directory mixedDir = new MixedDirectory(readDir, writeDir);
    updateIndex(mixedDir, numDocsPerUpdate, numDocsPerUpdate, new MixedDeletionPolicy());
    verify(readDir, numDocsPerUpdate);
    verify(mixedDir, 2 * numDocsPerUpdate);
}

36. TestPointValues#testPointsFieldMissingFromOneSegment()

Project: lucene-solr
File: TestPointValues.java
public void testPointsFieldMissingFromOneSegment() throws Exception {
    Directory dir = FSDirectory.open(createTempDir());
    IndexWriterConfig iwc = new IndexWriterConfig(null);
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new StringField("id", "0", Field.Store.NO));
    doc.add(new IntPoint("int0", 0));
    w.addDocument(doc);
    w.commit();
    doc = new Document();
    doc.add(new IntPoint("int1", 17));
    w.addDocument(doc);
    w.forceMerge(1);
    w.close();
    dir.close();
}

37. TestPointValues#testDeleteAllPointDocs()

Project: lucene-solr
File: TestPointValues.java
public void testDeleteAllPointDocs() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = newIndexWriterConfig();
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new StringField("id", "0", Field.Store.NO));
    doc.add(new IntPoint("int", 17));
    w.addDocument(doc);
    w.addDocument(new Document());
    w.commit();
    w.deleteDocuments(new Term("id", "0"));
    w.forceMerge(1);
    DirectoryReader r = w.getReader();
    assertEquals(0, r.leaves().get(0).reader().getPointValues().size("int"));
    assertEquals(0, r.leaves().get(0).reader().getPointValues().getDocCount("int"));
    w.close();
    r.close();
    dir.close();
}

38. TestPointValues#testDifferentCodecs2()

Project: lucene-solr
File: TestPointValues.java
// Write point values, one segment with Lucene62, another with SimpleText, then forceMerge with Lucene60
public void testDifferentCodecs2() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    iwc.setCodec(Codec.forName("SimpleText"));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new IntPoint("int", 1));
    w.addDocument(doc);
    w.close();
    iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    iwc.setCodec(Codec.forName("Lucene62"));
    w = new IndexWriter(dir, iwc);
    doc = new Document();
    doc.add(new IntPoint("int", 1));
    w.addDocument(doc);
    w.forceMerge(1);
    w.close();
    dir.close();
}

39. TestPointValues#testDifferentCodecs1()

Project: lucene-solr
File: TestPointValues.java
// Write point values, one segment with Lucene62, another with SimpleText, then forceMerge with SimpleText
public void testDifferentCodecs1() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    iwc.setCodec(Codec.forName("Lucene62"));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new IntPoint("int", 1));
    w.addDocument(doc);
    w.close();
    iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    iwc.setCodec(Codec.forName("SimpleText"));
    w = new IndexWriter(dir, iwc);
    doc = new Document();
    doc.add(new IntPoint("int", 1));
    w.addDocument(doc);
    w.forceMerge(1);
    w.close();
    dir.close();
}

40. TestPointValues#testIllegalTooManyDimensions()

Project: lucene-solr
File: TestPointValues.java
public void testIllegalTooManyDimensions() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    byte[][] values = new byte[PointValues.MAX_DIMENSIONS + 1][];
    for (int i = 0; i < values.length; i++) {
        values[i] = new byte[4];
    }
    expectThrows(IllegalArgumentException.class, () -> {
        doc.add(new BinaryPoint("dim", values));
    });
    Document doc2 = new Document();
    doc2.add(new IntPoint("dim", 17));
    w.addDocument(doc2);
    w.close();
    dir.close();
}

41. TestPointValues#testIllegalTooManyBytes()

Project: lucene-solr
File: TestPointValues.java
public void testIllegalTooManyBytes() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[PointValues.MAX_NUM_BYTES + 1]));
    expectThrows(IllegalArgumentException.class, () -> {
        w.addDocument(doc);
    });
    Document doc2 = new Document();
    doc2.add(new IntPoint("dim", 17));
    w.addDocument(doc2);
    w.close();
    dir.close();
}

42. TestPointValues#testIllegalNumBytesChangeViaAddIndexesSlowCodecReader()

Project: lucene-solr
File: TestPointValues.java
public void testIllegalNumBytesChangeViaAddIndexesSlowCodecReader() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4]));
    w.addDocument(doc);
    w.close();
    Directory dir2 = newDirectory();
    iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w2 = new IndexWriter(dir2, iwc);
    doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[6]));
    w2.addDocument(doc);
    DirectoryReader r = DirectoryReader.open(dir);
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        TestUtil.addIndexesSlowly(w2, r);
    });
    assertEquals("cannot change point numBytes from 6 to 4 for field=\"dim\"", expected.getMessage());
    IOUtils.close(r, w2, dir, dir2);
}

43. TestPointValues#testIllegalNumBytesChangeViaAddIndexesCodecReader()

Project: lucene-solr
File: TestPointValues.java
public void testIllegalNumBytesChangeViaAddIndexesCodecReader() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4]));
    w.addDocument(doc);
    w.close();
    Directory dir2 = newDirectory();
    iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w2 = new IndexWriter(dir2, iwc);
    doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[6]));
    w2.addDocument(doc);
    DirectoryReader r = DirectoryReader.open(dir);
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        w2.addIndexes(new CodecReader[] { (CodecReader) getOnlyLeafReader(r) });
    });
    assertEquals("cannot change point numBytes from 6 to 4 for field=\"dim\"", expected.getMessage());
    IOUtils.close(r, w2, dir, dir2);
}

44. TestPointValues#testIllegalNumBytesChangeViaAddIndexesDirectory()

Project: lucene-solr
File: TestPointValues.java
public void testIllegalNumBytesChangeViaAddIndexesDirectory() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4]));
    w.addDocument(doc);
    w.close();
    Directory dir2 = newDirectory();
    iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w2 = new IndexWriter(dir2, iwc);
    doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[6]));
    w2.addDocument(doc);
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        w2.addIndexes(new Directory[] { dir });
    });
    assertEquals("cannot change point numBytes from 6 to 4 for field=\"dim\"", expected.getMessage());
    IOUtils.close(w2, dir, dir2);
}

45. TestPointValues#testIllegalNumBytesChangeTwoWriters()

Project: lucene-solr
File: TestPointValues.java
public void testIllegalNumBytesChangeTwoWriters() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4]));
    w.addDocument(doc);
    w.close();
    iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w2 = new IndexWriter(dir, iwc);
    Document doc2 = new Document();
    doc2.add(new BinaryPoint("dim", new byte[6]));
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        w2.addDocument(doc2);
    });
    assertEquals("cannot change point numBytes from 4 to 6 for field=\"dim\"", expected.getMessage());
    w2.close();
    dir.close();
}

46. TestPointValues#testIllegalNumBytesChangeTwoSegments()

Project: lucene-solr
File: TestPointValues.java
public void testIllegalNumBytesChangeTwoSegments() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4]));
    w.addDocument(doc);
    w.commit();
    Document doc2 = new Document();
    doc2.add(new BinaryPoint("dim", new byte[6]));
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        w.addDocument(doc2);
    });
    assertEquals("cannot change point numBytes from 4 to 6 for field=\"dim\"", expected.getMessage());
    w.close();
    dir.close();
}

47. TestPointValues#testIllegalNumBytesChangeTwoDocs()

Project: lucene-solr
File: TestPointValues.java
public void testIllegalNumBytesChangeTwoDocs() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4]));
    w.addDocument(doc);
    Document doc2 = new Document();
    doc2.add(new BinaryPoint("dim", new byte[6]));
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        w.addDocument(doc2);
    });
    assertEquals("cannot change point numBytes from 4 to 6 for field=\"dim\"", expected.getMessage());
    w.close();
    dir.close();
}

48. TestPointValues#testIllegalNumBytesChangeOneDoc()

Project: lucene-solr
File: TestPointValues.java
public void testIllegalNumBytesChangeOneDoc() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4]));
    doc.add(new BinaryPoint("dim", new byte[6]));
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        w.addDocument(doc);
    });
    assertEquals("cannot change point numBytes from 4 to 6 for field=\"dim\"", expected.getMessage());
    w.close();
    dir.close();
}

49. TestPointValues#testIllegalDimChangeViaAddIndexesSlowCodecReader()

Project: lucene-solr
File: TestPointValues.java
public void testIllegalDimChangeViaAddIndexesSlowCodecReader() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4]));
    w.addDocument(doc);
    w.close();
    Directory dir2 = newDirectory();
    iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w2 = new IndexWriter(dir2, iwc);
    doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4], new byte[4]));
    w2.addDocument(doc);
    DirectoryReader r = DirectoryReader.open(dir);
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        TestUtil.addIndexesSlowly(w2, r);
    });
    assertEquals("cannot change point dimension count from 2 to 1 for field=\"dim\"", expected.getMessage());
    IOUtils.close(r, w2, dir, dir2);
}

50. TestPointValues#testIllegalDimChangeViaAddIndexesCodecReader()

Project: lucene-solr
File: TestPointValues.java
public void testIllegalDimChangeViaAddIndexesCodecReader() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4]));
    w.addDocument(doc);
    w.close();
    Directory dir2 = newDirectory();
    IndexWriter w2 = new IndexWriter(dir2, new IndexWriterConfig(new MockAnalyzer(random())));
    doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4], new byte[4]));
    w2.addDocument(doc);
    DirectoryReader r = DirectoryReader.open(dir);
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        w2.addIndexes(new CodecReader[] { (CodecReader) getOnlyLeafReader(r) });
    });
    assertEquals("cannot change point dimension count from 2 to 1 for field=\"dim\"", expected.getMessage());
    IOUtils.close(r, w2, dir, dir2);
}

51. TestPointValues#testIllegalDimChangeViaAddIndexesDirectory()

Project: lucene-solr
File: TestPointValues.java
public void testIllegalDimChangeViaAddIndexesDirectory() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4]));
    w.addDocument(doc);
    w.close();
    Directory dir2 = newDirectory();
    IndexWriter w2 = new IndexWriter(dir2, new IndexWriterConfig(new MockAnalyzer(random())));
    doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4], new byte[4]));
    w2.addDocument(doc);
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        w2.addIndexes(new Directory[] { dir });
    });
    assertEquals("cannot change point dimension count from 2 to 1 for field=\"dim\"", expected.getMessage());
    IOUtils.close(w2, dir, dir2);
}

52. TestPointValues#testIllegalDimChangeTwoWriters()

Project: lucene-solr
File: TestPointValues.java
public void testIllegalDimChangeTwoWriters() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4]));
    w.addDocument(doc);
    w.close();
    iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w2 = new IndexWriter(dir, iwc);
    Document doc2 = new Document();
    doc2.add(new BinaryPoint("dim", new byte[4], new byte[4]));
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        w2.addDocument(doc2);
    });
    assertEquals("cannot change point dimension count from 1 to 2 for field=\"dim\"", expected.getMessage());
    w2.close();
    dir.close();
}

53. TestPointValues#testIllegalDimChangeTwoSegments()

Project: lucene-solr
File: TestPointValues.java
public void testIllegalDimChangeTwoSegments() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4]));
    w.addDocument(doc);
    w.commit();
    Document doc2 = new Document();
    doc2.add(new BinaryPoint("dim", new byte[4], new byte[4]));
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        w.addDocument(doc2);
    });
    assertEquals("cannot change point dimension count from 1 to 2 for field=\"dim\"", expected.getMessage());
    w.close();
    dir.close();
}

54. TestPointValues#testIllegalDimChangeTwoDocs()

Project: lucene-solr
File: TestPointValues.java
public void testIllegalDimChangeTwoDocs() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4]));
    w.addDocument(doc);
    Document doc2 = new Document();
    doc2.add(new BinaryPoint("dim", new byte[4], new byte[4]));
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        w.addDocument(doc2);
    });
    assertEquals("cannot change point dimension count from 1 to 2 for field=\"dim\"", expected.getMessage());
    w.close();
    dir.close();
}

55. TestPointValues#testIllegalDimChangeOneDoc()

Project: lucene-solr
File: TestPointValues.java
// Illegal schema change tests:
public void testIllegalDimChangeOneDoc() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new BinaryPoint("dim", new byte[4]));
    doc.add(new BinaryPoint("dim", new byte[4], new byte[4]));
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        w.addDocument(doc);
    });
    assertEquals("cannot change point dimension count from 1 to 2 for field=\"dim\"", expected.getMessage());
    w.close();
    dir.close();
}

56. TestPointValues#testUpgradeFieldToPoints()

Project: lucene-solr
File: TestPointValues.java
// Suddenly add points to an existing field:
public void testUpgradeFieldToPoints() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = newIndexWriterConfig();
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(newStringField("dim", "foo", Field.Store.NO));
    w.addDocument(doc);
    w.close();
    iwc = newIndexWriterConfig();
    w = new IndexWriter(dir, iwc);
    doc.add(new BinaryPoint("dim", new byte[4]));
    w.close();
    dir.close();
}

57. TestPersistentSnapshotDeletionPolicy#testSnapshotReleaseByGeneration()

Project: lucene-solr
File: TestPersistentSnapshotDeletionPolicy.java
@Test
public void testSnapshotReleaseByGeneration() throws Exception {
    Directory dir = newDirectory();
    IndexWriter writer = new IndexWriter(dir, getConfig(random(), getDeletionPolicy(dir)));
    PersistentSnapshotDeletionPolicy psdp = (PersistentSnapshotDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
    prepareIndexAndSnapshots(psdp, writer, 1);
    writer.close();
    psdp.release(snapshots.get(0).getGeneration());
    psdp = new PersistentSnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy(), dir, OpenMode.APPEND);
    assertEquals("Should have no snapshots !", 0, psdp.getSnapshotCount());
    dir.close();
}

58. TestPersistentSnapshotDeletionPolicy#testSnapshotRelease()

Project: lucene-solr
File: TestPersistentSnapshotDeletionPolicy.java
@Test
public void testSnapshotRelease() throws Exception {
    Directory dir = newDirectory();
    IndexWriter writer = new IndexWriter(dir, getConfig(random(), getDeletionPolicy(dir)));
    PersistentSnapshotDeletionPolicy psdp = (PersistentSnapshotDeletionPolicy) writer.getConfig().getIndexDeletionPolicy();
    prepareIndexAndSnapshots(psdp, writer, 1);
    writer.close();
    psdp.release(snapshots.get(0));
    psdp = new PersistentSnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy(), dir, OpenMode.APPEND);
    assertEquals("Should have no snapshots !", 0, psdp.getSnapshotCount());
    dir.close();
}

59. TestPayloadsOnVectors#testPayloadsWithoutPositions()

Project: lucene-solr
File: TestPayloadsOnVectors.java
public void testPayloadsWithoutPositions() throws Exception {
    Directory dir = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
    Document doc = new Document();
    FieldType customType = new FieldType(TextField.TYPE_NOT_STORED);
    customType.setStoreTermVectors(true);
    customType.setStoreTermVectorPositions(false);
    customType.setStoreTermVectorPayloads(true);
    customType.setStoreTermVectorOffsets(random().nextBoolean());
    doc.add(new Field("field", "foo", customType));
    expectThrows(IllegalArgumentException.class, () -> {
        writer.addDocument(doc);
    });
    writer.close();
    dir.close();
}

60. TestPayloads#testAcrossFields()

Project: lucene-solr
File: TestPayloads.java
public void testAcrossFields() throws Exception {
    Directory dir = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), dir, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, true));
    Document doc = new Document();
    doc.add(new TextField("hasMaybepayload", "here we go", Field.Store.YES));
    writer.addDocument(doc);
    writer.close();
    writer = new RandomIndexWriter(random(), dir, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, true));
    doc = new Document();
    doc.add(new TextField("hasMaybepayload2", "here we go", Field.Store.YES));
    writer.addDocument(doc);
    writer.addDocument(doc);
    writer.forceMerge(1);
    writer.close();
    dir.close();
}

61. TestParallelLeafReader#testWithIndexSort2()

Project: lucene-solr
File: TestParallelLeafReader.java
// ok to have one leaf w/ index sort and the other with no sort
public void testWithIndexSort2() throws Exception {
    Directory dir1 = newDirectory();
    IndexWriterConfig iwc1 = newIndexWriterConfig(new MockAnalyzer(random()));
    iwc1.setIndexSort(new Sort(new SortField("foo", SortField.Type.INT)));
    IndexWriter w1 = new IndexWriter(dir1, iwc1);
    w1.addDocument(new Document());
    w1.commit();
    w1.addDocument(new Document());
    w1.forceMerge(1);
    w1.close();
    IndexReader r1 = DirectoryReader.open(dir1);
    Directory dir2 = newDirectory();
    IndexWriterConfig iwc2 = newIndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w2 = new IndexWriter(dir2, iwc2);
    w2.addDocument(new Document());
    w2.addDocument(new Document());
    w2.close();
    IndexReader r2 = DirectoryReader.open(dir2);
    new ParallelLeafReader(false, getOnlyLeafReader(r1), getOnlyLeafReader(r2)).close();
    new ParallelLeafReader(false, getOnlyLeafReader(r2), getOnlyLeafReader(r1)).close();
    IOUtils.close(r1, dir1, r2, dir2);
}

62. TestParallelLeafReader#testCloseInnerReader()

Project: lucene-solr
File: TestParallelLeafReader.java
public void testCloseInnerReader() throws Exception {
    Directory dir1 = getDir1(random());
    LeafReader ir1 = getOnlyLeafReader(DirectoryReader.open(dir1));
    // with overlapping
    ParallelLeafReader pr = new ParallelLeafReader(true, new LeafReader[] { ir1 }, new LeafReader[] { ir1 });
    ir1.close();
    // should already be closed because inner reader is closed!
    expectThrows(AlreadyClosedException.class, () -> {
        pr.document(0);
    });
    // noop:
    pr.close();
    dir1.close();
}

63. TestOmitTf#testStats()

Project: lucene-solr
File: TestOmitTf.java
/** test that when freqs are omitted, that totalTermFreq and sumTotalTermFreq are -1 */
public void testStats() throws Exception {
    Directory dir = newDirectory();
    RandomIndexWriter iw = new RandomIndexWriter(random(), dir, newIndexWriterConfig(new MockAnalyzer(random())));
    Document doc = new Document();
    FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
    ft.setIndexOptions(IndexOptions.DOCS);
    ft.freeze();
    Field f = newField("foo", "bar", ft);
    doc.add(f);
    iw.addDocument(doc);
    IndexReader ir = iw.getReader();
    iw.close();
    assertEquals(-1, ir.totalTermFreq(new Term("foo", new BytesRef("bar"))));
    assertEquals(-1, ir.getSumTotalTermFreq("foo"));
    ir.close();
    dir.close();
}

64. TestOmitPositions#testBasic()

Project: lucene-solr
File: TestOmitPositions.java
public void testBasic() throws Exception {
    Directory dir = newDirectory();
    RandomIndexWriter w = new RandomIndexWriter(random(), dir);
    Document doc = new Document();
    FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
    ft.setIndexOptions(IndexOptions.DOCS_AND_FREQS);
    Field f = newField("foo", "this is a test test", ft);
    doc.add(f);
    for (int i = 0; i < 100; i++) {
        w.addDocument(doc);
    }
    IndexReader reader = w.getReader();
    w.close();
    assertNotNull(MultiFields.getTermPositionsEnum(reader, "foo", new BytesRef("test")));
    PostingsEnum de = TestUtil.docs(random(), reader, "foo", new BytesRef("test"), null, PostingsEnum.FREQS);
    while (de.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
        assertEquals(2, de.freq());
    }
    reader.close();
    dir.close();
}

65. TestNumericDocValuesUpdates#testUpdateTwoNonexistingTerms()

Project: lucene-solr
File: TestNumericDocValuesUpdates.java
@Test
public void testUpdateTwoNonexistingTerms() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter writer = new IndexWriter(dir, conf);
    Document doc = new Document();
    doc.add(new StringField("id", "doc", Store.NO));
    doc.add(new NumericDocValuesField("f1", 1L));
    writer.addDocument(doc);
    // update w/ multiple nonexisting terms in same field
    writer.updateNumericDocValue(new Term("c", "foo"), "f1", 2L);
    writer.updateNumericDocValue(new Term("c", "bar"), "f1", 2L);
    writer.close();
    DirectoryReader reader = DirectoryReader.open(dir);
    assertEquals(1, reader.leaves().size());
    assertEquals(1L, reader.leaves().get(0).reader().getNumericDocValues("f1").get(0));
    reader.close();
    dir.close();
}

66. TestNumericDocValuesUpdates#testUpdateAllDeletedSegment()

Project: lucene-solr
File: TestNumericDocValuesUpdates.java
@Test
public void testUpdateAllDeletedSegment() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter writer = new IndexWriter(dir, conf);
    Document doc = new Document();
    doc.add(new StringField("id", "doc", Store.NO));
    doc.add(new NumericDocValuesField("f1", 1L));
    writer.addDocument(doc);
    writer.addDocument(doc);
    writer.commit();
    // delete all docs in the first segment
    writer.deleteDocuments(new Term("id", "doc"));
    writer.addDocument(doc);
    writer.updateNumericDocValue(new Term("id", "doc"), "f1", 2L);
    writer.close();
    DirectoryReader reader = DirectoryReader.open(dir);
    assertEquals(1, reader.leaves().size());
    assertEquals(2L, reader.leaves().get(0).reader().getNumericDocValues("f1").get(0));
    reader.close();
    dir.close();
}

67. TestNumericDocValuesUpdates#testUpdateNumericDVFieldWithSameNameAsPostingField()

Project: lucene-solr
File: TestNumericDocValuesUpdates.java
@Test
public void testUpdateNumericDVFieldWithSameNameAsPostingField() throws Exception {
    // this used to fail because FieldInfos.Builder neglected to update
    // globalFieldMaps.docValuesTypes map
    Directory dir = newDirectory();
    IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter writer = new IndexWriter(dir, conf);
    Document doc = new Document();
    doc.add(new StringField("f", "mock-value", Store.NO));
    doc.add(new NumericDocValuesField("f", 5));
    writer.addDocument(doc);
    writer.commit();
    writer.updateNumericDocValue(new Term("f", "mock-value"), "f", 17L);
    writer.close();
    DirectoryReader r = DirectoryReader.open(dir);
    NumericDocValues ndv = r.leaves().get(0).reader().getNumericDocValues("f");
    assertEquals(17, ndv.get(0));
    r.close();
    dir.close();
}

68. TestNumericDocValuesUpdates#testUpdateSameDocMultipleTimes()

Project: lucene-solr
File: TestNumericDocValuesUpdates.java
@Test
public void testUpdateSameDocMultipleTimes() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter writer = new IndexWriter(dir, conf);
    Document doc = new Document();
    doc.add(new StringField("key", "doc", Store.NO));
    doc.add(new NumericDocValuesField("ndv", 5));
    // flushed document
    writer.addDocument(doc);
    writer.commit();
    // in-memory document
    writer.addDocument(doc);
    // update existing field
    writer.updateNumericDocValue(new Term("key", "doc"), "ndv", 17L);
    // update existing field 2nd time in this commit
    writer.updateNumericDocValue(new Term("key", "doc"), "ndv", 3L);
    writer.close();
    final DirectoryReader reader = DirectoryReader.open(dir);
    NumericDocValues ndv = MultiDocValues.getNumericValues(reader, "ndv");
    for (int i = 0; i < reader.maxDoc(); i++) {
        assertEquals(3, ndv.get(i));
    }
    reader.close();
    dir.close();
}

69. TestNumericDocValuesUpdates#testUpdatesAreFlushed()

Project: lucene-solr
File: TestNumericDocValuesUpdates.java
@Test
public void testUpdatesAreFlushed() throws IOException {
    Directory dir = newDirectory();
    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)).setRAMBufferSizeMB(0.00000001));
    // val=1
    writer.addDocument(doc(0));
    // val=2
    writer.addDocument(doc(1));
    // val=2
    writer.addDocument(doc(3));
    writer.commit();
    assertEquals(1, writer.getFlushDeletesCount());
    writer.updateNumericDocValue(new Term("id", "doc-0"), "val", 5L);
    assertEquals(2, writer.getFlushDeletesCount());
    writer.updateNumericDocValue(new Term("id", "doc-1"), "val", 6L);
    assertEquals(3, writer.getFlushDeletesCount());
    writer.updateNumericDocValue(new Term("id", "doc-2"), "val", 7L);
    assertEquals(4, writer.getFlushDeletesCount());
    writer.getConfig().setRAMBufferSizeMB(1000d);
    writer.updateNumericDocValue(new Term("id", "doc-2"), "val", 7L);
    assertEquals(4, writer.getFlushDeletesCount());
    writer.close();
    dir.close();
}

70. TestNorms#testMaxByteNorms()

Project: lucene-solr
File: TestNorms.java
public void testMaxByteNorms() throws IOException {
    Directory dir = newFSDirectory(createTempDir("TestNorms.testMaxByteNorms"));
    buildIndex(dir);
    DirectoryReader open = DirectoryReader.open(dir);
    NumericDocValues normValues = MultiDocValues.getNormValues(open, byteTestField);
    assertNotNull(normValues);
    for (int i = 0; i < open.maxDoc(); i++) {
        Document document = open.document(i);
        int expected = Integer.parseInt(document.get(byteTestField));
        assertEquals(expected, normValues.get(i));
    }
    open.close();
    dir.close();
}

71. TestNoDeletionPolicy#testAllCommitsRemain()

Project: lucene-solr
File: TestNoDeletionPolicy.java
@Test
public void testAllCommitsRemain() throws Exception {
    Directory dir = newDirectory();
    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())).setIndexDeletionPolicy(NoDeletionPolicy.INSTANCE));
    for (int i = 0; i < 10; i++) {
        Document doc = new Document();
        doc.add(newTextField("c", "a" + i, Field.Store.YES));
        writer.addDocument(doc);
        writer.commit();
        assertEquals("wrong number of commits !", i + 1, DirectoryReader.listCommits(dir).size());
    }
    writer.close();
    dir.close();
}

72. TestMultiTermsEnum#testNoTermsInField()

Project: lucene-solr
File: TestMultiTermsEnum.java
// LUCENE-6826
public void testNoTermsInField() throws Exception {
    Directory directory = new RAMDirectory();
    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(new MockAnalyzer(random())));
    Document document = new Document();
    document.add(new StringField("deleted", "0", Field.Store.YES));
    writer.addDocument(document);
    DirectoryReader reader = DirectoryReader.open(writer);
    writer.close();
    Directory directory2 = new RAMDirectory();
    writer = new IndexWriter(directory2, new IndexWriterConfig(new MockAnalyzer(random())));
    List<LeafReaderContext> leaves = reader.leaves();
    CodecReader[] codecReaders = new CodecReader[leaves.size()];
    for (int i = 0; i < leaves.size(); i++) {
        codecReaders[i] = new MigratingCodecReader((CodecReader) leaves.get(i).reader());
    }
    // <- bang
    writer.addIndexes(codecReaders);
    IOUtils.close(writer, reader, directory);
}

73. TestMultiFields#testTermDocsEnum()

Project: lucene-solr
File: TestMultiFields.java
public void testTermDocsEnum() throws Exception {
    Directory dir = newDirectory();
    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
    Document d = new Document();
    d.add(newStringField("f", "j", Field.Store.NO));
    w.addDocument(d);
    w.commit();
    w.addDocument(d);
    IndexReader r = w.getReader();
    w.close();
    PostingsEnum de = MultiFields.getTermDocsEnum(r, "f", new BytesRef("j"));
    assertEquals(0, de.nextDoc());
    assertEquals(1, de.nextDoc());
    assertEquals(DocIdSetIterator.NO_MORE_DOCS, de.nextDoc());
    r.close();
    dir.close();
}

74. TestMultiFields#testSeparateEnums()

Project: lucene-solr
File: TestMultiFields.java
/*
  private void verify(IndexReader r, String term, List<Integer> expected) throws Exception {
    DocsEnum docs = _TestUtil.docs(random, r,
                                   "field",
                                   new BytesRef(term),
                                   MultiFields.getLiveDocs(r),
                                   null,
                                   false);
    for(int docID : expected) {
      assertEquals(docID, docs.nextDoc());
    }
    assertEquals(docs.NO_MORE_DOCS, docs.nextDoc());
  }
  */
public void testSeparateEnums() throws Exception {
    Directory dir = newDirectory();
    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
    Document d = new Document();
    d.add(newStringField("f", "j", Field.Store.NO));
    w.addDocument(d);
    w.commit();
    w.addDocument(d);
    IndexReader r = w.getReader();
    w.close();
    PostingsEnum d1 = TestUtil.docs(random(), r, "f", new BytesRef("j"), null, PostingsEnum.NONE);
    PostingsEnum d2 = TestUtil.docs(random(), r, "f", new BytesRef("j"), null, PostingsEnum.NONE);
    assertEquals(0, d1.nextDoc());
    assertEquals(0, d2.nextDoc());
    r.close();
    dir.close();
}

75. TestInfoStream#testTestPointsOff()

Project: lucene-solr
File: TestInfoStream.java
/** we shouldn't have test points unless we ask */
public void testTestPointsOff() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(null);
    iwc.setInfoStream(new InfoStream() {

        @Override
        public void close() throws IOException {
        }

        @Override
        public void message(String component, String message) {
            assertFalse("TP".equals(component));
        }

        @Override
        public boolean isEnabled(String component) {
            assertFalse("TP".equals(component));
            return true;
        }
    });
    IndexWriter iw = new IndexWriter(dir, iwc);
    iw.addDocument(new Document());
    iw.close();
    dir.close();
}

76. TestIndexWriterUnicode#testInvalidUTF16()

Project: lucene-solr
File: TestIndexWriterUnicode.java
// LUCENE-510
public void testInvalidUTF16() throws Throwable {
    Directory dir = newDirectory();
    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new TestIndexWriter.StringSplitAnalyzer()));
    Document doc = new Document();
    final int count = utf8Data.length / 2;
    for (int i = 0; i < count; i++) doc.add(newTextField("f" + i, utf8Data[2 * i], Field.Store.YES));
    w.addDocument(doc);
    w.close();
    IndexReader ir = DirectoryReader.open(dir);
    Document doc2 = ir.document(0);
    for (int i = 0; i < count; i++) {
        assertEquals("field " + i + " was not indexed correctly", 1, ir.docFreq(new Term("f" + i, utf8Data[2 * i + 1])));
        assertEquals("field " + i + " is incorrect", utf8Data[2 * i + 1], doc2.getField("f" + i).stringValue());
    }
    ir.close();
    dir.close();
}

77. TestIndexWriterUnicode#testEmbeddedFFFF()

Project: lucene-solr
File: TestIndexWriterUnicode.java
public void testEmbeddedFFFF() throws Throwable {
    Directory d = newDirectory();
    IndexWriter w = new IndexWriter(d, newIndexWriterConfig(new MockAnalyzer(random())));
    Document doc = new Document();
    doc.add(newTextField("field", "a a?b", Field.Store.NO));
    w.addDocument(doc);
    doc = new Document();
    doc.add(newTextField("field", "a", Field.Store.NO));
    w.addDocument(doc);
    IndexReader r = w.getReader();
    assertEquals(1, r.docFreq(new Term("field", "a?b")));
    r.close();
    w.close();
    d.close();
}

78. TestIndexWriterReader#testReopenNRTReaderOnCommit()

Project: lucene-solr
File: TestIndexWriterReader.java
// LUCENE-5912: make sure when you reopen an NRT reader using a commit point, the SegmentReaders are in fact shared:
public void testReopenNRTReaderOnCommit() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    w.addDocument(new Document());
    // Pull NRT reader; it has 1 segment:
    DirectoryReader r1 = DirectoryReader.open(w);
    assertEquals(1, r1.leaves().size());
    w.addDocument(new Document());
    w.commit();
    List<IndexCommit> commits = DirectoryReader.listCommits(dir);
    assertEquals(1, commits.size());
    DirectoryReader r2 = DirectoryReader.openIfChanged(r1, commits.get(0));
    assertEquals(2, r2.leaves().size());
    // Make sure we shared same instance of SegmentReader w/ first reader:
    assertTrue(r1.leaves().get(0).reader() == r2.leaves().get(0).reader());
    r1.close();
    r2.close();
    w.close();
    dir.close();
}

79. TestIndexWriterReader#testTooManySegments()

Project: lucene-solr
File: TestIndexWriterReader.java
/** Make sure if all we do is open NRT reader against
   *  writer, we don't see merge starvation. */
public void testTooManySegments() throws Exception {
    Directory dir = getAssertNoDeletesDirectory(new RAMDirectory());
    // Don't use newIndexWriterConfig, because we need a
    // "sane" mergePolicy:
    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
    IndexWriter w = new IndexWriter(dir, iwc);
    // Create 500 segments:
    for (int i = 0; i < 500; i++) {
        Document doc = new Document();
        doc.add(newStringField("id", "" + i, Field.Store.NO));
        w.addDocument(doc);
        IndexReader r = DirectoryReader.open(w);
        // Make sure segment count never exceeds 100:
        assertTrue(r.leaves().size() < 100);
        r.close();
    }
    w.close();
    dir.close();
}

80. TestIndexWriterReader#testForceMergeDeletes()

Project: lucene-solr
File: TestIndexWriterReader.java
public void testForceMergeDeletes() throws Throwable {
    Directory dir = newDirectory();
    final IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
    Document doc = new Document();
    doc.add(newTextField("field", "a b c", Field.Store.NO));
    Field id = newStringField("id", "", Field.Store.NO);
    doc.add(id);
    id.setStringValue("0");
    w.addDocument(doc);
    id.setStringValue("1");
    w.addDocument(doc);
    w.deleteDocuments(new Term("id", "0"));
    IndexReader r = w.getReader();
    w.forceMergeDeletes();
    w.close();
    r.close();
    r = DirectoryReader.open(dir);
    assertEquals(1, r.numDocs());
    assertFalse(r.hasDeletions());
    r.close();
    dir.close();
}

81. TestIndexWriterReader#testAfterClose()

Project: lucene-solr
File: TestIndexWriterReader.java
// Make sure reader remains usable even if IndexWriter closes
public void testAfterClose() throws Exception {
    Directory dir1 = getAssertNoDeletesDirectory(newDirectory());
    IndexWriter writer = new IndexWriter(dir1, newIndexWriterConfig(new MockAnalyzer(random())));
    // create the index
    createIndexNoClose(false, "test", writer);
    DirectoryReader r = writer.getReader();
    writer.close();
    TestUtil.checkIndex(dir1);
    // reader should remain usable even after IndexWriter is closed:
    assertEquals(100, r.numDocs());
    Query q = new TermQuery(new Term("indexname", "test"));
    IndexSearcher searcher = newSearcher(r);
    assertEquals(100, searcher.search(q, 10).totalHits);
    expectThrows(AlreadyClosedException.class, () -> {
        DirectoryReader.openIfChanged(r);
    });
    r.close();
    dir1.close();
}

82. TestMergeSchedulerExternal#testCustomMergeScheduler()

Project: lucene-solr
File: TestMergeSchedulerExternal.java
public void testCustomMergeScheduler() throws Exception {
    // we don't really need to execute anything, just to make sure the custom MS
    // compiles. But ensure that it can be used as well, e.g., no other hidden
    // dependencies or something. Therefore, don't use any random API !
    Directory dir = new RAMDirectory();
    IndexWriterConfig conf = new IndexWriterConfig(null);
    conf.setMergeScheduler(new ReportingMergeScheduler());
    IndexWriter writer = new IndexWriter(dir, conf);
    writer.addDocument(new Document());
    // trigger flush
    writer.commit();
    writer.addDocument(new Document());
    // trigger flush
    writer.commit();
    writer.forceMerge(1);
    writer.close();
    dir.close();
}

83. TestWildcard#testQuestionmark()

Project: lucene-solr
File: TestWildcard.java
/**
   * Tests Wildcard queries with a question mark.
   *
   * @throws IOException if an error occurs
   */
public void testQuestionmark() throws IOException {
    Directory indexStore = getIndexStore("body", new String[] { "metal", "metals", "mXtals", "mXtXls" });
    IndexReader reader = DirectoryReader.open(indexStore);
    IndexSearcher searcher = newSearcher(reader);
    Query query1 = new WildcardQuery(new Term("body", "m?tal"));
    Query query2 = new WildcardQuery(new Term("body", "metal?"));
    Query query3 = new WildcardQuery(new Term("body", "metals?"));
    Query query4 = new WildcardQuery(new Term("body", "m?t?ls"));
    Query query5 = new WildcardQuery(new Term("body", "M?t?ls"));
    Query query6 = new WildcardQuery(new Term("body", "meta??"));
    assertMatches(searcher, query1, 1);
    assertMatches(searcher, query2, 1);
    assertMatches(searcher, query3, 0);
    assertMatches(searcher, query4, 3);
    assertMatches(searcher, query5, 0);
    // Query: 'meta??' matches 'metals' not 'metal'
    assertMatches(searcher, query6, 1);
    reader.close();
    indexStore.close();
}

84. TestWildcard#testPrefixTerm()

Project: lucene-solr
File: TestWildcard.java
/**
   * Tests if a WildcardQuery that has only a trailing * in the term is
   * rewritten to a single PrefixQuery. The boost and rewriteMethod should be
   * preserved.
   */
public void testPrefixTerm() throws IOException {
    Directory indexStore = getIndexStore("field", new String[] { "prefix", "prefixx" });
    IndexReader reader = DirectoryReader.open(indexStore);
    IndexSearcher searcher = newSearcher(reader);
    MultiTermQuery wq = new WildcardQuery(new Term("field", "prefix*"));
    assertMatches(searcher, wq, 2);
    wq = new WildcardQuery(new Term("field", "*"));
    assertMatches(searcher, wq, 2);
    Terms terms = MultiFields.getTerms(searcher.getIndexReader(), "field");
    assertFalse(wq.getTermsEnum(terms).getClass().getSimpleName().contains("AutomatonTermsEnum"));
    reader.close();
    indexStore.close();
}

85. TestWildcard#testEmptyTerm()

Project: lucene-solr
File: TestWildcard.java
/**
   * Tests if a WildcardQuery with an empty term is rewritten to an empty BooleanQuery
   */
public void testEmptyTerm() throws IOException {
    Directory indexStore = getIndexStore("field", new String[] { "nowildcard", "nowildcardx" });
    IndexReader reader = DirectoryReader.open(indexStore);
    IndexSearcher searcher = newSearcher(reader);
    MultiTermQuery wq = new WildcardQuery(new Term("field", ""));
    wq.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_REWRITE);
    assertMatches(searcher, wq, 0);
    Query q = searcher.rewrite(wq);
    assertTrue(q instanceof MatchNoDocsQuery);
    reader.close();
    indexStore.close();
}

86. TestWildcard#testTermWithoutWildcard()

Project: lucene-solr
File: TestWildcard.java
/**
   * Tests if a WildcardQuery that has no wildcard in the term is rewritten to a single
   * TermQuery. The boost should be preserved, and the rewrite should return
   * a ConstantScoreQuery if the WildcardQuery had a ConstantScore rewriteMethod.
   */
public void testTermWithoutWildcard() throws IOException {
    Directory indexStore = getIndexStore("field", new String[] { "nowildcard", "nowildcardx" });
    IndexReader reader = DirectoryReader.open(indexStore);
    IndexSearcher searcher = newSearcher(reader);
    MultiTermQuery wq = new WildcardQuery(new Term("field", "nowildcard"));
    assertMatches(searcher, wq, 1);
    wq.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_REWRITE);
    Query q = searcher.rewrite(wq);
    assertTrue(q instanceof TermQuery);
    wq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE);
    q = searcher.rewrite(wq);
    assertTrue(q instanceof MultiTermQueryConstantScoreWrapper);
    wq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_REWRITE);
    q = searcher.rewrite(wq);
    assertTrue(q instanceof ConstantScoreQuery);
    reader.close();
    indexStore.close();
}

87. TestTotalHitCountCollector#testBasics()

Project: lucene-solr
File: TestTotalHitCountCollector.java
public void testBasics() throws Exception {
    Directory indexStore = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), indexStore);
    for (int i = 0; i < 5; i++) {
        Document doc = new Document();
        doc.add(new StringField("string", "a" + i, Field.Store.NO));
        doc.add(new StringField("string", "b" + i, Field.Store.NO));
        writer.addDocument(doc);
    }
    IndexReader reader = writer.getReader();
    writer.close();
    IndexSearcher searcher = newSearcher(reader);
    TotalHitCountCollector c = new TotalHitCountCollector();
    searcher.search(new MatchAllDocsQuery(), c);
    assertEquals(5, c.getTotalHits());
    reader.close();
    indexStore.close();
}

88. TestSloppyPhraseQuery#testInfiniteFreq1()

Project: lucene-solr
File: TestSloppyPhraseQuery.java
// LUCENE-3215
public void testInfiniteFreq1() throws Exception {
    String document = "drug druggy drug drug drug";
    Directory dir = newDirectory();
    RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
    Document doc = new Document();
    doc.add(newField("lyrics", document, new FieldType(TextField.TYPE_NOT_STORED)));
    iw.addDocument(doc);
    IndexReader ir = iw.getReader();
    iw.close();
    IndexSearcher is = newSearcher(ir);
    PhraseQuery.Builder builder = new PhraseQuery.Builder();
    builder.add(new Term("lyrics", "drug"), 1);
    builder.add(new Term("lyrics", "drug"), 3);
    builder.setSlop(1);
    PhraseQuery pq = builder.build();
    // "drug the drug"~1
    assertSaneScoring(pq, is);
    ir.close();
    dir.close();
}

89. TestSearcherManager#testEvilSearcherFactory()

Project: lucene-solr
File: TestSearcherManager.java
public void testEvilSearcherFactory() throws Exception {
    final Random random = random();
    final Directory dir = newDirectory();
    final RandomIndexWriter w = new RandomIndexWriter(random, dir);
    w.commit();
    final IndexReader other = DirectoryReader.open(dir);
    final SearcherFactory theEvilOne = new SearcherFactory() {

        @Override
        public IndexSearcher newSearcher(IndexReader ignored, IndexReader previous) {
            return LuceneTestCase.newSearcher(other);
        }
    };
    expectThrows(IllegalStateException.class, () -> {
        new SearcherManager(dir, theEvilOne);
    });
    expectThrows(IllegalStateException.class, () -> {
        new SearcherManager(w.w, random.nextBoolean(), false, theEvilOne);
    });
    w.close();
    other.close();
    dir.close();
}

90. TestSearcherManager#testListenerCalled()

Project: lucene-solr
File: TestSearcherManager.java
public void testListenerCalled() throws Exception {
    Directory dir = newDirectory();
    IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(null));
    final AtomicBoolean afterRefreshCalled = new AtomicBoolean(false);
    SearcherManager sm = new SearcherManager(iw, false, false, new SearcherFactory());
    sm.addListener(new ReferenceManager.RefreshListener() {

        @Override
        public void beforeRefresh() {
        }

        @Override
        public void afterRefresh(boolean didRefresh) {
            if (didRefresh) {
                afterRefreshCalled.set(true);
            }
        }
    });
    iw.addDocument(new Document());
    iw.commit();
    assertFalse(afterRefreshCalled.get());
    sm.maybeRefreshBlocking();
    assertTrue(afterRefreshCalled.get());
    sm.close();
    iw.close();
    dir.close();
}

91. TestSearcherManager#testEnsureOpen()

Project: lucene-solr
File: TestSearcherManager.java
public void testEnsureOpen() throws Exception {
    Directory dir = newDirectory();
    new IndexWriter(dir, new IndexWriterConfig(null)).close();
    SearcherManager sm = new SearcherManager(dir, null);
    IndexSearcher s = sm.acquire();
    sm.close();
    // this should succeed;
    sm.release(s);
    // this should fail
    expectThrows(AlreadyClosedException.class, () -> {
        sm.acquire();
    });
    // this should fail
    expectThrows(AlreadyClosedException.class, () -> {
        sm.maybeRefresh();
    });
    dir.close();
}

92. TestScoreCachingWrappingScorer#testGetScores()

Project: lucene-solr
File: TestScoreCachingWrappingScorer.java
public void testGetScores() throws Exception {
    Directory directory = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), directory);
    writer.commit();
    IndexReader ir = writer.getReader();
    writer.close();
    IndexSearcher searcher = newSearcher(ir);
    Weight fake = new TermQuery(new Term("fake", "weight")).createWeight(searcher, true, 1f);
    Scorer s = new SimpleScorer(fake);
    ScoreCachingCollector scc = new ScoreCachingCollector(scores.length);
    scc.setScorer(s);
    // We need to iterate on the scorer so that its doc() advances.
    int doc;
    while ((doc = s.iterator().nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
        scc.collect(doc);
    }
    for (int i = 0; i < scores.length; i++) {
        assertEquals(scores[i], scc.mscores[i], 0f);
    }
    ir.close();
    directory.close();
}

93. TestPrefixQuery#testMatchAll()

Project: lucene-solr
File: TestPrefixQuery.java
public void testMatchAll() throws Exception {
    Directory directory = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), directory);
    Document doc = new Document();
    doc.add(newStringField("field", "field", Field.Store.YES));
    writer.addDocument(doc);
    IndexReader reader = writer.getReader();
    PrefixQuery query = new PrefixQuery(new Term("field", ""));
    IndexSearcher searcher = newSearcher(reader);
    assertEquals(1, searcher.search(query, 1000).totalHits);
    writer.close();
    reader.close();
    directory.close();
}

94. TestPointQueries#testBasicMultiDimPointInSetQuery()

Project: lucene-solr
File: TestPointQueries.java
public void testBasicMultiDimPointInSetQuery() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = newIndexWriterConfig();
    iwc.setCodec(getCodec());
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new IntPoint("int", 17, 42));
    w.addDocument(doc);
    IndexReader r = DirectoryReader.open(w);
    IndexSearcher s = newSearcher(r, false);
    assertEquals(0, s.count(newMultiDimIntSetQuery("int", 2, 17, 41)));
    assertEquals(1, s.count(newMultiDimIntSetQuery("int", 2, 17, 42)));
    assertEquals(1, s.count(newMultiDimIntSetQuery("int", 2, -7, -7, 17, 42)));
    assertEquals(1, s.count(newMultiDimIntSetQuery("int", 2, 17, 42, -14, -14)));
    w.close();
    r.close();
    dir.close();
}

95. TestPhraseQuery#testPhraseQueryWithStopAnalyzer()

Project: lucene-solr
File: TestPhraseQuery.java
public void testPhraseQueryWithStopAnalyzer() throws Exception {
    Directory directory = newDirectory();
    Analyzer stopAnalyzer = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET);
    RandomIndexWriter writer = new RandomIndexWriter(random(), directory, newIndexWriterConfig(stopAnalyzer));
    Document doc = new Document();
    doc.add(newTextField("field", "the stop words are here", Field.Store.YES));
    writer.addDocument(doc);
    IndexReader reader = writer.getReader();
    writer.close();
    IndexSearcher searcher = newSearcher(reader);
    // valid exact phrase query
    PhraseQuery query = new PhraseQuery("field", "stop", "words");
    ScoreDoc[] hits = searcher.search(query, 1000).scoreDocs;
    assertEquals(1, hits.length);
    QueryUtils.check(random(), query, searcher);
    reader.close();
    directory.close();
}

96. TestNot#testNot()

Project: lucene-solr
File: TestNot.java
public void testNot() throws Exception {
    Directory store = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), store);
    Document d1 = new Document();
    d1.add(newTextField("field", "a b", Field.Store.YES));
    writer.addDocument(d1);
    IndexReader reader = writer.getReader();
    IndexSearcher searcher = newSearcher(reader);
    BooleanQuery.Builder query = new BooleanQuery.Builder();
    query.add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD);
    query.add(new TermQuery(new Term("field", "b")), BooleanClause.Occur.MUST_NOT);
    ScoreDoc[] hits = searcher.search(query.build(), 1000).scoreDocs;
    assertEquals(0, hits.length);
    writer.close();
    reader.close();
    store.close();
}

97. TestMultiPhraseQuery#testNoDocs()

Project: lucene-solr
File: TestMultiPhraseQuery.java
public void testNoDocs() throws Exception {
    Directory indexStore = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), indexStore);
    add("a note", "note", writer);
    IndexReader reader = writer.getReader();
    IndexSearcher searcher = newSearcher(reader);
    MultiPhraseQuery.Builder qb = new MultiPhraseQuery.Builder();
    qb.add(new Term("body", "a"));
    qb.add(new Term[] { new Term("body", "nope"), new Term("body", "nope") });
    MultiPhraseQuery q = qb.build();
    assertEquals("Wrong number of hits", 0, searcher.search(q, 1).totalHits);
    // just make sure no exc:
    searcher.explain(q, 0);
    writer.close();
    reader.close();
    indexStore.close();
}

98. TestMultiPhraseQuery#testMultiExactWithRepeats()

Project: lucene-solr
File: TestMultiPhraseQuery.java
public void testMultiExactWithRepeats() throws IOException {
    Directory indexStore = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), indexStore);
    add("a b c d e f g h i k", writer);
    IndexReader r = writer.getReader();
    writer.close();
    IndexSearcher searcher = newSearcher(r);
    MultiPhraseQuery.Builder qb = new MultiPhraseQuery.Builder();
    qb.add(new Term[] { new Term("body", "a"), new Term("body", "d") }, 0);
    qb.add(new Term[] { new Term("body", "a"), new Term("body", "f") }, 2);
    // should match on "a b"
    assertEquals(1, searcher.search(qb.build(), 1).totalHits);
    r.close();
    indexStore.close();
}

99. TestMultiPhraseQuery#testMultiSloppyWithRepeats()

Project: lucene-solr
File: TestMultiPhraseQuery.java
//LUCENE-3821 fixes sloppy phrase scoring, except for this known problem 
@Ignore
public void testMultiSloppyWithRepeats() throws IOException {
    Directory indexStore = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), indexStore);
    add("a b c d e f g h i k", writer);
    IndexReader r = writer.getReader();
    writer.close();
    IndexSearcher searcher = newSearcher(r);
    MultiPhraseQuery.Builder qb = new MultiPhraseQuery.Builder();
    // this will fail, when the scorer would propagate [a] rather than [a,b],
    qb.add(new Term[] { new Term("body", "a"), new Term("body", "b") });
    qb.add(new Term[] { new Term("body", "a") });
    qb.setSlop(6);
    // should match on "a b"
    assertEquals(1, searcher.search(qb.build(), 1).totalHits);
    r.close();
    indexStore.close();
}

100. TestMultiPhraseQuery#testTall()

Project: lucene-solr
File: TestMultiPhraseQuery.java
// LUCENE-2580
public void testTall() throws IOException {
    Directory indexStore = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), indexStore);
    add("blueberry chocolate pie", writer);
    add("blueberry chocolate tart", writer);
    IndexReader r = writer.getReader();
    writer.close();
    IndexSearcher searcher = newSearcher(r);
    MultiPhraseQuery.Builder qb = new MultiPhraseQuery.Builder();
    qb.add(new Term("body", "blueberry"));
    qb.add(new Term("body", "chocolate"));
    qb.add(new Term[] { new Term("body", "pie"), new Term("body", "tart") });
    assertEquals(2, searcher.search(qb.build(), 1).totalHits);
    r.close();
    indexStore.close();
}