Search in sources :

Example 1 with FilterProvider

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

the class ObservationTest method testAggregate4.

@Test
public void testAggregate4() throws Exception {
    assumeTrue(observationManager instanceof ObservationManagerImpl);
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    JackrabbitEventFilter filter = new JackrabbitEventFilter();
    filter.setEventTypes(ALL_EVENTS);
    filter = FilterFactory.wrap(filter).withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "**/foo/**" }).withIncludeGlobPaths("/parent/**/bar/**");
    oManager.addEventListener(listener, filter);
    ChangeProcessor cp = oManager.getChangeProcessor(listener);
    assertNotNull(cp);
    FilterProvider filterProvider = cp.getFilterProvider();
    assertNotNull(filterProvider);
    assertMatches(filterProvider.getSubTrees(), "/parent");
    Node parent = getAdminSession().getRootNode().addNode("parent", "nt:unstructured");
    Node a = parent.addNode("a", "nt:unstructured");
    Node b = a.addNode("b", "nt:unstructured");
    Node bar = b.addNode("bar", "oak:Unstructured");
    // OAK-5096: in OR mode the following event also gets sent:
    listener.expect(bar.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
    Node c = bar.addNode("c", "nt:unstructured");
    // OAK-5096: in OR mode the following event also gets sent:
    listener.expectAdd(c);
    Node foo = c.addNode("foo", "nt:unstructured");
    // OAK-5096: in OR mode the following event also gets sent:
    listener.expectAdd(foo);
    Node jcrContent = foo.addNode("jcr:content", "nt:unstructured");
    listener.expectAdd(jcrContent);
    parent.getSession().save();
    Thread.sleep(1000);
    List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    List<Event> unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
    assertTrue("Missing events: " + missing, missing.isEmpty());
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) FilterProvider(org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 2 with FilterProvider

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

the class ObservationTest method includeAncestorsRemove.

@Test
public void includeAncestorsRemove() throws Exception {
    JackrabbitEventFilter filter = new JackrabbitEventFilter();
    filter.setEventTypes(ALL_EVENTS);
    filter.setAbsPath(TEST_PATH + "/a/b/c/d");
    filter.setIsDeep(true);
    filter = FilterFactory.wrap(filter).withIncludeAncestorsRemove();
    FilterProvider filterProvider = doIncludeAncestorsRemove(filter);
    // with 'includeAncestorsRemove' flag the listener is registered at '/'
    assertMatches(filterProvider.getSubTrees(), "/");
    filter = new JackrabbitEventFilter();
    filter.setEventTypes(ALL_EVENTS);
    filter.setIsDeep(true);
    filter = FilterFactory.wrap(filter).withIncludeAncestorsRemove().withIncludeGlobPaths(TEST_PATH + "/a/b/c/**");
    filterProvider = doIncludeAncestorsRemove(filter);
    // with 'includeAncestorsRemove' flag the listener is registered at '/'
    assertMatches(filterProvider.getSubTrees(), "/");
}
Also used : JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) FilterProvider(org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 3 with FilterProvider

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

the class ObservationTest method testConsecutiveGlobPaths.

@Test
public void testConsecutiveGlobPaths() throws Exception {
    Node testNode = getNode(TEST_PATH);
    Node a1 = testNode.addNode("a1");
    a1.addNode("b1").addNode("c1");
    a1.addNode("b2").addNode("c2");
    testNode.addNode("a2").addNode("b").addNode("c");
    testNode.getSession().save();
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    JackrabbitEventFilter filter = new JackrabbitEventFilter();
    filter.setEventTypes(ALL_EVENTS);
    filter = FilterFactory.wrap(filter).withIncludeGlobPaths(TEST_PATH + "/a2/**").withIncludeGlobPaths(TEST_PATH + "/a1/**");
    oManager.addEventListener(listener, filter);
    ChangeProcessor cp = oManager.getChangeProcessor(listener);
    assertNotNull(cp);
    FilterProvider filterProvider = cp.getFilterProvider();
    assertNotNull(filterProvider);
    assertMatches(filterProvider.getSubTrees(), TEST_PATH + "/a1", TEST_PATH + "/a2");
    listener.expectRemove(testNode.getNode("a1").getNode("b2")).remove();
    listener.expectRemove(testNode.getNode("a2").getNode("b")).remove();
    testNode.getSession().save();
    Thread.sleep(1000);
    List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    assertTrue("Missing events: " + missing, missing.isEmpty());
    List<Event> unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) FilterProvider(org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Example 4 with FilterProvider

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

the class ObservationTest method doIncludeAncestorsRemove.

private FilterProvider doIncludeAncestorsRemove(JackrabbitEventFilter filter) throws Exception {
    assumeTrue(observationManager instanceof ObservationManagerImpl);
    Node testNode = getNode(TEST_PATH);
    testNode.addNode("a").addNode("b").addNode("c").addNode("d").setProperty("e", 42);
    testNode.getSession().save();
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    oManager.addEventListener(listener, filter);
    Node d = testNode.getNode("a").getNode("b").getNode("c").getNode("d");
    Property e = d.getProperty("e");
    listener.expectRemove(e);
    // listener.expectRemove(d.getProperty("jcr:primaryType"));
    // d.remove();
    listener.expectRemove(d).remove();
    testNode.getSession().save();
    Thread.sleep(1000);
    List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    List<Event> unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
    assertTrue("Missing events: " + missing, missing.isEmpty());
    oManager.addEventListener(new EventListener() {

        @Override
        public void onEvent(EventIterator events) {
            while (events.hasNext()) {
                System.out.println("/a-listener GOT: " + events.next());
            }
        }
    }, NODE_REMOVED, TEST_PATH + "/a", false, null, null, false);
    System.out.println("REGISTERED");
    testNode = getNode(TEST_PATH);
    Node b = testNode.getNode("a").getNode("b");
    listener.expect(b.getPath(), NODE_REMOVED);
    listener.optional(new Expectation("/a/b/c is optionally sent depending on filter") {

        @Override
        public boolean onEvent(Event event) throws Exception {
            if (event.getPath().equals(TEST_PATH + "/a/b/c") && event.getType() == NODE_REMOVED) {
                return true;
            }
            return false;
        }
    });
    b.remove();
    // but not the jcr:primaryType
    testNode.getSession().save();
    Thread.sleep(1000);
    missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    unexpected = listener.getUnexpected();
    assertTrue("Missing events: " + missing, missing.isEmpty());
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
    Node a = testNode.getNode("a");
    listener.expect(a.getPath(), NODE_REMOVED);
    a.remove();
    // but not the jcr:primaryType
    testNode.getSession().save();
    missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
    assertTrue("Missing events: " + missing, missing.isEmpty());
    ChangeProcessor cp = oManager.getChangeProcessor(listener);
    assertNotNull(cp);
    FilterProvider filterProvider = cp.getFilterProvider();
    assertNotNull(filterProvider);
    return filterProvider;
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) ItemExistsException(javax.jcr.ItemExistsException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) TimeoutException(java.util.concurrent.TimeoutException) VersionException(javax.jcr.version.VersionException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ReferentialIntegrityException(javax.jcr.ReferentialIntegrityException) AccessDeniedException(javax.jcr.AccessDeniedException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) LockException(javax.jcr.lock.LockException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException) ExecutionException(java.util.concurrent.ExecutionException) FilterProvider(org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider) Event(javax.jcr.observation.Event) EventListener(javax.jcr.observation.EventListener) EventIterator(javax.jcr.observation.EventIterator) Property(javax.jcr.Property)

Example 5 with FilterProvider

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

the class ObservationTest method testAggregate5.

/**
 * OAK-5096 : new test case for OR mode
 */
@Test
public void testAggregate5() throws Exception {
    assumeTrue(observationManager instanceof ObservationManagerImpl);
    ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
    ExpectationListener listener = new ExpectationListener();
    JackrabbitEventFilter filter = new JackrabbitEventFilter();
    filter.setEventTypes(ALL_EVENTS);
    filter = FilterFactory.wrap(filter).withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "**/foo/**" }).withIncludeGlobPaths("/parent/**/bar/**");
    oManager.addEventListener(listener, filter);
    ChangeProcessor cp = oManager.getChangeProcessor(listener);
    assertNotNull(cp);
    FilterProvider filterProvider = cp.getFilterProvider();
    assertNotNull(filterProvider);
    assertMatches(filterProvider.getSubTrees(), "/parent");
    Node parent = getAdminSession().getRootNode().addNode("parent", "nt:unstructured");
    Node bar = parent.addNode("bar", "nt:unstructured");
    listener.expect(bar.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
    Node c = bar.addNode("c", "nt:unstructured");
    listener.expectAdd(c);
    Node foo = c.addNode("foo", "nt:unstructured");
    listener.expectAdd(foo);
    Node jcrContent = foo.addNode("jcr:content", "nt:unstructured");
    listener.expectAdd(jcrContent);
    parent.getSession().save();
    Thread.sleep(1000);
    List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
    List<Event> unexpected = listener.getUnexpected();
    assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
    assertTrue("Missing events: " + missing, missing.isEmpty());
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Event(javax.jcr.observation.Event) JackrabbitEventFilter(org.apache.jackrabbit.api.observation.JackrabbitEventFilter) FilterProvider(org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest) Test(org.junit.Test)

Aggregations

FilterProvider (org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider)10 Node (javax.jcr.Node)7 Event (javax.jcr.observation.Event)7 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)7 JackrabbitEventFilter (org.apache.jackrabbit.api.observation.JackrabbitEventFilter)6 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)5 Test (org.junit.Test)5 Session (javax.jcr.Session)2 EventIterator (javax.jcr.observation.EventIterator)2 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 AccessDeniedException (javax.jcr.AccessDeniedException)1 InvalidItemStateException (javax.jcr.InvalidItemStateException)1 ItemExistsException (javax.jcr.ItemExistsException)1 PathNotFoundException (javax.jcr.PathNotFoundException)1 Property (javax.jcr.Property)1 ReferentialIntegrityException (javax.jcr.ReferentialIntegrityException)1 RepositoryException (javax.jcr.RepositoryException)1 LockException (javax.jcr.lock.LockException)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1