Class PreemptiveTimeoutUtils

java.lang.Object
org.junit.jupiter.api.util.PreemptiveTimeoutUtils

@API(status=INTERNAL, since="6.0") public class PreemptiveTimeoutUtils extends Object
Internal utilities for executing code with a preemptive timeout.
Since:
6.0
  • 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 supplied supplier completes before the given timeout 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