use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class ClusterConflictTest method mergeRetryWhileBackgroundRead.
// OAK-3433
@Test
public void mergeRetryWhileBackgroundRead() throws Exception {
DocumentNodeStore ns1 = mk.getNodeStore();
NodeBuilder b1 = ns1.getRoot().builder();
b1.child("a").child("b").child("c").child("foo");
merge(ns1, b1);
ns1.runBackgroundOperations();
ns2.runBackgroundOperations();
NodeBuilder b2 = ns2.getRoot().builder();
// force cache fill
assertNodeExists(b2, "/a/b/c/foo");
// remove /a/b/c on ns1
b1 = ns1.getRoot().builder();
b1.child("a").child("b").child("c").remove();
merge(ns1, b1);
// perform some change on ns2
b2.child("z");
merge(ns2, b2);
runBackgroundUpdate(ns2);
// this will pickup changes done by ns2 and update
// the head revision
runBackgroundRead(ns1);
// the next step is where the issue described
// in OAK-3433 occurs.
// the journal entry with changes done on ns1 is pushed
// with the current head revision, which is newer
// than the most recent change in the journal entry
runBackgroundUpdate(ns1);
// perform a background read after the rebase
// the first merge attempt will fail with a conflict
// because /a/b/c is seen as changed in the future
// without the fix for OAK-3433:
// the second merge attempt succeeds because now the
// /a/b/c change revision is visible and happened before the commit
// revision but before the base revision
b2 = ns2.getRoot().builder();
b2.child("z").setProperty("q", "v");
try {
ns2.merge(b2, new CommitHook() {
@Nonnull
@Override
public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
runBackgroundRead(ns2);
NodeBuilder builder = after.builder();
if (builder.getChildNode("a").getChildNode("b").hasChildNode("c")) {
builder.child("a").child("b").child("c").child("bar");
} else {
throw new CommitFailedException(CommitFailedException.OAK, 0, "/a/b/c does not exist anymore");
}
return builder.getNodeState();
}
}, CommitInfo.EMPTY);
fail("Merge must fail with CommitFailedException");
} catch (CommitFailedException e) {
// expected
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class TypeEditorTest method addNamedPropertyWithBadRequiredType.
@Test
public void addNamedPropertyWithBadRequiredType() {
EditorHook hook = new EditorHook(new TypeEditorProvider());
NodeState root = INITIAL_CONTENT;
NodeBuilder builder = root.builder();
NodeState before = builder.getNodeState();
NodeBuilder testNode = builder.child("testNode");
testNode.setProperty(JCR_PRIMARYTYPE, NT_FOLDER, Type.NAME);
testNode.setProperty(JCR_MIXINTYPES, ImmutableList.of("mix:title"), Type.NAMES);
testNode.setProperty("jcr:title", true);
try {
hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
fail();
} catch (CommitFailedException e) {
assertTrue(e.isConstraintViolation());
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class TypeEditorTest method malformedUUID.
@Test
public void malformedUUID() throws CommitFailedException {
EditorHook hook = new EditorHook(new TypeEditorProvider());
NodeState root = INITIAL_CONTENT;
NodeBuilder builder = root.builder();
NodeState before = builder.getNodeState();
builder.child("testcontent").setProperty(JCR_PRIMARYTYPE, "nt:unstructured", Type.NAME);
builder.child("testcontent").setProperty("jcr:uuid", "not-a-uuid");
NodeState after = builder.getNodeState();
root = hook.processCommit(before, after, CommitInfo.EMPTY);
builder = root.builder();
before = builder.getNodeState();
builder.child("testcontent").setProperty(JCR_MIXINTYPES, ImmutableList.of(MIX_REFERENCEABLE), Type.NAMES);
try {
hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
fail("should not be able to change mixin due to illegal uuid format");
} catch (CommitFailedException e) {
assertTrue(e.isConstraintViolation());
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class TypeEditorTest method changeNodeTypeWExtraProps.
@Test
public void changeNodeTypeWExtraProps() throws CommitFailedException {
EditorHook hook = new EditorHook(new TypeEditorProvider());
NodeState root = INITIAL_CONTENT;
NodeBuilder builder = root.builder();
NodeState before = builder.getNodeState();
builder.child("testcontent").setProperty(JCR_PRIMARYTYPE, "nt:unstructured", Type.NAME);
builder.child("testcontent").setProperty("extra", "information");
NodeState after = builder.getNodeState();
root = hook.processCommit(before, after, CommitInfo.EMPTY);
builder = root.builder();
before = builder.getNodeState();
builder.child("testcontent").setProperty(JCR_PRIMARYTYPE, "nt:folder", Type.NAME);
try {
hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
fail("should not be able to change node type due to extra properties");
} catch (CommitFailedException e) {
assertTrue(e.isConstraintViolation());
}
}
use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.
the class TypeEditorTest method changeNamedPropertyToBadRequiredType.
@Test
public void changeNamedPropertyToBadRequiredType() {
EditorHook hook = new EditorHook(new TypeEditorProvider());
NodeState root = INITIAL_CONTENT;
NodeBuilder builder = root.builder();
NodeBuilder testNode = builder.child("testNode");
testNode.setProperty(JCR_PRIMARYTYPE, NT_FOLDER, Type.NAME);
testNode.setProperty(JCR_MIXINTYPES, ImmutableList.of("mix:title"), Type.NAMES);
testNode.setProperty("jcr:title", "title");
NodeState before = builder.getNodeState();
testNode.setProperty("jcr:title", true);
try {
hook.processCommit(before, builder.getNodeState(), CommitInfo.EMPTY);
fail();
} catch (CommitFailedException e) {
assertTrue(e.isConstraintViolation());
}
}
Aggregations