private Attempt<Boolean> failedAttempt(int attemptNumber, long delaySinceFirstAttempt) { return new Attempt<>(new RuntimeException(), attemptNumber, delaySinceFirstAttempt); } }
private Attempt<Boolean> failedAttempt(int attemptNumber, long delaySinceFirstAttempt) { return new Attempt<>(new RuntimeException(), attemptNumber, delaySinceFirstAttempt); }
try { T result = attemptTimeLimiter.call(callable); attempt = new Attempt<>(result, attemptNumber, System.currentTimeMillis() - startTimeMillis); } catch(InterruptedException e) { throw e; } catch (Throwable t) { attempt = new Attempt<>(t, attemptNumber, System.currentTimeMillis() - startTimeMillis);
@Test public void testExceptionWait() { WaitStrategy exceptionWait = WaitStrategies.exceptionWait( RuntimeException.class, zeroSleepFunction()); assertEquals(0L, exceptionWait.computeSleepTime(failedAttempt(42, 7227))); WaitStrategy oneMinuteWait = WaitStrategies.exceptionWait(RuntimeException.class, oneMinuteSleepFunction()); assertEquals(3600 * 1000L, oneMinuteWait.computeSleepTime(failedAttempt(42, 7227))); WaitStrategy noMatchRetryAfterWait = WaitStrategies.exceptionWait(RetryAfterException.class, customSleepFunction()); assertEquals(0L, noMatchRetryAfterWait.computeSleepTime(failedAttempt(42, 7227))); WaitStrategy retryAfterWait = WaitStrategies.exceptionWait(RetryAfterException.class, customSleepFunction()); Attempt<Boolean> failedAttempt = new Attempt<>( new RetryAfterException(), 42, 7227L); assertEquals(29L, retryAfterWait.computeSleepTime(failedAttempt)); }