Search in sources :

Example 1 with SetOnce

use of org.apache.lucene.util.SetOnce in project lucene-solr by apache.

the class TestIndexWriter method testMergeAllDeleted.

public void testMergeAllDeleted() throws IOException {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
    final SetOnce<IndexWriter> iwRef = new SetOnce<>();
    IndexWriter evilWriter = RandomIndexWriter.mockIndexWriter(random(), dir, iwc, new RandomIndexWriter.TestPoint() {

        @Override
        public void apply(String message) {
            if ("startCommitMerge".equals(message)) {
                iwRef.get().setKeepFullyDeletedSegments(false);
            } else if ("startMergeInit".equals(message)) {
                iwRef.get().setKeepFullyDeletedSegments(true);
            }
        }
    });
    iwRef.set(evilWriter);
    for (int i = 0; i < 1000; i++) {
        addDoc(evilWriter);
        if (random().nextInt(17) == 0) {
            evilWriter.commit();
        }
    }
    evilWriter.deleteDocuments(new MatchAllDocsQuery());
    evilWriter.forceMerge(1);
    evilWriter.close();
    dir.close();
}
Also used : MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) SetOnce(org.apache.lucene.util.SetOnce) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) MMapDirectory(org.apache.lucene.store.MMapDirectory) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory) FSDirectory(org.apache.lucene.store.FSDirectory) SimpleFSDirectory(org.apache.lucene.store.SimpleFSDirectory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory)

Aggregations

MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 Directory (org.apache.lucene.store.Directory)1 FSDirectory (org.apache.lucene.store.FSDirectory)1 MMapDirectory (org.apache.lucene.store.MMapDirectory)1 NIOFSDirectory (org.apache.lucene.store.NIOFSDirectory)1 RAMDirectory (org.apache.lucene.store.RAMDirectory)1 SimpleFSDirectory (org.apache.lucene.store.SimpleFSDirectory)1 SetOnce (org.apache.lucene.util.SetOnce)1