Package org.awaitility.core
Class ConditionFactory
java.lang.Object
org.awaitility.core.ConditionFactory
A factory for creating
Condition objects. It's not recommended instantiating this class directly.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringThe alias.private final booleanThe catch uncaught exceptions.private final ConditionEvaluationListenerThe condition evaluation listenerprivate final ExceptionIgnorerThe ignore exceptions.private final ExecutorLifecycleThe executor lifecycleprivate final FailFastConditionIf this condition if ever false, indicates our condition will never be true.private final DurationThe poll delay.private final PollIntervalThe poll interval.private final WaitConstraintTiming constraint. -
Constructor Summary
ConstructorsConstructorDescriptionConditionFactory(String alias, WaitConstraint timeoutConstraint, PollInterval pollInterval, Duration pollDelay, boolean catchUncaughtExceptions, ExceptionIgnorer exceptionsIgnorer, ConditionEvaluationListener conditionEvaluationListener, ExecutorLifecycle executorLifecycle, FailFastCondition failFastCondition) Instantiates a new condition factory. -
Method Summary
Modifier and TypeMethodDescriptionSet the aliasand()A method to increase the readability of the Awaitility DSL.Condition has to be evaluated not earlier thantimeoutbefore throwing a timeout exception.Condition has to be evaluated not earlier thantimeoutbefore throwing a timeout exception.Await at mosttimeoutbefore throwing a timeout exception.Await at mosttimeoutbefore throwing a timeout exception.await()Await for an asynchronous operation.Await for an asynchronous operation and give this await instance a particular name.between(long atLeastDuration, TimeUnit atLeastTimeUnit, long atMostDuration, TimeUnit atMostTimeUnit) Specifies the duration window which has to be satisfied during operation execution.Specifies the duration window which has to be satisfied during operation execution.Instruct Awaitility to catch uncaught exceptions from other threads.conditionEvaluationListener(ConditionEvaluationListener conditionEvaluationListener) Handle condition evaluation results each time evaluation of a condition occurs.private DurationdefinePollDelay(Duration pollDelay, PollInterval pollInterval) Ensures backward compatibility (especially that poll delay is the same as poll interval for fixed poll interval).Don't catch uncaught exceptions in other threads.Await at the predicate holds during at leasttimeoutAwait at the predicate holds during at leasttimeoutIf the supplied Callable ever returns false, it indicates our condition will never be true, and if so fail the system immediately.failFast(String failFastFailureReason, ThrowingRunnable failFastAssertion) If the suppliedfailFastAssertionever returns throws an exception, it indicates our condition will never be true, and if so fail the system immediately.If the supplied Callable ever returns false, it indicates our condition will never be true, and if so fail the system immediately.failFast(ThrowingRunnable failFastAssertion) If the suppliedfailFastAssertionever returns throws an exception, it indicates our condition will never be true, and if so fail the system immediately.forever()Await forever until the condition is satisfied.private ConditionSettingsgiven()A method to increase the readability of the Awaitility DSL.ignoreException(Class<? extends Throwable> exceptionType) Instruct Awaitility to ignore a specific exception and no subclasses of this exception.Instruct Awaitility to ignore all exceptions that occur during evaluation.ignoreExceptionsInstanceOf(Class<? extends Throwable> exceptionType) Instruct Awaitility to ignore exceptions instance of the supplied exceptionType type.ignoreExceptionsMatching(Predicate<? super Throwable> predicate) Instruct Awaitility to ignore exceptions that occur during evaluation and matches the suppliedpredicate.ignoreExceptionsMatching(org.hamcrest.Matcher<? super Throwable> matcher) Instruct Awaitility to ignore exceptions that occur during evaluation and matches the supplied Hamcrest matcher.Instruct Awaitility to not ignore any exceptions that occur during evaluation.logging()Logging condition evaluation results each time evaluation of a condition occurs to System.out.Logging condition evaluation results each time evaluation of a condition occurs to chosen consumer.Specify the delay that will be used before Awaitility starts polling for the result the first time.Specify the delay that will be used before Awaitility starts polling for the result the first time.pollExecutorService(ExecutorService executorService) Specify the executor service whose threads will be used to evaluate the poll condition in Awaitility.Instructs Awaitility to execute the polling of the condition from the same as the test.pollInterval(long pollInterval, TimeUnit unit) Specify the polling interval Awaitility will use for this await statement.pollInterval(Duration pollInterval) Specify the polling interval Awaitility will use for this await statement.pollInterval(PollInterval pollInterval) pollThread(Function<Runnable, Thread> threadSupplier) Specify a thread supplier whose thread will be used to evaluate the poll condition in Awaitility.then()A method to increase the readability of the Awaitility DSL.Await at mosttimeoutbefore throwing a timeout exception.Await at mosttimeoutbefore throwing a timeout exception.voidAwait until aCallablereturnstrue.<T> TWait until the given supplier matches the supplied predicate.<T> TAwait until aCallablesupplies a value matching the specifiedMatcher.private <T> TvoiduntilAccumulator(DoubleAccumulator accumulator, Consumer<? super Double> matcher) Await until a DoubleAccumulator is asserted by thematcherconsumer E.g.voiduntilAccumulator(DoubleAccumulator accumulator, org.hamcrest.Matcher<? super Double> matcher) Await until aDoubleAccumulatorhas a value matching the specifiedMatcher.voiduntilAccumulator(LongAccumulator accumulator, Consumer<? super Long> matcher) Await until a LongAccumulator is asserted by thematcherconsumer E.g.voiduntilAccumulator(LongAccumulator accumulator, org.hamcrest.Matcher<? super Long> matcher) Await until aLongAccumulatorhas a value matching the specifiedMatcher.voiduntilAdder(DoubleAdder adder, Consumer<? super Double> matcher) Await until a DoubleAdder is asserted by thematcherconsumer E.g.voiduntilAdder(DoubleAdder adder, org.hamcrest.Matcher<? super Double> matcher) Await until aDoubleAdderhas a value matching the specifiedMatcher.voiduntilAdder(LongAdder adder, Consumer<? super Long> matcher) Await until a LongAdder is asserted by thematcherconsumer E.g.voiduntilAdder(LongAdder adder, org.hamcrest.Matcher<? super Long> matcher) Await until aLongAdderhas a value matching the specifiedMatcher.<T> voiduntilAsserted(Callable<T> supplier, Consumer<? super T> assertConsumer) Await until a callable returns a value that when passed to aConsumerends without throwing an exception.voiduntilAsserted(ThrowingRunnable assertion) Await until aRunnablesupplier execution passes (ends without throwing an exception).voiduntilAtomic(AtomicBoolean atomic, Consumer<? super Boolean> matcher) Await until a AtomicBoolean is asserted by thematcherconsumer E.g.voiduntilAtomic(AtomicBoolean atomic, org.hamcrest.Matcher<? super Boolean> matcher) Await until a Atomic variable has a value matching the specifiedMatcher.voiduntilAtomic(AtomicInteger atomic, Consumer<? super Integer> matcher) Await until a Atomic integer is asserted by thematcherconsumer E.g.untilAtomic(AtomicInteger atomic, org.hamcrest.Matcher<? super Integer> matcher) Await until a Atomic variable has a value matching the specifiedMatcher.voiduntilAtomic(AtomicLong atomic, Consumer<? super Long> matcher) Await until a Atomic long is asserted by thematcherconsumer E.g.untilAtomic(AtomicLong atomic, org.hamcrest.Matcher<? super Long> matcher) Await until a Atomic variable has a value matching the specifiedMatcher.<V> voiduntilAtomic(AtomicReference<V> atomic, Consumer<? super V> matcher) Await until a Atomic variable is asserted by thematcherconsumer E.g.<V> VuntilAtomic(AtomicReference<V> atomic, org.hamcrest.Matcher<? super V> matcher) Await until a Atomic variable has a value matching the specifiedMatcher.voiduntilFalse(AtomicBoolean atomic) Await until a Atomic boolean becomes false.voiduntilTrue(AtomicBoolean atomic) Await until a Atomic boolean becomes true.with()A method to increase the readability of the Awaitility DSL.
-
Field Details
-
timeoutConstraint
Timing constraint. -
pollInterval
The poll interval. -
catchUncaughtExceptions
private final boolean catchUncaughtExceptionsThe catch uncaught exceptions. -
exceptionsIgnorer
The ignore exceptions. -
alias
The alias. -
pollDelay
The poll delay. -
conditionEvaluationListener
The condition evaluation listener -
executorLifecycle
The executor lifecycle -
failFastCondition
If this condition if ever false, indicates our condition will never be true.
-
-
Constructor Details
-
ConditionFactory
public ConditionFactory(String alias, WaitConstraint timeoutConstraint, PollInterval pollInterval, Duration pollDelay, boolean catchUncaughtExceptions, ExceptionIgnorer exceptionsIgnorer, ConditionEvaluationListener conditionEvaluationListener, ExecutorLifecycle executorLifecycle, FailFastCondition failFastCondition) Instantiates a new condition factory.- Parameters:
alias- the aliastimeoutConstraint- the timeout constraintpollInterval- the poll intervalpollDelay- The poll delaycatchUncaughtExceptions- the catch uncaught exceptionsexceptionsIgnorer- Determine which exceptions that should ignoredconditionEvaluationListener- Determine which exceptions that should ignoredexecutorLifecycle- The executor service and the lifecycle of the executor service that'll be used to evaluate the condition during pollingfailFastCondition- If this condition if ever false, indicates our condition will never be true.
-
-
Method Details
-
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
Logging condition evaluation results each time evaluation of a condition occurs to System.out.- Returns:
- the condition factory
-
logging
Logging condition evaluation results each time evaluation of a condition occurs to chosen consumer.- Returns:
- the condition factory
-
timeout
Await at mosttimeoutbefore throwing a timeout exception.- Parameters:
timeout- the timeout- Returns:
- the condition factory
-
atMost
Await at mosttimeoutbefore throwing a timeout exception.- Parameters:
timeout- the timeout- Returns:
- the condition factory
-
during
Await at the predicate holds during at leasttimeout- Parameters:
timeout- the timeout- Returns:
- the condition factory
-
during
Await at the predicate holds during at leasttimeout- Parameters:
timeout- the timeoutunit- the unit- Returns:
- the condition factory
-
alias
Set the alias- Parameters:
alias- alias- Returns:
- the condition factory
- See Also:
-
atLeast
Condition has to be evaluated not earlier thantimeoutbefore throwing a timeout exception.- Parameters:
timeout- the timeout- Returns:
- the condition factory
-
atLeast
Condition has to be evaluated not earlier thantimeoutbefore throwing a timeout exception.- Parameters:
timeout- the timeoutunit- the unit- Returns:
- the condition factory
-
between
Specifies the duration window which has to be satisfied during operation execution. In case operation is executed beforeatLeastor afteratMosttimeout exception is thrown.- Parameters:
atLeast- lower part of execution windowatMost- upper part of execution window- Returns:
- the condition factory
-
between
public ConditionFactory between(long atLeastDuration, TimeUnit atLeastTimeUnit, long atMostDuration, TimeUnit atMostTimeUnit) Specifies the duration window which has to be satisfied during operation execution. In case operation is executed beforeatLeastDurationor afteratMostDurationtimeout exception is thrown.- Parameters:
atLeastDuration- lower part of execution windowatMostDuration- upper part of execution window- Returns:
- the condition factory
-
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
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 usingpollDelay(Duration),pollDelay(long, TimeUnit)orpollDelay(java.time.Duration).- Parameters:
pollInterval- the poll interval- Returns:
- the condition factory
-
timeout
Await at mosttimeoutbefore throwing a timeout exception.- Parameters:
timeout- the timeoutunit- the unit- Returns:
- the condition factory
-
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:
delay- the delayunit- the unit- Returns:
- the condition factory
-
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
Await at mosttimeoutbefore throwing a timeout exception.- Parameters:
timeout- the timeoutunit- the unit- Returns:
- the condition factory
-
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 unless it's specified explicitly usingpollDelay(Duration),pollDelay(long, TimeUnit)orpollDelay(java.time.Duration), or ConditionFactory#andWithPollDelay(long, TimeUnit)}. This is the same as creating aFixedPollInterval.- Parameters:
pollInterval- the poll intervalunit- the unit- Returns:
- the condition factory
- See Also:
-
pollInterval
-
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 istrue.- Returns:
- the condition factory
-
ignoreExceptionsInstanceOf
Instruct Awaitility to ignore exceptions instance of the supplied exceptionType type. Exceptions will be treated as evaluating tofalse. 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
Instruct Awaitility to ignore a specific exception and no subclasses of this exception. Exceptions will be treated as evaluating tofalse. 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
Instruct Awaitility to ignore all exceptions that occur during evaluation. Exceptions will be treated as evaluating tofalse. This is useful in situations where the evaluated conditions may temporarily throw exceptions.- Returns:
- the condition factory.
-
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
Instruct Awaitility to ignore exceptions that occur during evaluation and matches the supplied Hamcrest matcher. Exceptions will be treated as evaluating tofalse. This is useful in situations where the evaluated conditions may temporarily throw exceptions.- Returns:
- the condition factory.
-
ignoreExceptionsMatching
Instruct Awaitility to ignore exceptions that occur during evaluation and matches the suppliedpredicate. Exceptions will be treated as evaluating tofalse. This is useful in situations where the evaluated conditions may temporarily throw exceptions.- Returns:
- the condition factory.
-
await
Await for an asynchronous operation. This method returns the sameConditionFactoryinstance and is used only to get a more fluent-like syntax.- Returns:
- the condition factory
-
await
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
A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.- Returns:
- the condition factory
-
with
A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.- Returns:
- the condition factory
-
then
A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.- Returns:
- the condition factory
-
given
A method to increase the readability of the Awaitility DSL. It simply returns the same condition factory instance.- Returns:
- the condition factory
-
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
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
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
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
If the supplied Callable ever returns false, it indicates our condition will never be true, and if so fail the system immediately. Throws aTerminalFailureExceptionif fail fast condition evaluates totrue. If you want to specify a more descriptive error message then usefailFast(String, Callable).- Parameters:
failFastCondition- The terminal failure condition- Returns:
- the condition factory
- See Also:
-
failFast
If the supplied Callable ever returns false, it indicates our condition will never be true, and if so fail the system immediately. Throws aTerminalFailureExceptionif fail fast condition evaluates totrue.- Parameters:
failFastFailureReason- A descriptive reason why the fail fast condition has failed, will be included in theTerminalFailureExceptionthrown iffailFastConditionevaluates totrue.failFastCondition- The terminal failure condition- Returns:
- the condition factory
-
failFast
If the suppliedfailFastAssertionever 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
If the suppliedfailFastAssertionever 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 theTerminalFailureExceptionthrown iffailFastAssertionthrows an exception.failFastAssertion- The terminal failure assertion- Returns:
- the condition factory
- See Also:
-
until
Await until aCallablesupplies a value matching the specifiedMatcher. E.g.await().until(numberOfPersons(), is(greaterThan(2)));
where "numberOfPersons()" returns a standardCallable:private Callable<Integer> numberOfPersons() { return new Callable<Integer>() { public Integer call() { return personRepository.size(); } }; }
Using a genericCallableas 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
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
Await until aRunnablesupplier execution passes (ends without throwing an exception). E.g. with Java 8:await().untilAsserted(() -> Assertions.assertThat(personRepository.size()).isEqualTo(6));
orawait().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.AssertionErrorinstances 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 aThrowingRunnablethat doesn't return anything (void) andCallablethat 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
Await until a callable returns a value that when passed to aConsumerends 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
Await until a Atomic variable has a value matching the specifiedMatcher. E.g.await().untilAtomic(myAtomic, is(greaterThan(2)));
- Parameters:
atomic- the atomic variablematcher- the matcher The hamcrest matcher that checks whether the condition is fulfilled.- Returns:
- a
Integerobject. - Throws:
ConditionTimeoutException- If condition was not fulfilled within the given time period.
-
untilAtomic
Await until a Atomic integer is asserted by thematcherconsumer E.g.await().untilAtomic(myAtomic, value -> Assertions.assertThat(value).isEqualTo(123));
- Parameters:
atomic- the atomic variablematcher- 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
Await until a Atomic variable has a value matching the specifiedMatcher. E.g.await().untilAtomic(myAtomic, is(greaterThan(2)));
- Parameters:
atomic- the atomic variablematcher- the matcher The hamcrest matcher that checks whether the condition is fulfilled.- Returns:
- a
Longobject. - Throws:
ConditionTimeoutException- If condition was not fulfilled within the given time period.
-
untilAtomic
Await until a Atomic long is asserted by thematcherconsumer E.g.await().untilAtomic(myAtomic, value -> Assertions.assertThat(value).isEqualTo(123L));
- Parameters:
atomic- the atomic variablematcher- 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
Await until a Atomic variable has a value matching the specifiedMatcher. E.g.await().untilAtomic(myAtomic, is(greaterThan(2)));
- Parameters:
atomic- the atomic variablematcher- 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
Await until a AtomicBoolean is asserted by thematcherconsumer E.g.await().untilAtomic(myAtomicBoolean, value -> Assertions.assertThat(value).isTrue());
- Parameters:
atomic- the atomic variablematcher- 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
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
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
Await until aLongAdderhas a value matching the specifiedMatcher. E.g.await().untilAdder(myLongAdder, is(greaterThan(2L)));
- Parameters:
adder- theLongAddervariablematcher- 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
Await until a LongAdder is asserted by thematcherconsumer E.g.await().untilAdder(myAdder, value -> Assertions.assertThat(value).isEqualTo(123L));
- Parameters:
adder- the atomic variablematcher- 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
Await until aDoubleAdderhas a value matching the specifiedMatcher. E.g.await().untilAdder(myDoubleAdder, is(greaterThan(2.0d)));
- Parameters:
adder- theDoubleAddervariablematcher- 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
Await until a DoubleAdder is asserted by thematcherconsumer E.g.await().untilAdder(myAdder, value -> Assertions.assertThat(value).isEqualTo(12.3d));
- Parameters:
adder- the atomic variablematcher- 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(LongAccumulator accumulator, org.hamcrest.Matcher<? super Long> matcher) Await until aLongAccumulatorhas a value matching the specifiedMatcher. E.g.await().untilAccumulator(myLongAccumulator, is(greaterThan(2L)));
- Parameters:
accumulator- theLongAccumulatorvariablematcher- 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
Await until a LongAccumulator is asserted by thematcherconsumer E.g.await().untilAccumulator(myAdder, value -> Assertions.assertThat(value).isEqualTo(123L));
- Parameters:
accumulator- the atomic variablematcher- 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(DoubleAccumulator accumulator, org.hamcrest.Matcher<? super Double> matcher) Await until aDoubleAccumulatorhas a value matching the specifiedMatcher. E.g.await().untilAccumulator(myDoubleAccumulator, is(greaterThan(2.0d)));
- Parameters:
accumulator- theDoubleAccumulatorvariablematcher- 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
Await until a DoubleAccumulator is asserted by thematcherconsumer E.g.await().untilAccumulator(myAdder, value -> Assertions.assertThat(value).isEqualTo(12.3d));
- Parameters:
accumulator- the atomic variablematcher- 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
Await until a Atomic variable has a value matching the specifiedMatcher. E.g.await().untilAtomic(myAtomic, is(greaterThan(2)));
- Type Parameters:
V- a V object.- Parameters:
atomic- the atomic variablematcher- 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
Await until a Atomic variable is asserted by thematcherconsumer E.g.await().untilAtomic(myAtomic, value -> Assertions.assertThat(value).isEqualTo("something"));- Type Parameters:
V- a V object.- Parameters:
atomic- the atomic variablematcher- 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
Await until aCallablereturnstrue. 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 standardCallableof typeBoolean: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.
-
generateConditionSettings
-
until
-
definePollDelay
Ensures backward compatibility (especially that poll delay is the same as poll interval for fixed poll interval). It also make sure that poll delay isDuration.ZEROfor 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 delaypollInterval- The chosen (or default) poll interval- Returns:
- The poll delay to use
-