use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition in project jackrabbit-oak by apache.
the class NRTIndexTest method sameReaderIfNoChange.
@Test
public void sameReaderIfNoChange() throws Exception {
IndexDefinition idxDefn = getSyncIndexDefinition("/foo");
NRTIndex idx1 = indexFactory.createIndex(idxDefn);
LuceneIndexWriter w1 = idx1.getWriter();
Document d1 = new Document();
d1.add(newPathField("/a/b"));
w1.updateDocument("/a/b", d1);
List<LuceneIndexReader> readers = idx1.getReaders();
List<LuceneIndexReader> readers2 = idx1.getReaders();
assertSame(readers, readers2);
w1.updateDocument("/a/b", d1);
List<LuceneIndexReader> readers3 = idx1.getReaders();
assertNotSame(readers2, readers3);
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition in project jackrabbit-oak by apache.
the class NRTIndexTest method dirDeletedUponClose.
@Test
public void dirDeletedUponClose() throws Exception {
IndexDefinition idxDefn = getSyncIndexDefinition("/foo");
NRTIndex idx = indexFactory.createIndex(idxDefn);
LuceneIndexWriter writer = idx.getWriter();
File indexDir = idx.getIndexDir();
assertTrue(indexDir.exists());
idx.close();
assertFalse(indexDir.exists());
try {
idx.getReaders();
fail();
} catch (IllegalStateException ignore) {
}
try {
idx.getWriter();
fail();
} catch (IllegalStateException ignore) {
}
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition in project jackrabbit-oak by apache.
the class NRTIndexTest method multipleUpdateForSamePath.
@Test
public void multipleUpdateForSamePath() throws Exception {
IndexDefinition idxDefn = getSyncIndexDefinition("/foo");
NRTIndex idx = indexFactory.createIndex(idxDefn);
LuceneIndexWriter writer = idx.getWriter();
Document document = new Document();
document.add(newPathField("/a/b"));
writer.updateDocument("/a/b", document);
assertEquals(1, idx.getPrimaryReader().getReader().numDocs());
writer.updateDocument("/a/b", document);
//Update for same path should not lead to deletion
assertEquals(2, idx.getPrimaryReader().getReader().numDocs());
assertEquals(0, idx.getPrimaryReader().getReader().numDeletedDocs());
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition in project jackrabbit-oak by apache.
the class ExternalIndexObserverTest method createNRTIndex.
private static IndexDefinition createNRTIndex(String ruleName) {
IndexDefinitionBuilder idx = new IndexDefinitionBuilder();
idx.indexRule(ruleName).property("foo").propertyIndex();
idx.async("async", "sync");
return new IndexDefinition(INITIAL_CONTENT, idx.build(), "/oak:index/foo");
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition in project jackrabbit-oak by apache.
the class NRTIndexFactoryTest method indexCreationAndCloser.
@Test
public void indexCreationAndCloser() throws Exception {
IndexDefinition idxDefn = getNRTIndexDefinition("/foo");
NRTIndex idx1 = indexFactory.createIndex(idxDefn);
assertNotNull(idx1);
assertEquals(1, indexFactory.getIndexes("/foo").size());
NRTIndex idx2 = indexFactory.createIndex(idxDefn);
assertEquals(2, indexFactory.getIndexes("/foo").size());
assertFalse(idx1.isClosed());
NRTIndex idx3 = indexFactory.createIndex(idxDefn);
assertFalse(idx1.isClosed());
assertEquals(3, indexFactory.getIndexes("/foo").size());
//Nothing index so size is zero
assertEquals(0, idx2.getReaders().size());
assertEquals(0, idx3.getReaders().size());
NRTIndex idx4 = indexFactory.createIndex(idxDefn);
assertEquals(3, indexFactory.getIndexes("/foo").size());
assertEquals(0, idx3.getReaders().size());
assertEquals(0, idx4.getReaders().size());
//With 3 generation open the first one should be closed
assertTrue(idx1.isClosed());
assertNull(idx1.getPrevious());
NRTIndex idx5 = indexFactory.createIndex(idxDefn);
assertEquals(3, indexFactory.getIndexes("/foo").size());
assertTrue(idx2.isClosed());
assertNull(idx2.getPrevious());
}
Aggregations