Search in sources :

Example 51 with OpenSecurityProvider

use of org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider in project jackrabbit-oak by apache.

the class CommitContextTest method attributesBeingReset.

@Test
public void attributesBeingReset() throws Exception {
    // This test can only work with DocumentNodeStore as only that
    // reattempt a failed merge. SegmentNodeStore would not do another
    // attempt
    assumeDocumentStore();
    final AtomicInteger invokeCount = new AtomicInteger();
    repository = new Oak(store).with(new OpenSecurityProvider()).with(observer).with(new CommitHook() {

        @Nonnull
        @Override
        public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
            CommitContext attrs = (CommitContext) info.getInfo().get(CommitContext.NAME);
            int count = invokeCount.getAndIncrement();
            if (count == 0) {
                attrs.set("a", "1");
                attrs.set("b", "2");
            } else {
                attrs.set("a", "3");
            }
            return after;
        }
    }).with(new CommitHook() {

        @Nonnull
        @Override
        public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
            if (invokeCount.get() == 1) {
                throw new CommitFailedException(MERGE, 0, "attribute reset test");
            }
            return after;
        }
    }).createContentRepository();
    session = newSession();
    Root root = session.getLatestRoot();
    Tree tree = root.getTree("/");
    tree.setProperty("a", 1);
    root.commit();
    assertNotNull(observer.info);
    CommitContext attrs = (CommitContext) observer.info.getInfo().get(CommitContext.NAME);
    assertEquals("3", attrs.get("a"));
    assertNull(attrs.get("b"));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Root(org.apache.jackrabbit.oak.api.Root) Nonnull(javax.annotation.Nonnull) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Oak(org.apache.jackrabbit.oak.Oak) Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Aggregations

OpenSecurityProvider (org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider)51 Oak (org.apache.jackrabbit.oak.Oak)38 InitialContent (org.apache.jackrabbit.oak.InitialContent)25 Test (org.junit.Test)19 Root (org.apache.jackrabbit.oak.api.Root)16 Tree (org.apache.jackrabbit.oak.api.Tree)14 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)14 ContentRepository (org.apache.jackrabbit.oak.api.ContentRepository)12 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)11 Before (org.junit.Before)11 IOException (java.io.IOException)8 NodeTypeIndexProvider (org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexProvider)8 QueryIndexProvider (org.apache.jackrabbit.oak.spi.query.QueryIndexProvider)8 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)7 Nonnull (javax.annotation.Nonnull)6 Closeable (java.io.Closeable)5 LuceneIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider)5 LuceneIndexProvider (org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProvider)5 Observer (org.apache.jackrabbit.oak.spi.commit.Observer)5 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)4