Search in sources :

Example 11 with CommitInfo

use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.

the class IndexUpdateTest method contextAwareCallback.

@Test
public void contextAwareCallback() throws Exception {
    NodeState before = builder.getNodeState();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null);
    NodeState after = builder.getNodeState();
    CallbackCapturingProvider provider = new CallbackCapturingProvider();
    EditorHook hook = new EditorHook(new IndexUpdateProvider(provider));
    CommitInfo info = new CommitInfo("foo", "bar");
    NodeState indexed = hook.processCommit(before, after, info);
    assertNotNull(provider.callback);
    assertThat(provider.callback, instanceOf(ContextAwareCallback.class));
    ContextAwareCallback contextualCallback = (ContextAwareCallback) provider.callback;
    IndexingContext context = contextualCallback.getIndexingContext();
    assertNotNull(context);
    assertEquals("/oak:index/rootIndex", context.getIndexPath());
    assertTrue(context.isReindexing());
    assertFalse(context.isAsync());
    assertSame(info, context.getCommitInfo());
    before = indexed;
    builder = indexed.builder();
    builder.child("a").setProperty("foo", "bar");
    after = builder.getNodeState();
    hook.processCommit(before, after, info);
    assertFalse(((ContextAwareCallback) provider.callback).getIndexingContext().isReindexing());
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) Test(org.junit.Test)

Example 12 with CommitInfo

use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.

the class MutableRoot method commit.

@Override
public void commit(@Nonnull Map<String, Object> info) throws CommitFailedException {
    checkLive();
    ContentSession session = getContentSession();
    CommitInfo commitInfo = new CommitInfo(session.toString(), session.getAuthInfo().getUserID(), newInfoWithCommitContext(info));
    store.merge(builder, getCommitHook(), commitInfo);
    secureBuilder.baseChanged();
    modCount = 0;
    if (permissionProvider.hasValue()) {
        permissionProvider.get().refresh();
    }
    moveTracker.clear();
}
Also used : ContentSession(org.apache.jackrabbit.oak.api.ContentSession) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo)

Example 13 with CommitInfo

use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.

the class ExternalChangesTest method journalService.

@Test
public void journalService() throws Exception {
    wb.register(JournalPropertyService.class, new TestJournalService(), null);
    //Do a dummy write so that journal property handler gets refreshed
    //and picks our newly registered service
    NodeBuilder b0 = ns1.getRoot().builder();
    b0.child("0");
    ns1.merge(b0, newCollectingHook(), newCommitInfo());
    ns1.runBackgroundUpdateOperations();
    NodeBuilder b1 = ns1.getRoot().builder();
    b1.child("a");
    CommitContext cc = new SimpleCommitContext();
    cc.set(TestProperty.NAME, new TestProperty("foo"));
    ns1.merge(b1, newCollectingHook(), newCommitInfo(cc));
    NodeBuilder b2 = ns1.getRoot().builder();
    b2.child("b");
    cc = new SimpleCommitContext();
    cc.set(TestProperty.NAME, new TestProperty("bar"));
    ns1.merge(b2, newCollectingHook(), newCommitInfo(cc));
    //null entry
    NodeBuilder b3 = ns1.getRoot().builder();
    b3.child("c");
    ns1.merge(b3, newCollectingHook(), newCommitInfo());
    ns1.runBackgroundUpdateOperations();
    c2.reset();
    ns2.runBackgroundReadOperations();
    CommitInfo ci = c2.getExternalChange();
    cc = (CommitContext) ci.getInfo().get(CommitContext.NAME);
    CumulativeTestProperty ct = (CumulativeTestProperty) cc.get(TestProperty.NAME);
    assertNotNull(ct);
    assertThat(ct.values, containsInAnyOrder("foo", "bar", "NULL"));
}
Also used : CommitContext(org.apache.jackrabbit.oak.spi.commit.CommitContext) SimpleCommitContext(org.apache.jackrabbit.oak.core.SimpleCommitContext) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) SimpleCommitContext(org.apache.jackrabbit.oak.core.SimpleCommitContext) Test(org.junit.Test)

Example 14 with CommitInfo

use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.

the class ExternalChangesTest method changeSetForBranchCommit.

@Test
public void changeSetForBranchCommit() throws Exception {
    final int NUM_NODES = DocumentMK.UPDATE_LIMIT / 2;
    final int NUM_PROPS = 10;
    Set<String> propNames = Sets.newHashSet();
    NodeBuilder b1 = ns1.getRoot().builder();
    for (int i = 0; i < NUM_NODES; i++) {
        NodeBuilder c = b1.child("n" + i);
        for (int j = 0; j < NUM_PROPS; j++) {
            c.setProperty("q" + j, "value");
            c.setProperty("p" + j, "value");
            propNames.add("q" + j);
            propNames.add("p" + j);
        }
    }
    ns1.merge(b1, newCollectingHook(), newCommitInfo());
    ns1.runBackgroundUpdateOperations();
    c2.reset();
    ns2.runBackgroundReadOperations();
    CommitInfo ci = c2.getExternalChange();
    CommitContext cc = (CommitContext) ci.getInfo().get(CommitContext.NAME);
    assertNotNull(cc);
    ChangeSet cs = (ChangeSet) cc.get(ChangeCollectorProvider.COMMIT_CONTEXT_OBSERVATION_CHANGESET);
    assertNotNull(cs);
    assertTrue(cs.getPropertyNames().containsAll(propNames));
}
Also used : CommitContext(org.apache.jackrabbit.oak.spi.commit.CommitContext) SimpleCommitContext(org.apache.jackrabbit.oak.core.SimpleCommitContext) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) ChangeSet(org.apache.jackrabbit.oak.plugins.observation.ChangeSet) Test(org.junit.Test)

Example 15 with CommitInfo

use of org.apache.jackrabbit.oak.spi.commit.CommitInfo in project jackrabbit-oak by apache.

the class ExternalChangesTest method missingChangeSetResultsInOverflow.

@Test
public void missingChangeSetResultsInOverflow() throws Exception {
    NodeBuilder b1 = ns1.getRoot().builder();
    b1.child("a");
    b1.setProperty("foo1", "bar");
    ns1.merge(b1, newCollectingHook(), newCommitInfo());
    NodeBuilder b2 = ns1.getRoot().builder();
    b2.child("b");
    b2.setProperty("foo2", "bar");
    //Commit without ChangeSet
    ns1.merge(b2, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    ns1.runBackgroundUpdateOperations();
    c2.reset();
    ns2.runBackgroundReadOperations();
    CommitInfo ci = c2.getExternalChange();
    CommitContext cc = (CommitContext) ci.getInfo().get(CommitContext.NAME);
    assertNotNull(cc);
    ChangeSet cs = (ChangeSet) cc.get(ChangeCollectorProvider.COMMIT_CONTEXT_OBSERVATION_CHANGESET);
    assertNotNull(cs);
    //ChangeSet should result in overflow
    assertTrue(cs.anyOverflow());
}
Also used : CommitContext(org.apache.jackrabbit.oak.spi.commit.CommitContext) SimpleCommitContext(org.apache.jackrabbit.oak.core.SimpleCommitContext) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) ChangeSet(org.apache.jackrabbit.oak.plugins.observation.ChangeSet) Test(org.junit.Test)

Aggregations

CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)39 Test (org.junit.Test)29 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)23 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)16 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)11 CommitHook (org.apache.jackrabbit.oak.spi.commit.CommitHook)9 Nonnull (javax.annotation.Nonnull)7 Observer (org.apache.jackrabbit.oak.spi.commit.Observer)7 SimpleCommitContext (org.apache.jackrabbit.oak.core.SimpleCommitContext)6 CommitContext (org.apache.jackrabbit.oak.spi.commit.CommitContext)6 OakBaseTest (org.apache.jackrabbit.oak.OakBaseTest)4 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)3 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)3 ChangeSet (org.apache.jackrabbit.oak.plugins.observation.ChangeSet)3 EditorProvider (org.apache.jackrabbit.oak.spi.commit.EditorProvider)3 Observable (org.apache.jackrabbit.oak.spi.commit.Observable)3 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)3