Class PreemptiveTimeoutUtils
java.lang.Object
org.junit.jupiter.api.util.PreemptiveTimeoutUtils
Internal utilities for executing code with a preemptive timeout.
- Since:
- 6.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Factory for timeout failures. -
Method Summary
Modifier and TypeMethodDescriptionexecuteWithPreemptiveTimeout
(Duration timeout, ThrowingSupplier<T> supplier, @Nullable Supplier<@Nullable String> messageSupplier, PreemptiveTimeoutUtils.TimeoutFailureFactory<E> failureFactory) Assert that execution of the suppliedsupplier
completes before the giventimeout
is exceeded.
-
Method Details
-
executeWithPreemptiveTimeout
public static <T extends @Nullable Object, E extends Throwable> T executeWithPreemptiveTimeout(Duration timeout, ThrowingSupplier<T> supplier, @Nullable Supplier<@Nullable String> messageSupplier, PreemptiveTimeoutUtils.TimeoutFailureFactory<E> failureFactory) throws E Assert that execution of the suppliedsupplier
completes before the giventimeout
is exceeded.See the Preemptive Timeouts section of the class-level Javadoc for further details.
If the assertion passes then the
supplier
's result is returned.In the case the assertion does not pass, the supplied
PreemptiveTimeoutUtils.TimeoutFailureFactory
is invoked to create an exception which is then thrown.If necessary, the failure message will be retrieved lazily from the supplied
messageSupplier
.- Throws:
E
-