use of com.github.rholder.retry.WaitStrategy in project graylog2-server by Graylog2.
the class MessagesRetryWaitTest method secondsBasedRetryWaitsForSecondsStartingWith1.
@Test
void secondsBasedRetryWaitsForSecondsStartingWith1() {
WaitStrategy waitStrategy = Messages.exponentialWaitSeconds;
assertAll(() -> assertThat(waitStrategy.computeSleepTime(new IndexBlockRetryAttempt(1))).isEqualTo(1000), () -> assertThat(waitStrategy.computeSleepTime(new IndexBlockRetryAttempt(2))).isEqualTo(2000), () -> assertThat(waitStrategy.computeSleepTime(new IndexBlockRetryAttempt(3))).isEqualTo(4000), () -> assertThat(waitStrategy.computeSleepTime(new IndexBlockRetryAttempt(4))).isEqualTo(8000), () -> assertThat(waitStrategy.computeSleepTime(new IndexBlockRetryAttempt(5))).isEqualTo(16000));
}
use of com.github.rholder.retry.WaitStrategy in project cloudbreak by hortonworks.
the class RetryUtil method buildRetryer.
/**
* Builds a retryer.
*
* @param actionDescription a description of the action being performed
* @param waitUntilTime the latest time to wait to perform the action
* @param sleepTimeMs the sleep time in millisecond for retries
* @param exceptionClass the class of exception to throw
* @param logger the logger
* @param <T> the type of object returned
* @return the retryer
*/
private static <T> Retryer<T> buildRetryer(String actionDescription, ZonedDateTime waitUntilTime, long sleepTimeMs, Class<? extends CcmException> exceptionClass, Logger logger) {
StopStrategy stop;
if (waitUntilTime != null) {
// Given the time at which waiting should stop,
// get the available number of millis from this instant
stop = StopStrategyFactory.waitUntilDateTime(waitUntilTime);
logger.info("Trying until {} to {}", waitUntilTime, actionDescription);
} else {
stop = StopStrategies.neverStop();
logger.warn("Unbounded wait to {}", actionDescription);
}
WaitStrategy wait = WaitStrategies.fixedWait(sleepTimeMs, TimeUnit.MILLISECONDS);
logger.info("Checking every {} milliseconds", sleepTimeMs);
return RetryerBuilder.<T>newBuilder().retryIfException(t -> exceptionClass.isInstance(t) && ((CcmException) t).isRetryable()).retryIfResult(Objects::isNull).withStopStrategy(stop).withWaitStrategy(wait).build();
}
use of com.github.rholder.retry.WaitStrategy in project graylog2-server by Graylog2.
the class MessagesRetryWaitTest method millisecondsBasedRetryWaitsForMillisecondsStartingWith2.
// This test was added to document how the retry strategy actually behaves since this is hard to deduct from the code
@Test
void millisecondsBasedRetryWaitsForMillisecondsStartingWith2() {
WaitStrategy waitStrategy = Messages.exponentialWaitMilliseconds;
assertAll(() -> assertThat(waitStrategy.computeSleepTime(new IndexBlockRetryAttempt(1))).isEqualTo(2), () -> assertThat(waitStrategy.computeSleepTime(new IndexBlockRetryAttempt(2))).isEqualTo(4), () -> assertThat(waitStrategy.computeSleepTime(new IndexBlockRetryAttempt(3))).isEqualTo(8), () -> assertThat(waitStrategy.computeSleepTime(new IndexBlockRetryAttempt(4))).isEqualTo(16), () -> assertThat(waitStrategy.computeSleepTime(new IndexBlockRetryAttempt(5))).isEqualTo(32));
}
Aggregations