use of javax.jcr.observation.EventIterator in project sling by apache.
the class SuperimposingManagerImplTest method prepareNodeCreateEvent.
private EventIterator prepareNodeCreateEvent(Resource pResource) throws RepositoryException {
String resourcePath = pResource.getPath();
Event nodeEvent = mock(Event.class);
when(nodeEvent.getType()).thenReturn(Event.NODE_ADDED);
when(nodeEvent.getPath()).thenReturn(resourcePath);
Event propertyEvent = mock(Event.class);
when(propertyEvent.getType()).thenReturn(Event.PROPERTY_ADDED);
when(propertyEvent.getPath()).thenReturn(resourcePath + "/" + SuperimposingResourceProvider.PROP_SUPERIMPOSE_SOURCE_PATH);
EventIterator eventIterator = mock(EventIterator.class);
when(eventIterator.hasNext()).thenReturn(true, true, false);
when(eventIterator.nextEvent()).thenReturn(nodeEvent, propertyEvent);
return eventIterator;
}
use of javax.jcr.observation.EventIterator in project sling by apache.
the class SuperimposingManagerImplTest method prepareNodeRemoveEvent.
private EventIterator prepareNodeRemoveEvent(Resource pResource) throws RepositoryException {
String resourcePath = pResource.getPath();
Event nodeEvent = mock(Event.class);
when(nodeEvent.getType()).thenReturn(Event.NODE_REMOVED);
when(nodeEvent.getPath()).thenReturn(resourcePath);
EventIterator eventIterator = mock(EventIterator.class);
when(eventIterator.hasNext()).thenReturn(true, false);
when(eventIterator.nextEvent()).thenReturn(nodeEvent);
return eventIterator;
}
use of javax.jcr.observation.EventIterator in project jackrabbit-oak by apache.
the class CompatibilityIssuesTest method noEventsForTouchedProperties.
/**
* OAK-948 - JR2 generates propertyChange event for touched properties while Oak does not
*/
@Test
public void noEventsForTouchedProperties() throws RepositoryException, InterruptedException {
final String testNodeName = "test_touched_node";
final String testNodePath = '/' + testNodeName;
// Create the test node
Session session = getAdminSession();
Node testNode = session.getRootNode().addNode(testNodeName);
testNode.setProperty("foo", "bar");
testNode.setProperty("foo2", "bar0");
session.save();
Session observingSession = createAdminSession();
ObservationManager observationManager = observingSession.getWorkspace().getObservationManager();
try {
final List<Event> events = new ArrayList<Event>();
final CountDownLatch latch = new CountDownLatch(1);
EventListener listener = new EventListener() {
@Override
public void onEvent(EventIterator eventIt) {
while (eventIt.hasNext()) {
events.add(eventIt.nextEvent());
}
if (!events.isEmpty()) {
latch.countDown();
}
}
};
observationManager.addEventListener(listener, PROPERTY_CHANGED, testNodePath, true, null, null, false);
// Now touch foo and modify foo2
session.getNode(testNodePath).setProperty("foo", "bar");
session.getNode(testNodePath).setProperty("foo2", "bar2");
session.save();
latch.await(60, TimeUnit.SECONDS);
// Only one event is recorded for foo2 modification
assertEquals(1, events.size());
} finally {
observingSession.logout();
}
}
use of javax.jcr.observation.EventIterator in project jackrabbit-oak by apache.
the class JackrabbitNodeTest method _testRenameEventHandling.
// Ignore("OAK-3658")
public void _testRenameEventHandling() throws RepositoryException, InterruptedException {
Session s = getHelper().getSuperuserSession();
ObservationManager mgr = s.getWorkspace().getObservationManager();
final List<Event> events = newArrayList();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
try {
mgr.addEventListener(new EventListener() {
CountDownLatch latch = latch1;
@Override
public void onEvent(EventIterator eventIterator) {
synchronized (events) {
while (eventIterator.hasNext()) {
events.add(eventIterator.nextEvent());
}
latch.countDown();
latch = latch2;
}
}
}, Event.PERSIST | Event.NODE_ADDED | Event.NODE_MOVED | Event.NODE_REMOVED, testRootNode.getPath(), true, null, null, false);
NodeIterator it = testRootNode.getNodes();
Node n = it.nextNode();
String name = n.getName();
JackrabbitNode node = (JackrabbitNode) n;
node.rename(name + 'X');
superuser.save();
StringBuilder diags = new StringBuilder();
if (!latch1.await(60, SECONDS)) {
diags.append("latch1 timed out ");
}
boolean foundMove = false;
synchronized (events) {
for (Event event : events) {
if (diags.length() != 0) {
diags.append(", ");
}
diags.append("type " + event.getType() + " " + event.getDate() + "ms " + event.getPath());
if (Event.NODE_MOVED == event.getType()) {
foundMove = true;
break;
}
}
if (events.isEmpty()) {
diags.append("none");
}
}
if (!foundMove) {
// force another event, wait some more
testRootNode.addNode(name + "XYZ");
superuser.save();
StringBuffer addDiags = new StringBuffer();
if (!latch2.await(60, SECONDS)) {
addDiags.append("latch2 timed out ");
}
synchronized (events) {
for (Event event : events) {
if (addDiags.length() != 0) {
addDiags.append(", ");
}
addDiags.append("type " + event.getType() + " " + event.getDate() + "ms " + event.getPath());
}
}
if (addDiags.length() > 0) {
diags.append("; next event after additional addNode/save operation: " + addDiags);
}
}
if (!foundMove) {
fail("Expected NODE_MOVED event upon renaming a node (received: " + diags + ")");
}
} finally {
s.logout();
}
}
use of javax.jcr.observation.EventIterator 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;
}
Aggregations