Search in sources :

Example 6 with CommitHook

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);
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) ConflictHook(org.apache.jackrabbit.oak.plugins.commit.ConflictHook) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 7 with CommitHook

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);
    }
}
Also used : CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) BackgroundObserver(org.apache.jackrabbit.oak.spi.commit.BackgroundObserver) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) OrderedPropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.OrderedPropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) IndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider) RepositoryInitializer(org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer) Editor(org.apache.jackrabbit.oak.spi.commit.Editor) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) OrderedPropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.OrderedPropertyIndexEditorProvider) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) ReferenceEditorProvider(org.apache.jackrabbit.oak.plugins.index.reference.ReferenceEditorProvider) NodeCounterEditorProvider(org.apache.jackrabbit.oak.plugins.index.counter.NodeCounterEditorProvider) NamespaceEditorProvider(org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider) EditorProvider(org.apache.jackrabbit.oak.spi.commit.EditorProvider) IndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider) QueryIndexProvider(org.apache.jackrabbit.oak.spi.query.QueryIndexProvider)

Example 8 with CommitHook

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"));
}
Also used : Nonnull(javax.annotation.Nonnull) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 9 with CommitHook

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);
}
Also used : CompositeHook(org.apache.jackrabbit.oak.spi.commit.CompositeHook) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) Calendar(java.util.Calendar) ConflictHook(org.apache.jackrabbit.oak.plugins.commit.ConflictHook) ConflictValidatorProvider(org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 10 with CommitHook

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"));
}
Also used : Nonnull(javax.annotation.Nonnull) CommitHook(org.apache.jackrabbit.oak.spi.commit.CommitHook) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Aggregations

CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)21 Test (org.junit.Test)12 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)10 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)9 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)9 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)9 Nonnull (javax.annotation.Nonnull)8 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)8 OakBaseTest (org.apache.jackrabbit.oak.OakBaseTest)5 ConflictHook (org.apache.jackrabbit.oak.plugins.commit.ConflictHook)4 ConflictValidatorProvider (org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider)4 ArrayList (java.util.ArrayList)3 IndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider)3 CompositeEditorProvider (org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider)3 CompositeHook (org.apache.jackrabbit.oak.spi.commit.CompositeHook)3 EditorProvider (org.apache.jackrabbit.oak.spi.commit.EditorProvider)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 Calendar (java.util.Calendar)2 CompositeIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider)2 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)2