Package software.amazon.awssdk.testutils
Class Waiter<T>
- java.lang.Object
-
- software.amazon.awssdk.testutils.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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.Waiter<T>ignoringException(Class<? extends Throwable>... whatToIgnore)Define the exception types that should be ignored if the thing we are trying throws them.TorFail()Execute the function, throwing an assertion error if the thing we're trying does not succeed after 30 seconds.TorFailAfter(Duration howLongToTry)Execute the function, throwing an assertion error if the thing we're trying does not succeed after the provided duration.booleanorReturnFalse()Execute the function, returning true if the thing we're trying does not succeed after 30 seconds.static <T> Waiter<T>run(Supplier<T> thingToTry)Create a waiter that attempts executing the provided function until the condition set withuntil(Predicate)is met or until it throws an exception.Waiter<T>until(Predicate<T> whenToStop)Define the condition on the response under which the thing we are trying is complete.Waiter<T>untilException(Class<? extends Throwable>... whenToStopOnException)Define the condition on an exception thrown under which the thing we are trying is complete.
-
-
-
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 withuntil(Predicate)is met or until it throws an exception. Expected exception types can be ignored withignoringException(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.
-
-