public long getBackoffTimeAndIncrementAttempts() { long backoffTime = getBackoffTime(); useRetry(); return backoffTime; } }
/** * Sleep for a back off time as supplied by the backoff policy, and increases the attempts */ public void sleepUntilNextRetry() throws InterruptedException { int attempts = getAttemptTimes(); long sleepTime = getBackoffTime(); LOG.trace("Sleeping {} ms before retry #{}...", sleepTime, attempts); retryConfig.getTimeUnit().sleep(sleepTime); useRetry(); }
@Test public void testBasics() throws InterruptedException { int maxAttempts = 10; RetryCounterFactory factory = new RetryCounterFactory(maxAttempts, 10, 1000); RetryCounter retryCounter = factory.create(); while (retryCounter.shouldRetry()) { LOG.info("Attempt={}, backoffTime={}", retryCounter.getAttemptTimes(), retryCounter.getBackoffTime()); retryCounter.sleepUntilNextRetry(); } assertTrue(retryCounter.getAttemptTimes() == maxAttempts); } }
public long getBackoffTimeAndIncrementAttempts() { long backoffTime = getBackoffTime(); useRetry(); return backoffTime; } }
/** * Sleep for a back off time as supplied by the backoff policy, and increases the attempts * @throws InterruptedException */ public void sleepUntilNextRetry() throws InterruptedException { int attempts = getAttemptTimes(); long sleepTime = getBackoffTime(); LOG.trace("Sleeping {} ms before retry #{}...", sleepTime, attempts); retryConfig.getTimeUnit().sleep(sleepTime); useRetry(); }
@Test public void testBasics() throws InterruptedException { int maxAttempts = 10; RetryCounterFactory factory = new RetryCounterFactory(maxAttempts, 10, 1000); RetryCounter retryCounter = factory.create(); while (retryCounter.shouldRetry()) { LOG.info("Attempt={}, backoffTime={}", retryCounter.getAttemptTimes(), retryCounter.getBackoffTime()); retryCounter.sleepUntilNextRetry(); } assertTrue(retryCounter.getAttemptTimes() == maxAttempts); } }