use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class NodeStoreUtils method mergeWithConcurrentCheck.
static void mergeWithConcurrentCheck(NodeStore nodeStore, NodeBuilder builder) throws CommitFailedException {
CompositeHook hooks = new CompositeHook(ResetCommitAttributeHook.INSTANCE, new ConflictHook(new AnnotatingConflictHandler()), new EditorHook(CompositeEditorProvider.compose(singletonList(new ConflictValidatorProvider()))));
nodeStore.merge(builder, hooks, createCommitInfo());
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class IndexUpdateTest method testMissingProviderFailsCommit.
/**
* OAK-3505 Provide an optionally stricter policy for missing synchronous
* index editor providers
*/
@Test
public void testMissingProviderFailsCommit() throws Exception {
final IndexUpdateCallback noop = new IndexUpdateCallback() {
@Override
public void indexUpdate() {
}
};
final MissingIndexProviderStrategy mips = new MissingIndexProviderStrategy();
mips.setFailOnMissingIndexProvider(true);
EditorHook hook = new EditorHook(new EditorProvider() {
@Override
public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder, CommitInfo info) throws CommitFailedException {
return new IndexUpdate(emptyProvider(), null, after, builder, noop).withMissingProviderStrategy(mips);
}
});
NodeState before = builder.getNodeState();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null);
builder.child(INDEX_DEFINITIONS_NAME).child("azerty");
builder.child("testRoot").setProperty("foo", "abc");
NodeState after = builder.getNodeState();
try {
hook.processCommit(before, after, CommitInfo.EMPTY);
fail("commit should fail on missing index provider");
} catch (CommitFailedException ex) {
// expected
}
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook 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.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class IndexUpdateTest method reindexForDisabledIndexes.
@Test
public void reindexForDisabledIndexes() throws Exception {
EditorHook hook = new EditorHook(new IndexUpdateProvider(new CompositeIndexEditorProvider(new PropertyIndexEditorProvider(), new ReferenceEditorProvider())));
NodeState before = builder.getNodeState();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "fooIndex", true, false, ImmutableSet.of("foo"), null);
builder.child("testRoot").setProperty("foo", "abc");
NodeState after = builder.getNodeState();
NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
before = indexed;
builder = before.builder();
builder.getChildNode("oak:index").getChildNode("fooIndex").setProperty(TYPE_PROPERTY_NAME, TYPE_DISABLED);
builder.getChildNode("oak:index").getChildNode("fooIndex").setProperty(REINDEX_PROPERTY_NAME, true);
after = builder.getNodeState();
LogCustomizer customLogs = LogCustomizer.forLogger(IndexUpdate.class.getName()).filter(Level.INFO).create();
customLogs.starting();
before = after;
builder = before.builder();
builder.child("testRoot2").setProperty("foo", "abc");
after = builder.getNodeState();
indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
assertTrue(customLogs.getLogs().isEmpty());
customLogs.finished();
}
use of org.apache.jackrabbit.oak.spi.commit.EditorHook in project jackrabbit-oak by apache.
the class IndexUpdateTest method testReindexSyncMissingProvider.
/**
* OAK-2203 Test reindex behavior on a sync index when the index provider is missing
* for a given type
*/
@Test
public void testReindexSyncMissingProvider() throws Exception {
EditorHook hook = new EditorHook(new IndexUpdateProvider(emptyProvider()));
NodeState before = builder.getNodeState();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null);
builder.child(INDEX_DEFINITIONS_NAME).child("azerty");
builder.child("testRoot").setProperty("foo", "abc");
NodeState after = builder.getNodeState();
NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY);
NodeState rootIndex = checkPathExists(indexed, INDEX_DEFINITIONS_NAME, "rootIndex");
PropertyState ps = rootIndex.getProperty(REINDEX_PROPERTY_NAME);
assertNotNull(ps);
assertTrue(ps.getValue(Type.BOOLEAN));
NodeState azerty = checkPathExists(indexed, INDEX_DEFINITIONS_NAME, "azerty");
assertNull("Node should be ignored by reindexer", azerty.getProperty(REINDEX_PROPERTY_NAME));
}
Aggregations