Search in sources :

Example 21 with ChangeSet

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

the class ChangeCollectorProviderTest method doRemoveMaxPathDepth.

private void doRemoveMaxPathDepth(int maxPathDepth) throws CommitFailedException {
    collectorProvider.setMaxPathDepth(maxPathDepth);
    Root root = session.getLatestRoot();
    Tree rootTree = root.getTree("/test");
    Tree next = rootTree;
    for (int i = 0; i < 16; i++) {
        next = next.addChild("n" + i);
        if (i % 3 != 0) {
            next.setProperty("nextProp" + i, i);
            next.setProperty(JcrConstants.JCR_PRIMARYTYPE, i % 2 == 0 ? "test:even" : "test:odd", Type.NAME);
        }
    }
    root.commit();
    // now do the delete
    recorder.changes.clear();
    root = session.getLatestRoot();
    rootTree = root.getTree("/test");
    next = rootTree;
    for (int i = 0; i < 15; i++) {
        next = next.getChild("n" + i);
        if (i == 14) {
            next.remove();
        }
    }
    root.commit();
    ChangeSet changeSet = getSingleChangeSet();
    Set<String> expectedParentPaths = new HashSet<String>();
    String path = "/";
    if (maxPathDepth == 1) {
        path = "/test";
    } else if (maxPathDepth > 1) {
        path = "/test";
        for (int i = 0; i < maxPathDepth - 1; i++) {
            path = concat(path, "n" + i);
        }
    }
    expectedParentPaths.add(path);
    assertMatches("parentPaths-" + maxPathDepth, changeSet.getParentPaths(), expectedParentPaths.toArray(new String[0]));
    assertMatches("parentNodeNames-" + maxPathDepth, changeSet.getParentNodeNames(), "n13", "n14");
    assertMatches("parentNodeTypes-" + maxPathDepth, changeSet.getParentNodeTypes(), "test:even", "test:odd");
    assertMatches("allNodeTypes-" + maxPathDepth, changeSet.getAllNodeTypes(), "test:parentType", "test:even", "test:odd");
    assertMatches("propertyNames-" + maxPathDepth, changeSet.getPropertyNames(), JcrConstants.JCR_PRIMARYTYPE, "nextProp14");
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) Tree(org.apache.jackrabbit.oak.api.Tree) ChangeSet(org.apache.jackrabbit.oak.spi.observation.ChangeSet) HashSet(java.util.HashSet)

Example 22 with ChangeSet

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

the class ChangeCollectorProviderTest method testPathNotOverflown.

@Test
public void testPathNotOverflown() throws Exception {
    Root root = session.getLatestRoot();
    Tree rootTree = root.getTree("/test");
    Set<String> expectedParentPaths = Sets.newHashSet();
    expectedParentPaths.add("/test");
    Set<String> expectedParentNodeNames = Sets.newHashSet();
    expectedParentNodeNames.add("test");
    Set<String> expectedParentNodeTypes = Sets.newHashSet();
    expectedParentNodeTypes.add("test:parentType");
    // avoid overflowing
    for (int i = 0; i < collectorProvider.getMaxItems() - 1; i++) {
        Tree aChild = rootTree.addChild("manychildren" + i);
        aChild.setProperty("aProperty", "foo");
        aChild.setProperty(JcrConstants.JCR_PRIMARYTYPE, "aChildPrimaryType" + i, Type.NAME);
        expectedParentPaths.add("/test/manychildren" + i);
        expectedParentNodeNames.add("manychildren" + i);
        expectedParentNodeTypes.add("aChildPrimaryType" + i);
    }
    root.commit();
    ChangeSet changeSet = getSingleChangeSet();
    assertMatches("parentPaths", changeSet.getParentPaths(), expectedParentPaths.toArray(new String[0]));
    assertMatches("parentNodeNames", changeSet.getParentNodeNames(), expectedParentNodeNames.toArray(new String[0]));
    assertMatches("parentNodeTypes", changeSet.getParentNodeTypes(), expectedParentNodeTypes.toArray(new String[0]));
    assertMatches("allNodeTypes", changeSet.getAllNodeTypes(), expectedParentNodeTypes.toArray(new String[0]));
    assertMatches("propertyNames", changeSet.getPropertyNames(), JcrConstants.JCR_PRIMARYTYPE, "aProperty");
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) Tree(org.apache.jackrabbit.oak.api.Tree) ChangeSet(org.apache.jackrabbit.oak.spi.observation.ChangeSet) Test(org.junit.Test)

Example 23 with ChangeSet

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

the class ChangeCollectorProviderTest method testRemoveGreatGrandChild.

@Test
public void testRemoveGreatGrandChild() throws CommitFailedException {
    Root root = session.getLatestRoot();
    Tree rootTree = root.getTree("/test");
    assertTrue(rootTree.getChild("child1").getChild("grandChild1").getChild("greatGrandChild1").remove());
    root.commit();
    ChangeSet changeSet = getSingleChangeSet();
    assertMatches("parentPaths", changeSet.getParentPaths(), "/test/child1/grandChild1/greatGrandChild1", "/test/child1/grandChild1");
    assertMatches("parentNodeNames", changeSet.getParentNodeNames(), "grandChild1", "greatGrandChild1");
    assertMatches("parentNodeTypes", changeSet.getParentNodeTypes(), "test:greatGrandChildType", "test:grandChildType");
    assertMatches("allNodeTypes", changeSet.getAllNodeTypes(), "test:parentType", "test:childType", "test:grandChildType", "test:greatGrandChildType");
    assertMatches("propertyNames", changeSet.getPropertyNames(), JcrConstants.JCR_PRIMARYTYPE, "greatGrandChild1Prop");
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) Tree(org.apache.jackrabbit.oak.api.Tree) ChangeSet(org.apache.jackrabbit.oak.spi.observation.ChangeSet) Test(org.junit.Test)

Example 24 with ChangeSet

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

the class ChangeCollectorProviderTest method testChangeGreatAndGrandChild.

@Test
public void testChangeGreatAndGrandChild() throws CommitFailedException {
    Root root = session.getLatestRoot();
    Tree rootTree = root.getTree("/test");
    rootTree.getChild("child1").getChild("grandChild1").setProperty("grandChild1Prop", 2);
    rootTree.getChild("child1").getChild("grandChild1").getChild("greatGrandChild1").setProperty("greatGrandChild1Prop", 2);
    root.commit();
    ChangeSet changeSet = getSingleChangeSet();
    assertMatches("parentPaths", changeSet.getParentPaths(), "/test/child1/grandChild1", "/test/child1/grandChild1/greatGrandChild1");
    assertMatches("parentNodeNames", changeSet.getParentNodeNames(), "grandChild1", "greatGrandChild1");
    assertMatches("parentNodeTypes", changeSet.getParentNodeTypes(), "test:grandChildType", "test:greatGrandChildType");
    assertMatches("allNodeTypes", changeSet.getAllNodeTypes(), "test:parentType", "test:childType", "test:grandChildType", "test:greatGrandChildType");
    assertMatches("propertyNames", changeSet.getPropertyNames(), "grandChild1Prop", "greatGrandChild1Prop");
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) Tree(org.apache.jackrabbit.oak.api.Tree) ChangeSet(org.apache.jackrabbit.oak.spi.observation.ChangeSet) Test(org.junit.Test)

Example 25 with ChangeSet

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

the class ChangeCollectorProviderTest method testRemoveChild.

@Test
public void testRemoveChild() throws CommitFailedException {
    Root root = session.getLatestRoot();
    Tree rootTree = root.getTree("/test");
    assertTrue(rootTree.getChild("child1").remove());
    root.commit();
    ChangeSet changeSet = getSingleChangeSet();
    assertMatches("parentPaths", changeSet.getParentPaths(), "/test", "/test/child1", "/test/child1/grandChild1", "/test/child1/grandChild1/greatGrandChild1");
    assertMatches("parentNodeNames", changeSet.getParentNodeNames(), "test", "child1", "grandChild1", "greatGrandChild1");
    assertMatches("parentNodeTypes", changeSet.getParentNodeTypes(), "test:parentType", "test:childType", "test:grandChildType", "test:greatGrandChildType");
    assertMatches("allNodeTypes", changeSet.getAllNodeTypes(), "test:parentType", "test:childType", "test:grandChildType", "test:greatGrandChildType");
    assertMatches("propertyNames", changeSet.getPropertyNames(), JcrConstants.JCR_PRIMARYTYPE, "child1Prop", "grandChild1Prop", "greatGrandChild1Prop");
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) Tree(org.apache.jackrabbit.oak.api.Tree) ChangeSet(org.apache.jackrabbit.oak.spi.observation.ChangeSet) Test(org.junit.Test)

Aggregations

ChangeSet (org.apache.jackrabbit.oak.spi.observation.ChangeSet)26 Root (org.apache.jackrabbit.oak.api.Root)19 Tree (org.apache.jackrabbit.oak.api.Tree)19 Test (org.junit.Test)18 CommitContext (org.apache.jackrabbit.oak.spi.commit.CommitContext)5 SimpleCommitContext (org.apache.jackrabbit.oak.spi.commit.SimpleCommitContext)4 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)4 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Stopwatch (com.google.common.base.Stopwatch)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 InitialContent (org.apache.jackrabbit.oak.InitialContent)1 Oak (org.apache.jackrabbit.oak.Oak)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.spi.observation.ChangeSetBuilder)1 Before (org.junit.Before)1