use of org.apache.jackrabbit.oak.spi.commit.CommitHook in project jackrabbit-oak by apache.
the class NodeStoreTest method addExistingNode.
@Test
public void addExistingNode() throws CommitFailedException {
// FIXME OAK-1550 Incorrect handling of addExistingNode conflict in NodeStore
assumeTrue(fixture != NodeStoreFixtures.DOCUMENT_MEM);
assumeTrue(fixture != NodeStoreFixtures.DOCUMENT_NS);
assumeTrue(fixture != NodeStoreFixtures.DOCUMENT_RDB);
CommitHook hook = new CompositeHook(new ConflictHook(JcrConflictHandler.createJcrConflictHandler()), new EditorHook(new ConflictValidatorProvider()));
NodeBuilder b1 = store.getRoot().builder();
NodeBuilder b2 = store.getRoot().builder();
// rather the in memory one from AbstractRebaseDiff
for (int k = 0; k < 1002; k++) {
b1.setChildNode("n" + k);
b2.setChildNode("m" + k);
}
b1.setChildNode("conflict");
b2.setChildNode("conflict");
store.merge(b1, hook, CommitInfo.EMPTY);
store.merge(b2, hook, CommitInfo.EMPTY);
}
use of org.apache.jackrabbit.oak.spi.commit.CommitHook in project jackrabbit-oak by apache.
the class Jcr method setUpOak.
private void setUpOak() {
// whiteboard
if (whiteboard != null) {
oak.with(whiteboard);
}
// repository initializers
for (RepositoryInitializer repositoryInitializer : repositoryInitializers) {
oak.with(repositoryInitializer);
}
// query index providers
for (QueryIndexProvider queryIndexProvider : queryIndexProviders) {
oak.with(queryIndexProvider);
}
// commit hooks
for (CommitHook commitHook : commitHooks) {
oak.with(commitHook);
}
// conflict handlers
oak.with(conflictHandler);
// index editor providers
for (IndexEditorProvider indexEditorProvider : indexEditorProviders) {
oak.with(indexEditorProvider);
}
// editors
for (Editor editor : editors) {
oak.with(editor);
}
// editor providers
for (EditorProvider editorProvider : editorProviders) {
oak.with(editorProvider);
}
// securityProvider
oak.with(securityProvider);
// executors
if (scheduledExecutor != null) {
oak.with(scheduledExecutor);
}
if (executor != null) {
oak.with(executor);
}
// observers
for (Observer observer : observers) {
oak.with(observer);
}
// commit rate limiter
if (commitRateLimiter != null) {
oak.with(commitRateLimiter);
}
// query engine settings
if (queryEngineSettings != null) {
oak.with(queryEngineSettings);
}
// default workspace name
if (defaultWorkspaceName != null) {
oak.with(defaultWorkspaceName);
}
if (clusterable != null) {
oak.with(clusterable);
}
}
use of org.apache.jackrabbit.oak.spi.commit.CommitHook in project jackrabbit-oak by apache.
the class NodeStoreTest method beforeCommitHook.
@Test
public void beforeCommitHook() throws CommitFailedException {
NodeState root = store.getRoot();
NodeBuilder rootBuilder = root.builder();
NodeBuilder testBuilder = rootBuilder.child("test");
NodeBuilder newNodeBuilder = testBuilder.child("newNode");
newNodeBuilder.setProperty("n", 42);
testBuilder.getChildNode("a").remove();
store.merge(rootBuilder, new CommitHook() {
@Nonnull
@Override
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) {
NodeBuilder rootBuilder = after.builder();
NodeBuilder testBuilder = rootBuilder.child("test");
testBuilder.child("fromHook");
return rootBuilder.getNodeState();
}
}, CommitInfo.EMPTY);
NodeState test = store.getRoot().getChildNode("test");
assertTrue(test.getChildNode("newNode").exists());
assertTrue(test.getChildNode("fromHook").exists());
assertFalse(test.getChildNode("a").exists());
assertEquals(42, (long) test.getChildNode("newNode").getProperty("n").getValue(LONG));
assertEquals(test, store.getRoot().getChildNode("test"));
}
use of org.apache.jackrabbit.oak.spi.commit.CommitHook in project jackrabbit-oak by apache.
the class NodeStoreTest method addChangeChangedJCRLastModified.
@Test
public void addChangeChangedJCRLastModified() throws CommitFailedException {
CommitHook hook = new CompositeHook(new ConflictHook(JcrConflictHandler.createJcrConflictHandler()), new EditorHook(new ConflictValidatorProvider()));
NodeBuilder b = store.getRoot().builder();
Calendar calendar = Calendar.getInstance();
b.setChildNode("addExistingNodeJCRLastModified").setProperty(JCR_LASTMODIFIED, calendar);
store.merge(b, hook, CommitInfo.EMPTY);
NodeBuilder b1 = store.getRoot().builder();
NodeBuilder b2 = store.getRoot().builder();
calendar.add(Calendar.MINUTE, 1);
b1.setChildNode("addExistingNodeJCRLastModified").setProperty(JCR_LASTMODIFIED, calendar);
calendar.add(Calendar.MINUTE, 1);
b2.setChildNode("addExistingNodeJCRLastModified").setProperty(JCR_LASTMODIFIED, calendar);
b1.setChildNode("conflict");
b2.setChildNode("conflict");
store.merge(b1, hook, CommitInfo.EMPTY);
store.merge(b2, hook, CommitInfo.EMPTY);
}
use of org.apache.jackrabbit.oak.spi.commit.CommitHook in project jackrabbit-oak by apache.
the class NodeStoreTest method rebaseWithFailedMerge.
// OAK-1320
@Test
public void rebaseWithFailedMerge() throws CommitFailedException {
NodeBuilder rootBuilder = store.getRoot().builder();
rootBuilder.child("foo");
// commit something in between to force rebase
NodeBuilder b = store.getRoot().builder();
b.child("bar");
store.merge(b, EmptyHook.INSTANCE, CommitInfo.EMPTY);
try {
store.merge(rootBuilder, new CommitHook() {
@Nonnull
@Override
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
throw new CommitFailedException("", 0, "commit rejected");
}
}, CommitInfo.EMPTY);
fail("must throw CommitFailedException");
} catch (CommitFailedException e) {
// expected
}
// merge again
NodeState root = store.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
assertTrue(root.hasChildNode("bar"));
}
Aggregations