Class Waiter


  • public class Waiter
    extends java.lang.Object
    The simplest waiter, just to not include a new dependency into the project.
    • Constructor Summary

      Constructors 
      Constructor Description
      Waiter​(java.lang.String description)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Waiter applyRandomDiscrepancy​(float maximumDiscrepancy)  
      Waiter duration​(long duration, java.util.concurrent.TimeUnit timeUnit)  
      Waiter ignore​(java.lang.Class<? extends java.lang.Throwable> exception)  
      Waiter pollingEvery​(long duration, java.util.concurrent.TimeUnit timeUnit)  
      <T> T till​(java.util.concurrent.Callable<T> waitFor)
      Waits until the supplied callable returns a non-null result, polling at the configured interval, or until the wait times out or the thread is interrupted.
      Waiter timeoutFail()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Waiter

        public Waiter​(java.lang.String description)
    • Method Detail

      • duration

        public Waiter duration​(long duration,
                               java.util.concurrent.TimeUnit timeUnit)
      • pollingEvery

        public Waiter pollingEvery​(long duration,
                                   java.util.concurrent.TimeUnit timeUnit)
      • ignore

        public Waiter ignore​(java.lang.Class<? extends java.lang.Throwable> exception)
      • applyRandomDiscrepancy

        public Waiter applyRandomDiscrepancy​(float maximumDiscrepancy)
      • timeoutFail

        public Waiter timeoutFail()
      • till

        public <T> T till​(java.util.concurrent.Callable<T> waitFor)
        Waits until the supplied callable returns a non-null result, polling at the configured interval, or until the wait times out or the thread is interrupted.

        Important: false is still a non-null value for Boolean and will stop waiting as a successful result.

        Exceptions matching those configured via ignore(Class) are swallowed and the wait is retried; any other exception aborts the wait and is wrapped into InternalReportPortalClientException.

        If the timeout elapses:

        If the thread is interrupted, a warning is logged and null is returned.
        Type Parameters:
        T - type of the result supplied by the callable
        Parameters:
        waitFor - a callable that is evaluated repeatedly until it returns a non-null result
        Returns:
        the first non-null result returned by the callable; null on timeout/interruption when not configured to fail
        Throws:
        InternalReportPortalClientException - if an unexpected exception occurs in the callable or if timeout occurs and timeoutFail() was configured