Class Waiter<T>


  • public final class Waiter<T>
    extends Object
    This retries a particular function multiple times until it returns an expected result (or fails with an exception). Certain expected exception types can be ignored.
    • Method Detail

      • run

        public static <T> Waiter<T> run​(Supplier<T> thingToTry)
        Create a waiter that attempts executing the provided function until the condition set with until(Predicate) is met or until it throws an exception. Expected exception types can be ignored with ignoringException(Class[]).
      • until

        public Waiter<T> until​(Predicate<T> whenToStop)
        Define the condition on the response under which the thing we are trying is complete. If this isn't set, it will always be true. ie. if the function call succeeds, we stop waiting.
      • failOn

        public Waiter<T> failOn​(Predicate<T> whenToFail)
        Define the condition on the response under which the thing we are trying has already failed and further attempts are pointless. If this isn't set, it will always be false.
      • untilException

        @SafeVarargs
        public final Waiter<T> untilException​(Class<? extends Throwable>... whenToStopOnException)
        Define the condition on an exception thrown under which the thing we are trying is complete. If this isn't set, it will always be false. ie. never stop on any particular exception.
      • ignoringException

        @SafeVarargs
        public final Waiter<T> ignoringException​(Class<? extends Throwable>... whatToIgnore)
        Define the exception types that should be ignored if the thing we are trying throws them.
      • orReturnFalse

        public boolean orReturnFalse()
        Execute the function, returning true if the thing we're trying does not succeed after 30 seconds.
      • orFail

        public T orFail()
        Execute the function, throwing an assertion error if the thing we're trying does not succeed after 30 seconds.
      • orFailAfter

        public T orFailAfter​(Duration howLongToTry)
        Execute the function, throwing an assertion error if the thing we're trying does not succeed after the provided duration.