A Java DSL for synchronizing asynchronous operations
—
Primary DSL entry points for creating await statements and configuring basic wait conditions. These static methods form the foundation of all Awaitility operations.
Start building an await statement with default configuration.
/**
* Start building an await statement with default settings
* @return ConditionFactory for configuring and executing conditions
*/
static ConditionFactory await();Usage Example:
await().until(customerStatusHasUpdated());Start building a named await statement for better error messages and debugging.
/**
* Start building a named await statement for debugging
* @param alias name shown in timeout error messages
* @return ConditionFactory for configuring and executing conditions
*/
static ConditionFactory await(String alias);Usage Example:
await("customer registration").until(customerStatus(), equalTo(REGISTERED));Enable or disable automatic catching of uncaught exceptions during condition evaluation.
/**
* Start building an await statement with uncaught exception catching enabled
* @return ConditionFactory with uncaught exception catching enabled
*/
static ConditionFactory catchUncaughtExceptions();
/**
* Start building an await statement with uncaught exception catching disabled
* @return ConditionFactory with uncaught exception catching disabled
*/
static ConditionFactory dontCatchUncaughtExceptions();Usage Examples:
// Enable uncaught exception catching for this await
catchUncaughtExceptions().await().until(riskyOperation());
// Disable uncaught exception catching for this await
dontCatchUncaughtExceptions().await().until(cleanOperation());Alternative entry points for fluent configuration before await.
/**
* Start constructing an await statement with settings
* @return ConditionFactory for configuration and await
*/
static ConditionFactory with();
/**
* Alternative to with() for readable fluent chains
* @return ConditionFactory for configuration and await
*/
static ConditionFactory given();Usage Examples:
with().pollInterval(20, MILLISECONDS).await().until(somethingHappens());
given().timeout(30, SECONDS)
.and().pollDelay(100, MILLISECONDS)
.await("data processing")
.until(dataIsProcessed());Create await statements with explicit timeout without additional configuration.
/**
* Create await with explicit timeout using Duration
* @param timeout maximum wait time
* @return ConditionFactory with timeout pre-configured
*/
static ConditionFactory waitAtMost(Duration timeout);
/**
* Create await with explicit timeout using value and unit
* @param value timeout value
* @param unit time unit for timeout
* @return ConditionFactory with timeout pre-configured
*/
static ConditionFactory waitAtMost(long value, TimeUnit unit);Usage Examples:
waitAtMost(Duration.ofSeconds(10)).until(serviceIsReady());
waitAtMost(5, MINUTES).until(batchJobCompletes());Control uncaught exception handling behavior from the start.
/**
* Enable catching uncaught exceptions from other threads
* @return ConditionFactory with exception catching enabled
*/
static ConditionFactory catchUncaughtExceptions();
/**
* Disable catching uncaught exceptions from other threads
* @return ConditionFactory with exception catching disabled
*/
static ConditionFactory dontCatchUncaughtExceptions();Usage Examples:
// Fail test if any thread throws uncaught exception
catchUncaughtExceptions().await().until(multiThreadedOperationCompletes());
// Ignore uncaught exceptions from other threads
dontCatchUncaughtExceptions().await().until(operationCompletes());Create suppliers for field-based conditions using reflection.
/**
* Create field supplier builder for instance fields
* @param object instance containing the field
* @return FieldSupplierBuilder for field specification
*/
static FieldSupplierBuilder fieldIn(Object object);
/**
* Create field supplier builder for static fields
* @param clazz class containing the static field
* @return FieldSupplierBuilder for field specification
*/
static FieldSupplierBuilder fieldIn(Class<?> clazz);Usage Examples:
// Wait for instance field value
await().until(fieldIn(orderService).withName("processedCount"), greaterThan(10));
// Wait for static field value
await().until(fieldIn(DatabasePool.class).withName("activeConnections"), lessThan(5));Static methods for setting default behavior across all await statements.
/**
* Reset all default configuration to initial values:
* - timeout: 10 seconds
* - poll interval: 100 milliseconds
* - poll delay: 100 milliseconds
* - catch uncaught exceptions: true
* - ignore exceptions: false
*/
static void reset();/**
* Set default timeout for all await statements
* @param timeout default timeout duration
*/
static void setDefaultTimeout(Duration timeout);
/**
* Set default timeout using value and unit
* @param timeout timeout value
* @param unit time unit
*/
static void setDefaultTimeout(long timeout, TimeUnit unit);/**
* Set default poll interval for all await statements
* @param pollInterval default polling interval
*/
static void setDefaultPollInterval(Duration pollInterval);
/**
* Set default poll interval using value and unit
* @param pollInterval interval value
* @param unit time unit
*/
static void setDefaultPollInterval(long pollInterval, TimeUnit unit);
/**
* Set default poll interval using PollInterval strategy
* @param pollInterval polling strategy implementation
*/
static void setDefaultPollInterval(PollInterval pollInterval);
/**
* Set default poll delay for all await statements
* @param pollDelay initial delay before first poll
*/
static void setDefaultPollDelay(Duration pollDelay);
/**
* Set default poll delay using value and unit
* @param pollDelay delay value
* @param unit time unit
*/
static void setDefaultPollDelay(long pollDelay, TimeUnit unit);/**
* Enable catching uncaught exceptions by default for all await statements
*/
static void catchUncaughtExceptionsByDefault();
/**
* Disable catching uncaught exceptions by default for all await statements
*/
static void doNotCatchUncaughtExceptionsByDefault();
/**
* Ignore all exceptions by default for all await statements
*/
static void ignoreExceptionsByDefault();
/**
* Ignore specific exception type by default for all await statements
* @param exceptionType exception class to ignore
*/
static void ignoreExceptionByDefault(Class<? extends Throwable> exceptionType);
/**
* Ignore exceptions matching predicate by default for all await statements
* @param predicate function to test exceptions
*/
static void ignoreExceptionsByDefaultMatching(Predicate<? super Throwable> predicate);
/**
* Ignore exceptions matching Hamcrest matcher by default for all await statements
* @param matcher Hamcrest matcher for exceptions
*/
static void ignoreExceptionsByDefaultMatching(Matcher<? super Throwable> matcher);/**
* Set default condition evaluation listener for all await statements
* @param defaultConditionEvaluationListener listener for evaluation events
*/
static void setDefaultConditionEvaluationListener(ConditionEvaluationListener defaultConditionEvaluationListener);
/**
* Set logging listener for condition evaluation events
* @param loggingListener listener that handles logging
*/
static void setLoggingListener(ConditionEvaluationListener loggingListener);
/**
* Enable custom logging for condition evaluation
* @param logPrinter consumer that handles log messages
*/
static void setLogging(Consumer<String> logPrinter);
/**
* Enable default logging for condition evaluation to System.out
*/
static void setDefaultLogging();/**
* Set default fail-fast condition for all await statements
* @param defaultFailFastCondition condition that triggers immediate failure
*/
static void setDefaultFailFastCondition(Callable<Boolean> defaultFailFastCondition);
/**
* Set default fail-fast condition with custom failure reason
* @param failFastFailureReason reason shown when fail-fast triggers
* @param defaultFailFastCondition condition that triggers immediate failure
*/
static void setDefaultFailFastCondition(String failFastFailureReason, Callable<Boolean> defaultFailFastCondition);
/**
* Set default fail-fast assertion for all await statements
* @param defaultFailFastAssertion assertion that triggers immediate failure
*/
static void setDefaultFailFastCondition(ThrowingRunnable defaultFailFastAssertion);
/**
* Set default fail-fast assertion with custom failure reason
* @param failFastFailureReason reason shown when fail-fast triggers
* @param defaultFailFastAssertion assertion that triggers immediate failure
*/
static void setDefaultFailFastCondition(String failFastFailureReason, ThrowingRunnable defaultFailFastAssertion);/**
* Configure all await statements to poll in the same thread (synchronous polling)
*/
static void pollInSameThread();
/**
* Configure all await statements to use a custom executor service for polling
* @param executorService executor service for condition evaluation
*/
static void pollExecutorService(ExecutorService executorService);
/**
* Configure all await statements to use a custom thread supplier for polling
* @param threadSupplier function that creates threads for condition evaluation
*/
static void pollThread(Function<Runnable, Thread> threadSupplier);Configuration Examples:
// Set global defaults at test class setup
@BeforeClass
public static void configureAwaitility() {
setDefaultTimeout(30, SECONDS);
setDefaultPollInterval(50, MILLISECONDS);
setDefaultPollDelay(10, MILLISECONDS);
}
@AfterClass
public static void resetAwaitility() {
reset(); // Clean up for other tests
}Install with Tessl CLI
npx tessl i tessl/maven-org-awaitility--awaitility