use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method testAsync.
/**
* Async Index Test
* <ul>
* <li>Add an index definition</li>
* <li>Add some content</li>
* <li>Search & verify</li>
* </ul>
*
*/
@Test
public void testAsync() throws Exception {
NodeStore store = new MemoryNodeStore();
IndexEditorProvider provider = new PropertyIndexEditorProvider();
NodeBuilder builder = store.getRoot().builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
builder.child("testRoot").setProperty("foo", "abc");
// merge it back in
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider);
async.run();
NodeState root = store.getRoot();
// first check that the index content nodes exist
checkPathExists(root, INDEX_DEFINITIONS_NAME, "rootIndex", INDEX_CONTENT_NODE_NAME);
assertFalse(root.getChildNode(INDEX_DEFINITIONS_NAME).hasChildNode(":conflict"));
PropertyIndexLookup lookup = new PropertyIndexLookup(root);
assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
}
use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup in project jackrabbit-oak by apache.
the class IndexUpdateTest method testReindexAsync.
/**
* Async Reindex Test (OAK-2174)
* <ul>
* <li>Add some content</li>
* <li>Add an index definition with the reindex flag and the reindex-async flag set</li>
* <li>Run the background async job manually</li>
* <li>Search & verify</li>
* </ul>
*/
@Test
public void testReindexAsync() throws Exception {
IndexEditorProvider provider = new PropertyIndexEditorProvider();
EditorHook hook = new EditorHook(new IndexUpdateProvider(provider));
NodeStore store = new MemoryNodeStore();
NodeBuilder builder = store.getRoot().builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(REINDEX_ASYNC_PROPERTY_NAME, true);
builder.child("testRoot").setProperty("foo", "abc");
// merge it back in
store.merge(builder, hook, CommitInfo.EMPTY);
// first check that the async flag exist
NodeState ns1 = checkPathExists(store.getRoot(), INDEX_DEFINITIONS_NAME, "rootIndex");
assertTrue(ns1.getProperty(REINDEX_PROPERTY_NAME).getValue(Type.BOOLEAN));
assertTrue(ns1.getProperty(REINDEX_ASYNC_PROPERTY_NAME).getValue(Type.BOOLEAN));
assertEquals(ASYNC_REINDEX_VALUE, ns1.getString(ASYNC_PROPERTY_NAME));
AsyncIndexUpdate async = new AsyncIndexUpdate(ASYNC_REINDEX_VALUE, store, provider, true);
int max = 5;
// same behaviour as PropertyIndexAsyncReindex mbean
boolean done = false;
int count = 0;
while (!done || count >= max) {
async.run();
done = async.isFinished();
count++;
}
// first check that the index content nodes exist
NodeState ns = checkPathExists(store.getRoot(), INDEX_DEFINITIONS_NAME, "rootIndex");
checkPathExists(ns, INDEX_CONTENT_NODE_NAME);
assertFalse(ns.getProperty(REINDEX_PROPERTY_NAME).getValue(Type.BOOLEAN));
assertNull(ns.getProperty(ASYNC_PROPERTY_NAME));
// next, lookup
PropertyIndexLookup lookup = new PropertyIndexLookup(store.getRoot());
assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
}
use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup in project jackrabbit-oak by apache.
the class IndexUpdateTest method testReindex.
/**
* Reindex Test
* <ul>
* <li>Add some content</li>
* <li>Add an index definition with the reindex flag set</li>
* <li>Search & verify</li>
* </ul>
*/
@Test
public void testReindex() throws Exception {
builder.child("testRoot").setProperty("foo", "abc");
NodeState before = builder.getNodeState();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null);
NodeState after = builder.getNodeState();
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
// first check that the index content nodes exist
NodeState ns = checkPathExists(indexed, INDEX_DEFINITIONS_NAME, "rootIndex");
checkPathExists(ns, INDEX_CONTENT_NODE_NAME);
PropertyState ps = ns.getProperty(REINDEX_PROPERTY_NAME);
assertNotNull(ps);
assertFalse(ps.getValue(Type.BOOLEAN));
// next, lookup
PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
}
use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup in project jackrabbit-oak by apache.
the class IndexUpdateTest method testReindexAuto.
/**
* Auto Reindex Test
* <ul>
* <li>Add some content</li>
* <li>Add an index definition without a reindex flag (see OAK-1874)</li>
* <li>Search & verify</li>
* </ul>
*/
@Test
public void testReindexAuto() throws Exception {
builder.child("testRoot").setProperty("foo", "abc");
NodeState before = builder.getNodeState();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", false, false, ImmutableSet.of("foo"), null);
NodeState after = builder.getNodeState();
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
// first check that the index content nodes exist
NodeState ns = checkPathExists(indexed, INDEX_DEFINITIONS_NAME, "rootIndex");
checkPathExists(ns, INDEX_CONTENT_NODE_NAME);
PropertyState ps = ns.getProperty(REINDEX_PROPERTY_NAME);
assertNotNull(ps);
assertFalse(ps.getValue(Type.BOOLEAN));
// next, lookup
PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
}
use of org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup in project jackrabbit-oak by apache.
the class IndexUpdateTest method ignoreReindexingFlag.
@Test
public void ignoreReindexingFlag() throws Exception {
String indexPath = "/oak:index/rootIndex";
CallbackCapturingProvider provider = new CallbackCapturingProvider();
IndexUpdateProvider indexUpdate = new IndexUpdateProvider(provider);
EditorHook hook = new EditorHook(indexUpdate);
NodeState before = builder.getNodeState();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null);
builder.child("a").setProperty("foo", "abc");
NodeState after = builder.getNodeState();
NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
assertTrue(provider.getContext(indexPath).isReindexing());
before = indexed;
builder = before.builder();
builder.child("b").setProperty("foo", "xyz");
child(builder, indexPath).setProperty(IndexConstants.REINDEX_PROPERTY_NAME, true);
after = builder.getNodeState();
provider.reset();
indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
assertTrue(provider.getContext(indexPath).isReindexing());
//Now set IndexUpdate to ignore the reindex flag
indexUpdate.setIgnoreReindexFlags(true);
indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
assertFalse(provider.getContext(indexPath).isReindexing());
//Despite reindex flag set to true and reindexing not done new
//content should still get picked up
PropertyIndexLookup lookup = new PropertyIndexLookup(indexed);
assertFalse(find(lookup, "foo", "xyz").isEmpty());
}
Aggregations