Search in sources :

Example 26 with EventIterator

use of javax.jcr.observation.EventIterator in project jackrabbit by apache.

the class EventIteratorTest method testGetPosition.

/**
 * Tests if getPosition() returns the correct values.
 */
public void testGetPosition() throws RepositoryException {
    EventResult listener = new EventResult(log);
    addEventListener(listener, Event.NODE_ADDED);
    testRootNode.addNode(nodeName1, testNodeType);
    testRootNode.addNode(nodeName2, testNodeType);
    testRootNode.addNode(nodeName3, testNodeType);
    testRootNode.getSession().save();
    EventIterator events = listener.getEventIterator(DEFAULT_WAIT_TIMEOUT);
    removeEventListener(listener);
    assertNotNull("No events delivered within " + DEFAULT_WAIT_TIMEOUT + "ms.", events);
    assertEquals("Initial call to getPosition() must return 0.", 0, events.getPosition());
    events.nextEvent();
    assertEquals("Wrong value for getPosition()", 1, events.getPosition());
    events.nextEvent();
    assertEquals("Wrong value for getPosition()", 2, events.getPosition());
    events.nextEvent();
    assertEquals("Wrong value for getPosition()", 3, events.getPosition());
}
Also used : EventIterator(javax.jcr.observation.EventIterator)

Aggregations

EventIterator (javax.jcr.observation.EventIterator)26 Event (javax.jcr.observation.Event)14 EventListener (javax.jcr.observation.EventListener)12 RepositoryException (javax.jcr.RepositoryException)9 Session (javax.jcr.Session)9 Node (javax.jcr.Node)7 ObservationManager (javax.jcr.observation.ObservationManager)7 ArrayList (java.util.ArrayList)4 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)3 JackrabbitEvent (org.apache.jackrabbit.api.observation.JackrabbitEvent)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 Lock (javax.jcr.lock.Lock)2 FilterProvider (org.apache.jackrabbit.oak.plugins.observation.filter.FilterProvider)2 File (java.io.File)1 IOException (java.io.IOException)1 RemoteException (java.rmi.RemoteException)1 HashMap (java.util.HashMap)1