public static void waitFor(WaitConfig waitConfig, WaitHandler wh, Supplier<String> timeoutMessageSupplier) { if (waitConfig.duration == null) { throw new RuntimeException("duration must be specified"); } TestContext waitContext = new TestContext(1, waitConfig.duration); waitContext.setCheckInterval(waitConfig.interval); try { waitContext.await(() -> { if (wh.isReady()) { waitContext.complete(); } }); } catch (Exception ex) { Exception exceptionToThrow; if (ex instanceof TimeoutException) { // add original exception as suppressed exception to provide more context String timeoutMessage = timeoutMessageSupplier.get(); exceptionToThrow = new TimeoutException(timeoutMessage); } else { String msg = "waitFor check logic raised exception"; exceptionToThrow = new IllegalStateException(msg); } exceptionToThrow.addSuppressed(ex); throw ExceptionTestUtils.throwAsUnchecked(exceptionToThrow); } }
public static void waitFor(WaitConfig waitConfig, WaitHandler wh, Supplier<String> timeoutMessageSupplier) { if (waitConfig.duration == null) { throw new RuntimeException("duration must be specified"); } TestContext waitContext = new TestContext(1, waitConfig.duration); waitContext.setCheckInterval(waitConfig.interval); try { waitContext.await(() -> { if (wh.isReady()) { waitContext.complete(); } }); } catch (Exception ex) { Exception exceptionToThrow; if (ex instanceof TimeoutException) { // add original exception as suppressed exception to provide more context String timeoutMessage = timeoutMessageSupplier.get(); exceptionToThrow = new TimeoutException(timeoutMessage); } else { String msg = "waitFor check logic raised exception"; exceptionToThrow = new IllegalStateException(msg); } exceptionToThrow.addSuppressed(ex); throw ExceptionTestUtils.throwAsUnchecked(exceptionToThrow); } }
} catch (RuntimeException e) { throw ExceptionTestUtils.throwAsUnchecked(e.getSuppressed()[0]);
} catch (RuntimeException e) { throw ExceptionTestUtils.throwAsUnchecked(e.getSuppressed()[0]);