Class EventPoller

  • All Implemented Interfaces:
    Callable<Boolean>

    public class EventPoller
    extends org.apache.sling.testing.clients.util.poller.Polling
    A poller that checks the occurrence of a given OSGi event. Can either be used via the checkEventOccurrence() class method or by instantiating an eventPoller and calling the callUntilCondition() method.
    • Field Summary

      • Fields inherited from class org.apache.sling.testing.clients.util.poller.Polling

        c, exceptions, lastException, waited
    • Constructor Summary

      Constructors 
      Constructor Description
      EventPoller​(org.apache.sling.testing.clients.SlingClient client, String topic, String path, long since)
      Instantiate a new EventPoller
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Boolean call()  
      static boolean checkEventOccurrence​(org.apache.sling.testing.clients.SlingClient client, String topic, String path, long since)
      Asynchronously checks for the occurrence of a given event in the OSGi event log.
      static boolean containsEvent​(com.fasterxml.jackson.databind.JsonNode events, String topic, String path)
      Checks if a given array of events contains an event with a given topic at a given path
      static com.fasterxml.jackson.databind.JsonNode getEventsSince​(org.apache.sling.testing.clients.SlingClient client, long timestamp)
      Returns all OSGi event since a given time.
      static long getLatestEventTimestamp​(org.apache.sling.testing.clients.SlingClient client)
      Returns a timestamp of the latest recorded OSGi event.
      • Methods inherited from class org.apache.sling.testing.clients.util.poller.Polling

        getExceptions, getLastException, getWaited, message, poll
    • Constructor Detail

      • EventPoller

        public EventPoller​(org.apache.sling.testing.clients.SlingClient client,
                           String topic,
                           String path,
                           long since)
        Instantiate a new EventPoller
        Parameters:
        client - required to read from the event log
        topic - the topic that should be looked for
        path - the path the event should occur
        since - the time from which on events are considered
    • Method Detail

      • call

        public Boolean call()
                     throws org.apache.sling.testing.clients.ClientException
        Specified by:
        call in interface Callable<Boolean>
        Overrides:
        call in class org.apache.sling.testing.clients.util.poller.Polling
        Throws:
        org.apache.sling.testing.clients.ClientException
      • getLatestEventTimestamp

        public static long getLatestEventTimestamp​(org.apache.sling.testing.clients.SlingClient client)
                                            throws org.apache.sling.testing.clients.ClientException
        Returns a timestamp of the latest recorded OSGi event.
        Parameters:
        client - required to read from the event log
        Returns:
        a timestamp of the latest event
        Throws:
        org.apache.sling.testing.clients.ClientException - if request to OSGi event log could not be made
      • getEventsSince

        public static com.fasterxml.jackson.databind.JsonNode getEventsSince​(org.apache.sling.testing.clients.SlingClient client,
                                                                             long timestamp)
                                                                      throws org.apache.sling.testing.clients.ClientException
        Returns all OSGi event since a given time.
        Parameters:
        client - required to read from the event log
        timestamp - the time from which on events are considered
        Returns:
        an array of events as JSONArray
        Throws:
        org.apache.sling.testing.clients.ClientException - if request to OSGi event log could not be made
      • containsEvent

        public static boolean containsEvent​(com.fasterxml.jackson.databind.JsonNode events,
                                            String topic,
                                            String path)
        Checks if a given array of events contains an event with a given topic at a given path
        Parameters:
        events - array of events that should be searched
        topic - the topic that should be looked for
        path - the path the event should occur
        Returns:
        true if the event was found in the given array
      • checkEventOccurrence

        public static boolean checkEventOccurrence​(org.apache.sling.testing.clients.SlingClient client,
                                                   String topic,
                                                   String path,
                                                   long since)
                                            throws InterruptedException
        Asynchronously checks for the occurrence of a given event in the OSGi event log.
        Parameters:
        client - required to read from the event log
        topic - the topic that should be looked for
        path - the path the event should occur
        since - the time from which on events are considered
        Returns:
        true if the event occurred.
        Throws:
        InterruptedException - to mark this method as waiting