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());
}
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(), "/");
}
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());
}
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;
}
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());
}
Aggregations