Search in sources :

Example 16 with ChangeSet

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

the class ChangeSetFilterImplTest method manyIncludePaths.

@Test
public void manyIncludePaths() throws Exception {
    int numPaths = 50;
    ChangeSetBuilder builder = newBuilder(50, 9);
    for (int i = 0; i < numPaths; i++) {
        builder.addParentPath("/a/b/c/d/e/n" + i);
    }
    ChangeSet cs = builder.build();
    Set<String> includes = Sets.newHashSet();
    for (int i = 0; i < 100; i++) {
        includes.add("/foo/bar/n-" + i + "/*.jsp");
    }
    ChangeSetFilter filter = new ChangeSetFilterImpl(s(), true, includes, s(), s(), s(), s());
    // warm up
    doManyIncludePaths(filter, cs);
    // and measure
    Stopwatch sw = Stopwatch.createStarted();
    doManyIncludePaths(filter, cs);
    LOG.info("manyIncludePaths() took {}", sw.stop());
}
Also used : ChangeSetBuilder(org.apache.jackrabbit.oak.spi.observation.ChangeSetBuilder) Stopwatch(com.google.common.base.Stopwatch) ChangeSet(org.apache.jackrabbit.oak.spi.observation.ChangeSet) Test(org.junit.Test)

Example 17 with ChangeSet

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

the class ChangeCollectorProviderTest method testPropertyNotOverflown.

@Test
public void testPropertyNotOverflown() throws Exception {
    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(); 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");
    assertMatches("propertyNames", 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) Test(org.junit.Test)

Example 18 with ChangeSet

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

the class ChangeCollectorProviderTest method setup.

@Before
public void setup() throws PrivilegedActionException, CommitFailedException {
    collectorProvider = new ChangeCollectorProvider();
    recorder = new Recorder();
    Oak oak = new Oak().with(new InitialContent()).with(collectorProvider).with(recorder).with(getSecurityProvider());
    contentRepository = oak.createContentRepository();
    session = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() {

        @Override
        public ContentSession run() throws LoginException, NoSuchWorkspaceException {
            return contentRepository.login(null, null);
        }
    });
    Root root = session.getLatestRoot();
    Tree rootTree = root.getTree("/").addChild("test");
    rootTree.setProperty(JcrConstants.JCR_PRIMARYTYPE, "test:parentType", Type.NAME);
    Tree child1 = rootTree.addChild("child1");
    child1.setProperty("child1Prop", 1);
    child1.setProperty(JcrConstants.JCR_PRIMARYTYPE, "test:childType", Type.NAME);
    Tree grandChild1 = child1.addChild("grandChild1");
    grandChild1.setProperty("grandChild1Prop", 1);
    grandChild1.setProperty(JcrConstants.JCR_PRIMARYTYPE, "test:grandChildType", Type.NAME);
    Tree greatGrandChild1 = grandChild1.addChild("greatGrandChild1");
    greatGrandChild1.setProperty("greatGrandChild1Prop", 1);
    greatGrandChild1.setProperty(JcrConstants.JCR_PRIMARYTYPE, "test:greatGrandChildType", Type.NAME);
    Tree child2 = rootTree.addChild("child2");
    child2.setProperty("child2Prop", 1);
    child2.setProperty(JcrConstants.JCR_PRIMARYTYPE, "test:childType", Type.NAME);
    Tree grandChild2 = child2.addChild("grandChild2");
    grandChild2.setProperty("grandChild2Prop", 1);
    grandChild2.setProperty(JcrConstants.JCR_PRIMARYTYPE, "test:grandChildType", Type.NAME);
    recorder.changes.clear();
    root.commit();
    ChangeSet changeSet = getSingleChangeSet();
    assertMatches("parentPaths", changeSet.getParentPaths(), "/test/child2", "/test/child1", "/test/child1/grandChild1/greatGrandChild1", "/", "/test", "/test/child1/grandChild1", "/test/child2/grandChild2");
    assertMatches("parentNodeNames", changeSet.getParentNodeNames(), "child2", "child1", "greatGrandChild1", "test", "grandChild1", "grandChild2");
    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", "child2Prop", "grandChild1Prop", "grandChild2Prop", "greatGrandChild1Prop");
    // clear the recorder so that we start off empty
    recorder.changes.clear();
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) Root(org.apache.jackrabbit.oak.api.Root) Oak(org.apache.jackrabbit.oak.Oak) Tree(org.apache.jackrabbit.oak.api.Tree) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ChangeSet(org.apache.jackrabbit.oak.spi.observation.ChangeSet) Before(org.junit.Before)

Example 19 with ChangeSet

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

the class ChangeCollectorProviderTest method doTestPathOverflown.

private void doTestPathOverflown(int overflowCnt) throws CommitFailedException, PrivilegedActionException {
    setup();
    Root root = session.getLatestRoot();
    Tree rootTree = root.getTree("/test");
    for (int i = 0; i < collectorProvider.getMaxItems() + overflowCnt; i++) {
        rootTree.addChild("manychildren" + i).setProperty("aProperty", "foo");
        ;
    }
    root.commit();
    ChangeSet changeSet = getSingleChangeSet();
    assertEquals("parentPaths", null, changeSet.getParentPaths());
    assertEquals("parentNodeNames", null, changeSet.getParentNodeNames());
    assertMatches("parentNodeTypes", changeSet.getParentNodeTypes(), "test:parentType");
    assertMatches("allNodeTypes", changeSet.getAllNodeTypes(), "test:parentType");
    assertMatches("propertyNames", changeSet.getPropertyNames(), "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)

Example 20 with ChangeSet

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

the class ChangeCollectorProviderTest method getSingleChangeSet.

/**
 * Assumes that the recorder got 1 call, and extracts the ChangeSet from
 * that call
 */
private ChangeSet getSingleChangeSet() {
    assertEquals(recorder.changes.size(), 1);
    CommitContext commitContext = (CommitContext) recorder.changes.get(0).info.getInfo().get(CommitContext.NAME);
    assertNotNull(commitContext);
    ChangeSet changeSet = (ChangeSet) commitContext.get(ChangeSet.COMMIT_CONTEXT_OBSERVATION_CHANGESET);
    assertNotNull(changeSet);
    return changeSet;
}
Also used : CommitContext(org.apache.jackrabbit.oak.spi.commit.CommitContext) SimpleCommitContext(org.apache.jackrabbit.oak.spi.commit.SimpleCommitContext) ChangeSet(org.apache.jackrabbit.oak.spi.observation.ChangeSet)

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