use of org.apache.jackrabbit.oak.spi.commit.EditorProvider in project jackrabbit-oak by apache.
the class NodeStoreUtils method mergeWithConcurrentCheck.
public static void mergeWithConcurrentCheck(NodeStore nodeStore, NodeBuilder builder) throws CommitFailedException {
List<EditorProvider> editorProviders = Lists.newArrayList();
editorProviders.add(new ConflictValidatorProvider());
CompositeHook hooks = new CompositeHook(new ConflictHook(new AnnotatingConflictHandler()), new EditorHook(CompositeEditorProvider.compose(editorProviders)));
nodeStore.merge(builder, hooks, CommitInfo.EMPTY);
}
use of org.apache.jackrabbit.oak.spi.commit.EditorProvider in project jackrabbit-oak by apache.
the class PrivateStoreValidatorProviderTest method testValidatorServiceRegistered.
@Test
public void testValidatorServiceRegistered() {
// test service registration, there should be a service for the PrivateStoreValidatorProvider
MountInfoProvider mountInfoProvider = createMountInfoProvider("/content/readonly");
context.registerService(MountInfoProvider.class, mountInfoProvider);
registerValidatorProvider(privateStoreValidatorProvider, true);
EditorProvider validator = context.getService(EditorProvider.class);
assertNotNull("No PrivateStoreValidatorProvider available!", validator);
assertTrue(validator instanceof PrivateStoreValidatorProvider);
assertTrue(((PrivateStoreValidatorProvider) validator).isFailOnDetection());
MockOsgi.deactivate(privateStoreValidatorProvider, context.bundleContext());
assertNull(context.getService(EditorProvider.class));
}
use of org.apache.jackrabbit.oak.spi.commit.EditorProvider in project jackrabbit-oak by apache.
the class AsyncIndexUpdate method mergeWithConcurrencyCheck.
private static void mergeWithConcurrencyCheck(final NodeStore store, List<ValidatorProvider> validatorProviders, NodeBuilder builder, final String checkpoint, final Long lease, final String name) throws CommitFailedException {
CommitHook concurrentUpdateCheck = new CommitHook() {
@Override
@Nonnull
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
// check for concurrent updates by this async task
NodeState async = before.getChildNode(ASYNC);
if ((checkpoint == null || Objects.equal(checkpoint, async.getString(name))) && (lease == null || lease == async.getLong(leasify(name)))) {
return after;
} else {
throw newConcurrentUpdateException();
}
}
};
List<EditorProvider> editorProviders = Lists.newArrayList();
editorProviders.add(new ConflictValidatorProvider());
editorProviders.addAll(validatorProviders);
CompositeHook hooks = new CompositeHook(ResetCommitAttributeHook.INSTANCE, ConflictHook.of(new AnnotatingConflictHandler()), new EditorHook(CompositeEditorProvider.compose(editorProviders)), concurrentUpdateCheck);
try {
store.merge(builder, hooks, createCommitInfo());
} catch (CommitFailedException ex) {
// OAK-2961
if (ex.isOfType(CommitFailedException.STATE) && ex.getCode() == 1) {
throw newConcurrentUpdateException();
} else {
throw ex;
}
}
}
use of org.apache.jackrabbit.oak.spi.commit.EditorProvider 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.EditorProvider in project jackrabbit-oak by apache.
the class HierarchyConflictTest method merge.
private static void merge(NodeStore store, NodeBuilder root, final EditorCallback callback) throws CommitFailedException {
CompositeHook hooks = new CompositeHook(new EditorHook(new EditorProvider() {
private int numEdits = 0;
@Override
public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder, CommitInfo info) throws CommitFailedException {
if (callback != null) {
if (++numEdits > 1) {
// this is a retry, fail the commit
throw new CommitFailedException(OAK, 0, "do not retry merge in this test");
}
callback.edit(builder);
}
return null;
}
}), ConflictHook.of(new AnnotatingConflictHandler()), new EditorHook(new ConflictValidatorProvider()));
store.merge(root, hooks, CommitInfo.EMPTY);
}
Aggregations