use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter in project jackrabbit-oak by apache.
the class ObservationTest method applyNodeTypeOnSelf.
// ------------------------------------------------------------< OakEventFilter tests >---
@Test
public void applyNodeTypeOnSelf() throws Exception {
assumeTrue(observationManager instanceof ObservationManagerImpl);
Node testNode = getNode(TEST_PATH);
testNode.addNode("a", "nt:unstructured").addNode("b", "oak:Unstructured").addNode("c", "nt:unstructured");
testNode.getSession().save();
ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter();
filter.setEventTypes(ALL_EVENTS);
filter.setAbsPath("/");
filter.setIsDeep(true);
filter.setNodeTypes(new String[] { "oak:Unstructured" });
filter = FilterFactory.wrap(filter).withApplyNodeTypeOnSelf();
oManager.addEventListener(listener, filter);
testNode.getNode("a").getNode("b").getNode("c").remove();
testNode.getSession().save();
// wait 1 sec to give failures a chance (we're not expecting anything, but perhaps
// something would come, after 1sec more likely than after 0sec)
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());
Node b = testNode.getNode("a").getNode("b");
// OAK-5061 : the event NODE_REMOVED on /a/b is actually expected and was missing in the test:
listener.expect(b.getPath(), NODE_REMOVED);
b.remove();
testNode.getSession().save();
Thread.sleep(1000);
missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
assertTrue("Missing events: " + missing, missing.isEmpty());
unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
}
use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter 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());
}
use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter in project jackrabbit-oak by apache.
the class ObservationTest method includeGlobPaths.
@Test
public void includeGlobPaths() throws Exception {
Node testNode = getNode(TEST_PATH);
testNode.addNode("a1").addNode("b").addNode("c");
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/**");
oManager.addEventListener(listener, filter);
ChangeProcessor cp = oManager.getChangeProcessor(listener);
assertNotNull(cp);
FilterProvider filterProvider = cp.getFilterProvider();
assertNotNull(filterProvider);
assertMatches(filterProvider.getSubTrees(), TEST_PATH + "/a2");
testNode.getNode("a1").getNode("b").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());
Node a3 = testNode.addNode("a3");
Node foo = a3.addNode("bar").addNode("foo");
testNode.getSession().save();
filter = new JackrabbitEventFilter();
filter.setEventTypes(ALL_EVENTS);
// filter.setAbsPath(TEST_PATH + "/a3/bar/foo/x");
filter = FilterFactory.wrap(filter).withIncludeGlobPaths(TEST_PATH + "/a3/**/x");
oManager.addEventListener(listener, filter);
cp = oManager.getChangeProcessor(listener);
assertNotNull(cp);
filterProvider = cp.getFilterProvider();
assertNotNull(filterProvider);
assertMatches(filterProvider.getSubTrees(), TEST_PATH + "/a3");
Node x = foo.addNode("x");
listener.expect(x.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
testNode.getSession().save();
Thread.sleep(1000);
missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
assertTrue("Missing events: " + missing, missing.isEmpty());
unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
filter = new JackrabbitEventFilter();
filter.setEventTypes(ALL_EVENTS);
filter = FilterFactory.wrap(filter).withIncludeGlobPaths(TEST_PATH + "/a3/**/y");
oManager.addEventListener(listener, filter);
cp = oManager.getChangeProcessor(listener);
assertNotNull(cp);
filterProvider = cp.getFilterProvider();
assertNotNull(filterProvider);
assertMatches(filterProvider.getSubTrees(), TEST_PATH + "/a3");
Node y = foo.addNode("y");
listener.expect(y.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
testNode.getSession().save();
Thread.sleep(1000);
missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
assertTrue("Missing events: " + missing, missing.isEmpty());
unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
}
use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter in project jackrabbit by apache.
the class ObservationManagerImpl method addEventListener.
@Override
public void addEventListener(EventListener listener, JackrabbitEventFilter filter) throws RepositoryException {
String[] excludedPaths = filter.getExcludedPaths();
if (excludedPaths.length > 0) {
log.warn("JackrabbitEventFilter excludedPaths is not implemented and will be ignored: {}", Arrays.toString(excludedPaths));
}
List<String> absPaths = new ArrayList<String>(Arrays.asList(filter.getAdditionalPaths()));
if (filter.getAbsPath() != null) {
absPaths.add(filter.getAbsPath());
}
EventFilter f = createEventFilter(filter.getEventTypes(), absPaths, filter.getIsDeep(), filter.getIdentifiers(), filter.getNodeTypes(), filter.getNoLocal(), filter.getNoExternal(), filter.getNoInternal());
dispatcher.addConsumer(new EventConsumer(session, listener, f));
}
use of org.apache.jackrabbit.api.observation.JackrabbitEventFilter in project jackrabbit by apache.
the class JackrabbitObservationManagerTest method testDisjunctPaths.
public void testDisjunctPaths() throws ExecutionException, InterruptedException, RepositoryException {
JackrabbitObservationManager oManager = (JackrabbitObservationManager) obsMgr;
EventResult listener = new EventResult(log);
JackrabbitEventFilter filter = new JackrabbitEventFilter().setAdditionalPaths('/' + testPath + "/a", '/' + testPath + "/x").setEventTypes(NODE_ADDED);
oManager.addEventListener(listener, filter);
try {
Node b = testRootNode.addNode("a").addNode("b");
b.addNode("c");
Node y = testRootNode.addNode("x").addNode("y");
y.addNode("z");
testRootNode.getSession().save();
Event[] added = listener.getEvents(DEFAULT_WAIT_TIMEOUT);
checkNodeAdded(added, new String[] { "a/b", "x/y" }, null);
} finally {
oManager.removeEventListener(listener);
}
}
Aggregations