Class ConditionFactory


  • public class ConditionFactory
    extends java.lang.Object
    A factory for creating Condition objects. It's not recommended instantiating this class directly.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ConditionFactory alias​(java.lang.String alias)
      Set the alias
      ConditionFactory and()
      A method to increase the readability of the Awaitility DSL.
      ConditionFactory atLeast​(long timeout, java.util.concurrent.TimeUnit unit)
      Condition has to be evaluated not earlier than timeout before throwing a timeout exception.
      ConditionFactory atLeast​(java.time.Duration timeout)
      Condition has to be evaluated not earlier than timeout before throwing a timeout exception.
      ConditionFactory atMost​(long timeout, java.util.concurrent.TimeUnit unit)
      Await at most timeout before throwing a timeout exception.
      ConditionFactory atMost​(java.time.Duration timeout)
      Await at most timeout before throwing a timeout exception.
      ConditionFactory await()
      Await for an asynchronous operation.
      ConditionFactory await​(java.lang.String alias)
      Await for an asynchronous operation and give this await instance a particular name.
      ConditionFactory between​(long atLeastDuration, java.util.concurrent.TimeUnit atLeastTimeUnit, long atMostDuration, java.util.concurrent.TimeUnit atMostTimeUnit)
      Specifies the duration window which has to be satisfied during operation execution.
      ConditionFactory between​(java.time.Duration atLeast, java.time.Duration atMost)
      Specifies the duration window which has to be satisfied during operation execution.
      ConditionFactory catchUncaughtExceptions()
      Instruct Awaitility to catch uncaught exceptions from other threads.
      ConditionFactory conditionEvaluationListener​(ConditionEvaluationListener conditionEvaluationListener)
      Handle condition evaluation results each time evaluation of a condition occurs.
      private java.time.Duration definePollDelay​(java.time.Duration pollDelay, PollInterval pollInterval)
      Ensures backward compatibility (especially that poll delay is the same as poll interval for fixed poll interval).
      ConditionFactory dontCatchUncaughtExceptions()
      Don't catch uncaught exceptions in other threads.
      ConditionFactory during​(long timeout, java.util.concurrent.TimeUnit unit)
      Await at the predicate holds during at least timeout
      ConditionFactory during​(java.time.Duration timeout)
      Await at the predicate holds during at least timeout
      ConditionFactory failFast​(java.lang.String failFastFailureReason, java.util.concurrent.Callable<java.lang.Boolean> failFastCondition)
      If the supplied Callable ever returns false, it indicates our condition will never be true, and if so fail the system immediately.
      ConditionFactory failFast​(java.lang.String failFastFailureReason, ThrowingRunnable failFastAssertion)
      If the supplied failFastAssertion ever returns throws an exception, it indicates our condition will never be true, and if so fail the system immediately.
      ConditionFactory failFast​(java.util.concurrent.Callable<java.lang.Boolean> failFastCondition)
      If the supplied Callable ever returns false, it indicates our condition will never be true, and if so fail the system immediately.
      ConditionFactory failFast​(ThrowingRunnable failFastAssertion)
      If the supplied failFastAssertion ever returns throws an exception, it indicates our condition will never be true, and if so fail the system immediately.
      ConditionFactory forever()
      Await forever until the condition is satisfied.
      private ConditionSettings generateConditionSettings()  
      ConditionFactory given()
      A method to increase the readability of the Awaitility DSL.
      ConditionFactory ignoreException​(java.lang.Class<? extends java.lang.Throwable> exceptionType)
      Instruct Awaitility to ignore a specific exception and no subclasses of this exception.
      ConditionFactory ignoreExceptions()
      Instruct Awaitility to ignore all exceptions that occur during evaluation.
      ConditionFactory ignoreExceptionsInstanceOf​(java.lang.Class<? extends java.lang.Throwable> exceptionType)
      Instruct Awaitility to ignore exceptions instance of the supplied exceptionType type.
      ConditionFactory ignoreExceptionsMatching​(java.util.function.Predicate<? super java.lang.Throwable> predicate)
      Instruct Awaitility to ignore exceptions that occur during evaluation and matches the supplied predicate.
      ConditionFactory ignoreExceptionsMatching​(org.hamcrest.Matcher<? super java.lang.Throwable> matcher)
      Instruct Awaitility to ignore exceptions that occur during evaluation and matches the supplied Hamcrest matcher.
      ConditionFactory ignoreNoExceptions()
      Instruct Awaitility to not ignore any exceptions that occur during evaluation.
      ConditionFactory logging()
      Logging condition evaluation results each time evaluation of a condition occurs to System.out.
      ConditionFactory logging​(java.util.function.Consumer<java.lang.String> logPrinter)
      Logging condition evaluation results each time evaluation of a condition occurs to chosen consumer.
      ConditionFactory pollDelay​(long delay, java.util.concurrent.TimeUnit unit)
      Specify the delay that will be used before Awaitility starts polling for the result the first time.
      ConditionFactory pollDelay​(java.time.Duration pollDelay)
      Specify the delay that will be used before Awaitility starts polling for the result the first time.
      ConditionFactory pollExecutorService​(java.util.concurrent.ExecutorService executorService)
      Specify the executor service whose threads will be used to evaluate the poll condition in Awaitility.
      ConditionFactory pollInSameThread()
      Instructs Awaitility to execute the polling of the condition from the same as the test.
      ConditionFactory pollInterval​(long pollInterval, java.util.concurrent.TimeUnit unit)
      Specify the polling interval Awaitility will use for this await statement.
      ConditionFactory pollInterval​(java.time.Duration pollInterval)
      Specify the polling interval Awaitility will use for this await statement.
      ConditionFactory pollInterval​(PollInterval pollInterval)  
      ConditionFactory pollThread​(java.util.function.Function<java.lang.Runnable,​java.lang.Thread> threadSupplier)
      Specify a thread supplier whose thread will be used to evaluate the poll condition in Awaitility.
      ConditionFactory then()
      A method to increase the readability of the Awaitility DSL.
      ConditionFactory timeout​(long timeout, java.util.concurrent.TimeUnit unit)
      Await at most timeout before throwing a timeout exception.
      ConditionFactory timeout​(java.time.Duration timeout)
      Await at most timeout before throwing a timeout exception.
      void until​(java.util.concurrent.Callable<java.lang.Boolean> conditionEvaluator)
      Await until a Callable returns true.
      <T> T until​(java.util.concurrent.Callable<T> supplier, java.util.function.Predicate<? super T> predicate)
      Wait until the given supplier matches the supplied predicate.
      <T> T until​(java.util.concurrent.Callable<T> supplier, org.hamcrest.Matcher<? super T> matcher)
      Await until a Callable supplies a value matching the specified Matcher.
      private <T> T until​(Condition<T> condition)  
      void untilAccumulator​(java.util.concurrent.atomic.DoubleAccumulator accumulator, java.util.function.Consumer<? super java.lang.Double> matcher)
      Await until a DoubleAccumulator is asserted by the matcher consumer E.g.
      void untilAccumulator​(java.util.concurrent.atomic.DoubleAccumulator accumulator, org.hamcrest.Matcher<? super java.lang.Double> matcher)
      Await until a DoubleAccumulator has a value matching the specified Matcher.
      void untilAccumulator​(java.util.concurrent.atomic.LongAccumulator accumulator, java.util.function.Consumer<? super java.lang.Long> matcher)
      Await until a LongAccumulator is asserted by the matcher consumer E.g.
      void untilAccumulator​(java.util.concurrent.atomic.LongAccumulator accumulator, org.hamcrest.Matcher<? super java.lang.Long> matcher)
      Await until a LongAccumulator has a value matching the specified Matcher.
      void untilAdder​(java.util.concurrent.atomic.DoubleAdder adder, java.util.function.Consumer<? super java.lang.Double> matcher)
      Await until a DoubleAdder is asserted by the matcher consumer E.g.
      void untilAdder​(java.util.concurrent.atomic.DoubleAdder adder, org.hamcrest.Matcher<? super java.lang.Double> matcher)
      Await until a DoubleAdder has a value matching the specified Matcher.
      void untilAdder​(java.util.concurrent.atomic.LongAdder adder, java.util.function.Consumer<? super java.lang.Long> matcher)
      Await until a LongAdder is asserted by the matcher consumer E.g.
      void untilAdder​(java.util.concurrent.atomic.LongAdder adder, org.hamcrest.Matcher<? super java.lang.Long> matcher)
      Await until a LongAdder has a value matching the specified Matcher.
      <T> void untilAsserted​(java.util.concurrent.Callable<T> supplier, java.util.function.Consumer<? super T> assertConsumer)
      Await until a callable returns a value that when passed to a Consumer ends without throwing an exception.
      void untilAsserted​(ThrowingRunnable assertion)
      Await until a Runnable supplier execution passes (ends without throwing an exception).
      void untilAtomic​(java.util.concurrent.atomic.AtomicBoolean atomic, java.util.function.Consumer<? super java.lang.Boolean> matcher)
      Await until a AtomicBoolean is asserted by the matcher consumer E.g.
      void untilAtomic​(java.util.concurrent.atomic.AtomicBoolean atomic, org.hamcrest.Matcher<? super java.lang.Boolean> matcher)
      Await until a Atomic variable has a value matching the specified Matcher.
      void untilAtomic​(java.util.concurrent.atomic.AtomicInteger atomic, java.util.function.Consumer<? super java.lang.Integer> matcher)
      Await until a Atomic integer is asserted by the matcher consumer E.g.
      java.lang.Integer untilAtomic​(java.util.concurrent.atomic.AtomicInteger atomic, org.hamcrest.Matcher<? super java.lang.Integer> matcher)
      Await until a Atomic variable has a value matching the specified Matcher.
      void untilAtomic​(java.util.concurrent.atomic.AtomicLong atomic, java.util.function.Consumer<? super java.lang.Long> matcher)
      Await until a Atomic long is asserted by the matcher consumer E.g.
      java.lang.Long untilAtomic​(java.util.concurrent.atomic.AtomicLong atomic, org.hamcrest.Matcher<? super java.lang.Long> matcher)
      Await until a Atomic variable has a value matching the specified Matcher.
      <V> void untilAtomic​(java.util.concurrent.atomic.AtomicReference<V> atomic, java.util.function.Consumer<? super V> matcher)
      Await until a Atomic variable is asserted by the matcher consumer E.g.
      <V> V untilAtomic​(java.util.concurrent.atomic.AtomicReference<V> atomic, org.hamcrest.Matcher<? super V> matcher)
      Await until a Atomic variable has a value matching the specified Matcher.
      void untilFalse​(java.util.concurrent.atomic.AtomicBoolean atomic)
      Await until a Atomic boolean becomes false.
      void untilTrue​(java.util.concurrent.atomic.AtomicBoolean atomic)
      Await until a Atomic boolean becomes true.
      ConditionFactory with()
      A method to increase the readability of the Awaitility DSL.
      • Methods inherited from class java.lang.Object

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

      • timeoutConstraint

        private final WaitConstraint timeoutConstraint
        Timing constraint.
      • pollInterval

        private final PollInterval pollInterval
        The poll interval.
      • catchUncaughtExceptions

        private final boolean catchUncaughtExceptions
        The catch uncaught exceptions.
      • exceptionsIgnorer

        private final ExceptionIgnorer exceptionsIgnorer
        The ignore exceptions.
      • alias

        private final java.lang.String alias
        The alias.
      • pollDelay

        private final java.time.Duration pollDelay
        The poll delay.
      • executorLifecycle

        private final ExecutorLifecycle executorLifecycle
        The executor lifecycle
      • failFastCondition

        private final FailFastCondition failFastCondition
        If this condition if ever false, indicates our condition will never be true.
    • Constructor Detail

      • ConditionFactory

        public ConditionFactory​(java.lang.String alias,
                                WaitConstraint timeoutConstraint,
                                PollInterval pollInterval,
                                java.time.Duration pollDelay,
                                boolean catchUncaughtExceptions,
                                ExceptionIgnorer exceptionsIgnorer,
                                ConditionEvaluationListener conditionEvaluationListener,
                                ExecutorLifecycle executorLifecycle,
                                FailFastCondition failFastCondition)
        Instantiates a new condition factory.
        Parameters:
        alias - the alias
        timeoutConstraint - the timeout constraint
        pollInterval - the poll interval
        pollDelay - The poll delay
        catchUncaughtExceptions - the catch uncaught exceptions
        exceptionsIgnorer - Determine which exceptions that should ignored
        conditionEvaluationListener - Determine which exceptions that should ignored
        executorLifecycle - The executor service and the lifecycle of the executor service that'll be used to evaluate the condition during polling
        failFastCondition - If this condition if ever false, indicates our condition will never be true.
    • Method Detail

      • conditionEvaluationListener

        public ConditionFactory conditionEvaluationListener​(ConditionEvaluationListener conditionEvaluationListener)
        Handle condition evaluation results each time evaluation of a condition occurs. Works only with a Hamcrest matcher-based condition.
        Parameters:
        conditionEvaluationListener - the condition evaluation listener
        Returns:
        the condition factory
      • logging

        public ConditionFactory logging()
        Logging condition evaluation results each time evaluation of a condition occurs to System.out.
        Returns:
        the condition factory
      • logging

        public ConditionFactory logging​(java.util.function.Consumer<java.lang.String> logPrinter)
        Logging condition evaluation results each time evaluation of a condition occurs to chosen consumer.
        Returns:
        the condition factory
      • timeout

        public ConditionFactory timeout​(java.time.Duration timeout)
        Await at most timeout before throwing a timeout exception.
        Parameters:
        timeout - the timeout
        Returns:
        the condition factory
      • atMost

        public ConditionFactory atMost​(java.time.Duration timeout)
        Await at most timeout before throwing a timeout exception.
        Parameters:
        timeout - the timeout
        Returns:
        the condition factory
      • during

        public ConditionFactory during​(java.time.Duration timeout)
        Await at the predicate holds during at least timeout
        Parameters:
        timeout - the timeout
        Returns:
        the condition factory
      • during

        public ConditionFactory during​(long timeout,
                                       java.util.concurrent.TimeUnit unit)
        Await at the predicate holds during at least timeout
        Parameters:
        timeout - the timeout
        unit - the unit
        Returns:
        the condition factory
      • atLeast

        public ConditionFactory atLeast​(java.time.Duration timeout)
        Condition has to be evaluated not earlier than timeout before throwing a timeout exception.
        Parameters:
        timeout - the timeout
        Returns:
        the condition factory
      • atLeast

        public ConditionFactory atLeast​(long timeout,
                                        java.util.concurrent.TimeUnit unit)
        Condition has to be evaluated not earlier than timeout before throwing a timeout exception.
        Parameters:
        timeout - the timeout
        unit - the unit
        Returns:
        the condition factory
      • between

        public ConditionFactory between​(java.time.Duration atLeast,
                                        java.time.Duration atMost)
        Specifies the duration window which has to be satisfied during operation execution. In case operation is executed before atLeast or after atMost timeout exception is thrown.
        Parameters:
        atLeast - lower part of execution window
        atMost - upper part of execution window
        Returns:
        the condition factory
      • between

        public ConditionFactory between​(long atLeastDuration,
                                        java.util.concurrent.TimeUnit atLeastTimeUnit,
                                        long atMostDuration,
                                        java.util.concurrent.TimeUnit atMostTimeUnit)
        Specifies the duration window which has to be satisfied during operation execution. In case operation is executed before atLeastDuration or after atMostDuration timeout exception is thrown.
        Parameters:
        atLeastDuration - lower part of execution window
        atMostDuration - upper part of execution window
        Returns:
        the condition factory
      • forever

        public ConditionFactory forever()
        Await forever until the condition is satisfied. Caution: You can block subsequent tests and the entire build can hang indefinitely, it's recommended to always use a timeout.
        Returns:
        the condition factory
      • pollInterval

        public ConditionFactory pollInterval​(java.time.Duration pollInterval)
        Specify the polling interval Awaitility will use for this await statement. This means the frequency in which the condition is checked for completion.

        Note that the poll delay will be automatically set as to the same value as the interval (if using a FixedPollInterval) unless it's specified explicitly using pollDelay(Duration), pollDelay(long, TimeUnit) or pollDelay(java.time.Duration).

        Parameters:
        pollInterval - the poll interval
        Returns:
        the condition factory
      • timeout

        public ConditionFactory timeout​(long timeout,
                                        java.util.concurrent.TimeUnit unit)
        Await at most timeout before throwing a timeout exception.
        Parameters:
        timeout - the timeout
        unit - the unit
        Returns:
        the condition factory
      • pollDelay

        public ConditionFactory pollDelay​(long delay,
                                          java.util.concurrent.TimeUnit unit)
        Specify the delay that will be used before Awaitility starts polling for the result the first time. If you don't specify a poll delay explicitly it'll be the same as the poll interval.
        Parameters:
        delay - the delay
        unit - the unit
        Returns:
        the condition factory
      • pollDelay

        public ConditionFactory pollDelay​(java.time.Duration pollDelay)
        Specify the delay that will be used before Awaitility starts polling for the result the first time. If you don't specify a poll delay explicitly it'll be the same as the poll interval.
        Parameters:
        pollDelay - the poll delay
        Returns:
        the condition factory
      • atMost

        public ConditionFactory atMost​(long timeout,
                                       java.util.concurrent.TimeUnit unit)
        Await at most timeout before throwing a timeout exception.
        Parameters:
        timeout - the timeout
        unit - the unit
        Returns:
        the condition factory
      • pollInterval

        public ConditionFactory pollInterval​(long pollInterval,
                                             java.util.concurrent.TimeUnit unit)
        Specify the polling interval Awaitility will use for this await statement. This means the frequency in which the condition is checked for completion.

         

        Note that the poll delay will be automatically set as to the same value as the interval unless it's specified explicitly using pollDelay(Duration), pollDelay(long, TimeUnit) or pollDelay(java.time.Duration) , or ConditionFactory#andWithPollDelay(long, TimeUnit)}. This is the same as creating a FixedPollInterval.
        Parameters:
        pollInterval - the poll interval
        unit - the unit
        Returns:
        the condition factory
        See Also:
        FixedPollInterval
      • catchUncaughtExceptions

        public ConditionFactory catchUncaughtExceptions()
        Instruct Awaitility to catch uncaught exceptions from other threads. This is useful in multi-threaded systems when you want your test to fail regardless of which thread throwing the exception. Default is true.
        Returns:
        the condition factory
      • ignoreExceptionsInstanceOf

        public ConditionFactory ignoreExceptionsInstanceOf​(java.lang.Class<? extends java.lang.Throwable> exceptionType)
        Instruct Awaitility to ignore exceptions instance of the supplied exceptionType type. Exceptions will be treated as evaluating to false. This is useful in situations where the evaluated conditions may temporarily throw exceptions.

        If you want to ignore a specific exceptionType then use ignoreException(Class)

        Parameters:
        exceptionType - The exception type (hierarchy) to ignore
        Returns:
        the condition factory
      • ignoreException

        public ConditionFactory ignoreException​(java.lang.Class<? extends java.lang.Throwable> exceptionType)
        Instruct Awaitility to ignore a specific exception and no subclasses of this exception. Exceptions will be treated as evaluating to false. This is useful in situations where the evaluated conditions may temporarily throw exceptions.

        If you want to ignore a subtypes of this exception then use ignoreExceptionsInstanceOf(Class)}

        Parameters:
        exceptionType - The exception type to ignore
        Returns:
        the condition factory
      • ignoreExceptions

        public ConditionFactory ignoreExceptions()
        Instruct Awaitility to ignore all exceptions that occur during evaluation. Exceptions will be treated as evaluating to false. This is useful in situations where the evaluated conditions may temporarily throw exceptions.
        Returns:
        the condition factory.
      • ignoreNoExceptions

        public ConditionFactory ignoreNoExceptions()
        Instruct Awaitility to not ignore any exceptions that occur during evaluation. This is only useful if Awaitility is configured to ignore exceptions by default but you want to have a different behavior for a single test case.
        Returns:
        the condition factory.
      • ignoreExceptionsMatching

        public ConditionFactory ignoreExceptionsMatching​(org.hamcrest.Matcher<? super java.lang.Throwable> matcher)
        Instruct Awaitility to ignore exceptions that occur during evaluation and matches the supplied Hamcrest matcher. Exceptions will be treated as evaluating to false. This is useful in situations where the evaluated conditions may temporarily throw exceptions.
        Returns:
        the condition factory.
      • ignoreExceptionsMatching

        public ConditionFactory ignoreExceptionsMatching​(java.util.function.Predicate<? super java.lang.Throwable> predicate)
        Instruct Awaitility to ignore exceptions that occur during evaluation and matches the supplied predicate. Exceptions will be treated as evaluating to false. This is useful in situations where the evaluated conditions may temporarily throw exceptions.
        Returns:
        the condition factory.
      • await

        public ConditionFactory await()
        Await for an asynchronous operation. This method returns the same ConditionFactory instance and is used only to get a more fluent-like syntax.
        Returns:
        the condition factory
      • await

        public ConditionFactory await​(java.lang.String alias)
        Await for an asynchronous operation and give this await instance a particular name. This is useful in cases when you have several await statements in one test and you want to know which one that fails (the alias will be shown if a timeout exception occurs).
        Parameters:
        alias - the alias
        Returns:
        the condition factory
      • and

        public ConditionFactory and()
        A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.
        Returns:
        the condition factory
      • with

        public ConditionFactory with()
        A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.
        Returns:
        the condition factory
      • then

        public ConditionFactory then()
        A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.
        Returns:
        the condition factory
      • given

        public ConditionFactory given()
        A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.
        Returns:
        the condition factory
      • dontCatchUncaughtExceptions

        public ConditionFactory dontCatchUncaughtExceptions()
        Don't catch uncaught exceptions in other threads. This will not make the await statement fail if exceptions occur in other threads.
        Returns:
        the condition factory
      • pollExecutorService

        public ConditionFactory pollExecutorService​(java.util.concurrent.ExecutorService executorService)
        Specify the executor service whose threads will be used to evaluate the poll condition in Awaitility. Note that the executor service must be shutdown manually!

        This is an advanced feature and it should only be used sparingly.

        Parameters:
        executorService - The executor service that Awaitility will use when polling condition evaluations
        Returns:
        the condition factory
      • pollThread

        public ConditionFactory pollThread​(java.util.function.Function<java.lang.Runnable,​java.lang.Thread> threadSupplier)
        Specify a thread supplier whose thread will be used to evaluate the poll condition in Awaitility. The supplier will be called only once and the thread it returns will be reused during all condition evaluations. This is an advanced feature and it should only be used sparingly.
        Parameters:
        threadSupplier - A supplier of the thread that Awaitility will use when polling
        Returns:
        the condition factory
      • pollInSameThread

        public ConditionFactory pollInSameThread()
        Instructs Awaitility to execute the polling of the condition from the same as the test. This is an advanced feature and you should be careful when combining this with conditions that wait forever (or a long time) since Awaitility cannot interrupt the thread when it's using the same thread as the test. For safety you should always combine tests using this feature with a test framework specific timeout, for example in JUnit:
        Returns:
        the condition factory
      • failFast

        public ConditionFactory failFast​(java.util.concurrent.Callable<java.lang.Boolean> failFastCondition)
        If the supplied Callable ever returns false, it indicates our condition will never be true, and if so fail the system immediately. Throws a TerminalFailureException if fail fast condition evaluates to true. If you want to specify a more descriptive error message then use failFast(String, Callable).
        Parameters:
        failFastCondition - The terminal failure condition
        Returns:
        the condition factory
        See Also:
        failFast(String, Callable)
      • failFast

        public ConditionFactory failFast​(java.lang.String failFastFailureReason,
                                         java.util.concurrent.Callable<java.lang.Boolean> failFastCondition)
        If the supplied Callable ever returns false, it indicates our condition will never be true, and if so fail the system immediately. Throws a TerminalFailureException if fail fast condition evaluates to true.
        Parameters:
        failFastFailureReason - A descriptive reason why the fail fast condition has failed, will be included in the TerminalFailureException thrown if failFastCondition evaluates to true.
        failFastCondition - The terminal failure condition
        Returns:
        the condition factory
      • failFast

        public ConditionFactory failFast​(ThrowingRunnable failFastAssertion)
        If the supplied failFastAssertion ever returns throws an exception, it indicates our condition will never be true, and if so fail the system immediately. This allows you to use a more descriptive error message of why the fail-fast condition failed by doing e.g.:
         Workflow workflow = ..
         await()
             .atMost(1, MINUTES)
             .failFast(() ->  assertThat(workflow.get("phase")).describedAs("Workflow failed. Last known state:\n" + workflow.toPrettyString()).isNotEqualTo("Failed");
             .untilAsserted(...);
         
        Parameters:
        failFastAssertion - The terminal failure assertion
        Returns:
        the condition factory
        See Also:
        failFast(String, Callable)
      • failFast

        public ConditionFactory failFast​(java.lang.String failFastFailureReason,
                                         ThrowingRunnable failFastAssertion)
        If the supplied failFastAssertion ever returns throws an exception, it indicates our condition will never be true, and if so fail the system immediately. This allows you to use a more descriptive error message of why the fail-fast condition failed by doing e.g.:
         Workflow workflow = ..
         await()
             .atMost(1, MINUTES)
             .failFast("workflow failed", () ->  assertThat(workflow.get("phase")).describedAs("Workflow failed. Last known state:\n" + workflow.toPrettyString()).isNotEqualTo("Failed");
             .untilAsserted(...);
         
        Parameters:
        failFastFailureReason - A descriptive reason why the fail fast condition has failed, will be included in the TerminalFailureException thrown if failFastAssertion throws an exception.
        failFastAssertion - The terminal failure assertion
        Returns:
        the condition factory
        See Also:
        failFast(String, Callable)
      • until

        public <T> T until​(java.util.concurrent.Callable<T> supplier,
                           org.hamcrest.Matcher<? super T> matcher)
        Await until a Callable supplies a value matching the specified Matcher. E.g.

         

         await().until(numberOfPersons(), is(greaterThan(2)));
         

         

        where "numberOfPersons()" returns a standard Callable:

         

         private Callable<Integer> numberOfPersons() {
                return new Callable<Integer>() {
                        public Integer call() {
                                return personRepository.size();
                }
            };
         }
         

         

        Using a generic Callable as done by using this version of "until" allows you to reuse the "numberOfPersons()" definition in multiple await statements. I.e. you can easily create another await statement (perhaps in a different test case) using e.g.

         

         await().until(numberOfPersons(), is(equalTo(6)));
         
        Type Parameters:
        T - the generic type
        Parameters:
        supplier - the supplier that is responsible for getting the value that should be matched.
        matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
        Returns:
        a T object.
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • until

        public <T> T until​(java.util.concurrent.Callable<T> supplier,
                           java.util.function.Predicate<? super T> predicate)
        Wait until the given supplier matches the supplied predicate. For example:
         await().until(myRepository::count, cnt -> cnt == 2);
         
        Type Parameters:
        T - the generic type
        Parameters:
        supplier - The supplier that returns the object that will be evaluated by the predicate.
        predicate - The predicate that must match
        Returns:
        a T object.
        Since:
        3.1.1
      • untilAsserted

        public void untilAsserted​(ThrowingRunnable assertion)
        Await until a Runnable supplier execution passes (ends without throwing an exception). E.g. with Java 8:

         

         await().untilAsserted(() -> Assertions.assertThat(personRepository.size()).isEqualTo(6));
         
        or
         await().untilAsserted(() -> assertEquals(6, personRepository.size()));
         

         

        This method is intended to benefit from lambda expressions introduced in Java 8. It allows to use standard AssertJ/FEST Assert assertions (by the way also standard JUnit/TestNG assertions) to test asynchronous calls and systems.

         

        AssertionError instances thrown by the supplier are treated as an assertion failure and proper error message is propagated on timeout. Other exceptions are rethrown immediately as an execution errors.

         

        While technically it is completely valid to use plain Runnable class in Java 7 code, the resulting expression is very verbose and can decrease the readability of the test case, e.g.

         

         await().untilAsserted(new Runnable() {
             public void run() {
                 Assertions.assertThat(personRepository.size()).isEqualTo(6);
             }
         });
         

         

        NOTE:
        Be VERY careful so that you're not using this method incorrectly in languages (like Kotlin and Groovy) that doesn't disambiguate between a ThrowingRunnable that doesn't return anything (void) and Callable that returns a value. For example in Kotlin you can do like this:

         

         await().untilAsserted { true == false }
         
        and the compiler won't complain with an error (as is the case in Java). If you were to execute this test in Kotlin it'll pass!
        Parameters:
        assertion - the supplier that is responsible for executing the assertion and throwing AssertionError on failure.
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
        Since:
        1.6.0
      • untilAsserted

        public <T> void untilAsserted​(java.util.concurrent.Callable<T> supplier,
                                      java.util.function.Consumer<? super T> assertConsumer)
        Await until a callable returns a value that when passed to a Consumer ends without throwing an exception. E.g. with Java 8:

         

         public class MyBean {
        
             public String myFunction() {
                  // Imagine stuff being executed in asynchrinously here and the result of this
                  // operation is a string called "my value"
                 return "my value"
             }
         }
        
         // Then in your test you can wait for the "myFunction" to return "my value"
         await().untilAsserted(myBean::myFunction, value ->  Assertions.assertThat(value).isEqualTo("my value"));
         
        Parameters:
        supplier - the supplier that is responsible for executing the assertion and throwing AssertionError on failure.
        assertConsumer - The consumer that will assert that the supplied value is correct, or throw an exception.
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
        Since:
        4.3.2
      • untilAtomic

        public java.lang.Integer untilAtomic​(java.util.concurrent.atomic.AtomicInteger atomic,
                                             org.hamcrest.Matcher<? super java.lang.Integer> matcher)
        Await until a Atomic variable has a value matching the specified Matcher. E.g.

         

         await().untilAtomic(myAtomic, is(greaterThan(2)));
         
        Parameters:
        atomic - the atomic variable
        matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
        Returns:
        a Integer object.
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilAtomic

        public void untilAtomic​(java.util.concurrent.atomic.AtomicInteger atomic,
                                java.util.function.Consumer<? super java.lang.Integer> matcher)
        Await until a Atomic integer is asserted by the matcher consumer E.g.

         

         await().untilAtomic(myAtomic, value -> Assertions.assertThat(value).isEqualTo(123));
         
        Parameters:
        atomic - the atomic variable
        matcher - the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilAtomic

        public java.lang.Long untilAtomic​(java.util.concurrent.atomic.AtomicLong atomic,
                                          org.hamcrest.Matcher<? super java.lang.Long> matcher)
        Await until a Atomic variable has a value matching the specified Matcher. E.g.

         

         await().untilAtomic(myAtomic, is(greaterThan(2)));
         
        Parameters:
        atomic - the atomic variable
        matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
        Returns:
        a Long object.
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilAtomic

        public void untilAtomic​(java.util.concurrent.atomic.AtomicLong atomic,
                                java.util.function.Consumer<? super java.lang.Long> matcher)
        Await until a Atomic long is asserted by the matcher consumer E.g.

         

         await().untilAtomic(myAtomic, value -> Assertions.assertThat(value).isEqualTo(123L));
         
        Parameters:
        atomic - the atomic variable
        matcher - the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilAtomic

        public void untilAtomic​(java.util.concurrent.atomic.AtomicBoolean atomic,
                                org.hamcrest.Matcher<? super java.lang.Boolean> matcher)
        Await until a Atomic variable has a value matching the specified Matcher. E.g.

         

         await().untilAtomic(myAtomic, is(greaterThan(2)));
         
        Parameters:
        atomic - the atomic variable
        matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilAtomic

        public void untilAtomic​(java.util.concurrent.atomic.AtomicBoolean atomic,
                                java.util.function.Consumer<? super java.lang.Boolean> matcher)
        Await until a AtomicBoolean is asserted by the matcher consumer E.g.

         

         await().untilAtomic(myAtomicBoolean, value -> Assertions.assertThat(value).isTrue());
         
        Parameters:
        atomic - the atomic variable
        matcher - the matcher The consumer that validates that the atomic boolean value is correct, or throws an exception
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilTrue

        public void untilTrue​(java.util.concurrent.atomic.AtomicBoolean atomic)
        Await until a Atomic boolean becomes true.
        Parameters:
        atomic - the atomic variable
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilFalse

        public void untilFalse​(java.util.concurrent.atomic.AtomicBoolean atomic)
        Await until a Atomic boolean becomes false.
        Parameters:
        atomic - the atomic variable
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilAdder

        public void untilAdder​(java.util.concurrent.atomic.LongAdder adder,
                               org.hamcrest.Matcher<? super java.lang.Long> matcher)
        Await until a LongAdder has a value matching the specified Matcher. E.g.

         

         await().untilAdder(myLongAdder, is(greaterThan(2L)));
         
        Parameters:
        adder - the LongAdder variable
        matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilAdder

        public void untilAdder​(java.util.concurrent.atomic.LongAdder adder,
                               java.util.function.Consumer<? super java.lang.Long> matcher)
        Await until a LongAdder is asserted by the matcher consumer E.g.

         

         await().untilAdder(myAdder, value -> Assertions.assertThat(value).isEqualTo(123L));
         
        Parameters:
        adder - the atomic variable
        matcher - the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilAdder

        public void untilAdder​(java.util.concurrent.atomic.DoubleAdder adder,
                               org.hamcrest.Matcher<? super java.lang.Double> matcher)
        Await until a DoubleAdder has a value matching the specified Matcher. E.g.

         

         await().untilAdder(myDoubleAdder, is(greaterThan(2.0d)));
         
        Parameters:
        adder - the DoubleAdder variable
        matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilAdder

        public void untilAdder​(java.util.concurrent.atomic.DoubleAdder adder,
                               java.util.function.Consumer<? super java.lang.Double> matcher)
        Await until a DoubleAdder is asserted by the matcher consumer E.g.

         

         await().untilAdder(myAdder, value -> Assertions.assertThat(value).isEqualTo(12.3d));
         
        Parameters:
        adder - the atomic variable
        matcher - the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilAccumulator

        public void untilAccumulator​(java.util.concurrent.atomic.LongAccumulator accumulator,
                                     org.hamcrest.Matcher<? super java.lang.Long> matcher)
        Await until a LongAccumulator has a value matching the specified Matcher. E.g.

         

         await().untilAccumulator(myLongAccumulator, is(greaterThan(2L)));
         
        Parameters:
        accumulator - the LongAccumulator variable
        matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilAccumulator

        public void untilAccumulator​(java.util.concurrent.atomic.LongAccumulator accumulator,
                                     java.util.function.Consumer<? super java.lang.Long> matcher)
        Await until a LongAccumulator is asserted by the matcher consumer E.g.

         

         await().untilAccumulator(myAdder, value -> Assertions.assertThat(value).isEqualTo(123L));
         
        Parameters:
        accumulator - the atomic variable
        matcher - the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilAccumulator

        public void untilAccumulator​(java.util.concurrent.atomic.DoubleAccumulator accumulator,
                                     org.hamcrest.Matcher<? super java.lang.Double> matcher)
        Await until a DoubleAccumulator has a value matching the specified Matcher. E.g.

         

         await().untilAccumulator(myDoubleAccumulator, is(greaterThan(2.0d)));
         
        Parameters:
        accumulator - the DoubleAccumulator variable
        matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilAccumulator

        public void untilAccumulator​(java.util.concurrent.atomic.DoubleAccumulator accumulator,
                                     java.util.function.Consumer<? super java.lang.Double> matcher)
        Await until a DoubleAccumulator is asserted by the matcher consumer E.g.

         

         await().untilAccumulator(myAdder, value -> Assertions.assertThat(value).isEqualTo(12.3d));
         
        Parameters:
        accumulator - the atomic variable
        matcher - the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilAtomic

        public <V> V untilAtomic​(java.util.concurrent.atomic.AtomicReference<V> atomic,
                                 org.hamcrest.Matcher<? super V> matcher)
        Await until a Atomic variable has a value matching the specified Matcher. E.g.

         

         await().untilAtomic(myAtomic, is(greaterThan(2)));
         
        Type Parameters:
        V - a V object.
        Parameters:
        atomic - the atomic variable
        matcher - the matcher The hamcrest matcher that checks whether the condition is fulfilled.
        Returns:
        a V object.
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • untilAtomic

        public <V> void untilAtomic​(java.util.concurrent.atomic.AtomicReference<V> atomic,
                                    java.util.function.Consumer<? super V> matcher)
        Await until a Atomic variable is asserted by the matcher consumer E.g.

         

         await().untilAtomic(myAtomic, value -> Assertions.assertThat(value).isEqualTo("something"));
         
        Type Parameters:
        V - a V object.
        Parameters:
        atomic - the atomic variable
        matcher - the matcher The consumer that validates that the atomic reference value is correct, or throws an exception
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • until

        public void until​(java.util.concurrent.Callable<java.lang.Boolean> conditionEvaluator)
        Await until a Callable returns true. This is method is not as generic as the other variants of "until" but it allows for a more precise and in some cases even more english-like syntax. E.g.

         

         await().until(numberOfPersonsIsEqualToThree());
         

         

        where "numberOfPersonsIsEqualToThree()" returns a standard Callable of type Boolean:

         

         private Callable<Boolean> numberOfPersons() {
                return new Callable<Boolean>() {
                        public Boolean call() {
                                return personRepository.size() == 3;
                }
            };
         }
         
        Parameters:
        conditionEvaluator - the condition evaluator
        Throws:
        ConditionTimeoutException - If condition was not fulfilled within the given time period.
      • until

        private <T> T until​(Condition<T> condition)
      • definePollDelay

        private java.time.Duration definePollDelay​(java.time.Duration pollDelay,
                                                   PollInterval pollInterval)
        Ensures backward compatibility (especially that poll delay is the same as poll interval for fixed poll interval). It also make sure that poll delay is Duration.ZERO for all other poll intervals if poll delay was not explicitly defined. If poll delay was explicitly defined the it will just be returned.
        Parameters:
        pollDelay - The poll delay
        pollInterval - The chosen (or default) poll interval
        Returns:
        The poll delay to use