Search in sources :

Example 6 with ChangeSet

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

the class ChangeCollectorProviderTest method doTestPropertyOverflown.

private void doTestPropertyOverflown(int overflowCnt) throws CommitFailedException, PrivilegedActionException {
    setup();
    Root root = session.getLatestRoot();
    Tree rootTree = root.getTree("/test");
    Tree child1 = rootTree.getChild("child1");
    Set<String> expectedPropertyNames = Sets.newHashSet();
    for (int i = 0; i < collectorProvider.getMaxItems() + overflowCnt; i++) {
        child1.setProperty("aProperty" + i, "foo");
        expectedPropertyNames.add("aProperty" + i);
    }
    root.commit();
    ChangeSet changeSet = getSingleChangeSet();
    assertMatches("parentPaths", changeSet.getParentPaths(), "/test/child1");
    assertMatches("parentNodeNames", changeSet.getParentNodeNames(), "child1");
    assertMatches("parentNodeTypes", changeSet.getParentNodeTypes(), "test:childType");
    assertMatches("allNodeTypes", changeSet.getAllNodeTypes(), "test:parentType", "test:childType");
    assertEquals("propertyNames", null, changeSet.getPropertyNames());
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) Tree(org.apache.jackrabbit.oak.api.Tree) ChangeSet(org.apache.jackrabbit.oak.spi.observation.ChangeSet)

Example 7 with ChangeSet

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

the class ChangeCollectorProviderTest method testAddNonEmptyGrandChild.

@Test
public void testAddNonEmptyGrandChild() throws CommitFailedException {
    Root root = session.getLatestRoot();
    Tree rootTree = root.getTree("/test");
    Tree child = rootTree.addChild("child");
    child.setProperty("childProperty", 1);
    Tree grandChild = child.addChild("grandChild");
    grandChild.setProperty("grandChildProperty", 2);
    root.commit();
    ChangeSet changeSet = getSingleChangeSet();
    assertMatches("parentPaths", changeSet.getParentPaths(), "/test", "/test/child", "/test/child/grandChild");
    assertMatches("parentNodeNames", changeSet.getParentNodeNames(), "test", "child", "grandChild");
    assertMatches("parentNodeTypes", changeSet.getParentNodeTypes(), "test:parentType");
    assertMatches("allNodeTypes", changeSet.getAllNodeTypes(), "test:parentType");
    assertMatches("propertyNames", changeSet.getPropertyNames(), "childProperty", "grandChildProperty");
}
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 8 with ChangeSet

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

the class ChangeCollectorProviderTest method testAddNodeWithProperties.

@Test
public void testAddNodeWithProperties() throws Exception {
    Root root = session.getLatestRoot();
    Tree rootTree = root.getTree("/test");
    Tree aChild = rootTree.addChild("newchild");
    aChild.setProperty("aProp", "aValue", Type.NAME);
    aChild.setProperty(JcrConstants.JCR_PRIMARYTYPE, "aPrimaryType", Type.NAME);
    root.commit();
    ChangeSet changeSet = getSingleChangeSet();
    assertMatches("parentPaths", changeSet.getParentPaths(), "/test", "/test/newchild");
    assertMatches("parentNodeNames", changeSet.getParentNodeNames(), "test", "newchild");
    assertMatches("parentNodeTypes", changeSet.getParentNodeTypes(), "test:parentType", "aPrimaryType");
    assertMatches("allNodeTypes", changeSet.getAllNodeTypes(), "test:parentType", "aPrimaryType");
    assertMatches("propertyNames", changeSet.getPropertyNames(), JcrConstants.JCR_PRIMARYTYPE, "aProp");
}
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 9 with ChangeSet

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

the class ChangeCollectorProviderTest method testAddEmptyChild.

@Test
public void testAddEmptyChild() throws CommitFailedException {
    Root root = session.getLatestRoot();
    Tree rootTree = root.getTree("/test");
    rootTree.addChild("child");
    root.commit();
    ChangeSet changeSet = getSingleChangeSet();
    assertMatches("parentPaths", changeSet.getParentPaths(), "/test");
    assertMatches("parentNodeNames", changeSet.getParentNodeNames(), "test");
    assertMatches("parentNodeTypes", changeSet.getParentNodeTypes(), "test:parentType");
    assertMatches("allNodeTypes", changeSet.getAllNodeTypes(), "test:parentType");
    assertMatches("propertyNames", changeSet.getPropertyNames());
}
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 10 with ChangeSet

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

the class ChangeCollectorProviderTest method doChangeMaxPathDepth.

private void doChangeMaxPathDepth(int changeAt, 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();
    recorder.changes.clear();
    // now do the change
    root = session.getLatestRoot();
    rootTree = root.getTree("/test");
    next = rootTree;
    List<String> expectedParentPaths = new LinkedList<String>();
    List<String> expectedParentNodeNames = new LinkedList<String>();
    Set<String> expectedAllNodeTypes = new HashSet<String>();
    List<String> expectedParentNodeTypes = new LinkedList<String>();
    List<String> expectedPropertyNames = new LinkedList<String>();
    expectedPropertyNames.add(JcrConstants.JCR_PRIMARYTYPE);
    String parent = "/";
    if (maxPathDepth > 0) {
        parent = "/test";
    }
    expectedAllNodeTypes.add("test:parentType");
    for (int i = 0; i <= changeAt; i++) {
        String childName = "n" + i;
        next = next.getChild(childName);
        if (i < maxPathDepth - 1) {
            parent = concat(parent, childName);
        }
        final String originalNodeTypeName = i % 2 == 0 ? "test:even" : "test:odd";
        if (i % 3 != 0) {
            if (i == changeAt) {
                expectedParentNodeTypes.add(originalNodeTypeName);
            }
            expectedAllNodeTypes.add(originalNodeTypeName);
        }
        if (i == changeAt) {
            expectedParentNodeNames.add(next.getName());
            String propertyName = "nextProp" + i;
            next.setProperty(propertyName, i + 1);
            expectedPropertyNames.add(propertyName);
            final String changedNodeTypeName = i % 2 == 0 ? "test:evenChanged" : "test:oddChanged";
            expectedParentNodeTypes.add(changedNodeTypeName);
            expectedAllNodeTypes.add(changedNodeTypeName);
            next.setProperty(JcrConstants.JCR_PRIMARYTYPE, changedNodeTypeName, Type.NAME);
        }
    }
    expectedParentPaths.add(parent);
    root.commit();
    ChangeSet changeSet = getSingleChangeSet();
    assertMatches("parentPaths-" + changeAt + "-" + maxPathDepth, changeSet.getParentPaths(), expectedParentPaths.toArray(new String[0]));
    assertMatches("parentNodeNames-" + changeAt + "-" + maxPathDepth, changeSet.getParentNodeNames(), expectedParentNodeNames.toArray(new String[0]));
    assertMatches("parentNodeTypes-" + changeAt + "-" + maxPathDepth, changeSet.getParentNodeTypes(), expectedParentNodeTypes.toArray(new String[0]));
    assertMatches("allNodeTypes-" + changeAt + "-" + maxPathDepth, changeSet.getAllNodeTypes(), expectedAllNodeTypes.toArray(new String[0]));
    assertMatches("propertyNames-" + changeAt + "-" + maxPathDepth, changeSet.getPropertyNames(), expectedPropertyNames.toArray(new String[0]));
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) Tree(org.apache.jackrabbit.oak.api.Tree) ChangeSet(org.apache.jackrabbit.oak.spi.observation.ChangeSet) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

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