Search in sources :

Example 56 with CommitFailedException

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
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Nonnull(javax.annotation.Nonnull) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test) AbstractMongoConnectionTest(org.apache.jackrabbit.oak.plugins.document.AbstractMongoConnectionTest)

Example 57 with CommitFailedException

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());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Example 58 with CommitFailedException

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());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Example 59 with CommitFailedException

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());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Example 60 with CommitFailedException

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());
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Aggregations

CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)246 Test (org.junit.Test)166 Tree (org.apache.jackrabbit.oak.api.Tree)75 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)66 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)60 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)59 Root (org.apache.jackrabbit.oak.api.Root)48 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)42 RepositoryException (javax.jcr.RepositoryException)17 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)13 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)13 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)12 Nonnull (javax.annotation.Nonnull)10 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)10 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)10 TokenInfo (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo)10 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)9 ArrayList (java.util.ArrayList)8 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)8 UserManager (org.apache.jackrabbit.api.security.user.UserManager)7