Search in sources :

Example 1 with ChangeSet

use of org.apache.jackrabbit.oak.plugins.observation.ChangeSet 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 2 with ChangeSet

use of org.apache.jackrabbit.oak.plugins.observation.ChangeSet 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)

Example 3 with ChangeSet

use of org.apache.jackrabbit.oak.plugins.observation.ChangeSet in project jackrabbit-oak by apache.

the class JournalEntry method addTo.

private void addTo(ChangeSetBuilder changeSetBuilder) {
    String cs = (String) get(CHANGE_SET);
    ChangeSet set = null;
    if (cs == null && getChanges().keySet().isEmpty()) {
        //Purely a branch commit. So ChangeSet can be empty
        return;
    }
    if (cs != null) {
        set = ChangeSet.fromString(cs);
    } else {
        LOG.debug("Null changeSet found for JournalEntry {}. ChangeSetBuilder would be set to overflow mode", getId());
    }
    changeSetBuilder.add(set);
}
Also used : ChangeSet(org.apache.jackrabbit.oak.plugins.observation.ChangeSet)

Example 4 with ChangeSet

use of org.apache.jackrabbit.oak.plugins.observation.ChangeSet in project jackrabbit-oak by apache.

the class ExternalChangesTest method changeSetForExternalChanges.

@Test
public void changeSetForExternalChanges() 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");
    ns1.merge(b2, 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);
    assertFalse(cs.anyOverflow());
    assertThat(cs.getPropertyNames(), containsInAnyOrder("foo1", "foo2"));
}
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 5 with ChangeSet

use of org.apache.jackrabbit.oak.plugins.observation.ChangeSet in project jackrabbit-oak by apache.

the class AsyncIndexerServiceTest method changeCollectionEnabled.

@Test
public void changeCollectionEnabled() throws Exception {
    injectDefaultServices();
    Map<String, Object> config = ImmutableMap.<String, Object>of("asyncConfigs", new String[] { "async:5" });
    context.registerService(IndexEditorProvider.class, new PropertyIndexEditorProvider());
    MockOsgi.activate(service, context.bundleContext(), config);
    NodeBuilder builder = nodeStore.getRoot().builder();
    createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
    builder.child("testRoot").setProperty("foo", "abc");
    // merge it back in
    nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    CommitInfoCollector infoCollector = new CommitInfoCollector();
    nodeStore.addObserver(infoCollector);
    AsyncIndexUpdate indexUpdate = getIndexUpdate("async");
    indexUpdate.run();
    CommitContext commitContext = (CommitContext) infoCollector.infos.get(0).getInfo().get(CommitContext.NAME);
    assertNotNull(commitContext);
    ChangeSet changeSet = (ChangeSet) commitContext.get(ChangeCollectorProvider.COMMIT_CONTEXT_OBSERVATION_CHANGESET);
    assertNotNull(changeSet);
}
Also used : CommitContext(org.apache.jackrabbit.oak.spi.commit.CommitContext) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitInfoCollector(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdateTest.CommitInfoCollector) ChangeSet(org.apache.jackrabbit.oak.plugins.observation.ChangeSet) Test(org.junit.Test)

Aggregations

ChangeSet (org.apache.jackrabbit.oak.plugins.observation.ChangeSet)6 Test (org.junit.Test)5 CommitContext (org.apache.jackrabbit.oak.spi.commit.CommitContext)4 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)4 SimpleCommitContext (org.apache.jackrabbit.oak.core.SimpleCommitContext)3 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)3 Stopwatch (com.google.common.base.Stopwatch)1 CommitInfoCollector (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdateTest.CommitInfoCollector)1 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)1 ChangeSetBuilder (org.apache.jackrabbit.oak.plugins.observation.ChangeSetBuilder)1