.withWaitStrategy(WaitStrategies.randomWait(5, TimeUnit.MILLISECONDS)) .withStopStrategy(StopStrategies.stopAfterAttempt(10)) .build();
.withWaitStrategy(WaitStrategies.join( WaitStrategies.exponentialWait(1000, 90, TimeUnit.SECONDS), WaitStrategies.randomWait(100, TimeUnit.MILLISECONDS, 500, TimeUnit.MILLISECONDS) )) .withStopStrategy(StopStrategies.stopAfterAttempt(retryCount))
@Bean public Retryer<PaymentLog> retryer(MonitorAppConfigHolder configHolder) { return RetryerBuilder.<PaymentLog>newBuilder() .retryIfExceptionOfType(OptimisticLockingFailureException.class) .retryIfExceptionOfType(OptimisticLockException.class) .withWaitStrategy(randomWait( configHolder.getTokenConversionMaxTimeWait(), TimeUnit.MILLISECONDS)) .withStopStrategy(StopStrategies.neverStop()) .build(); } }
.withWaitStrategy(WaitStrategies.join( WaitStrategies.exponentialWait(1000, 90, TimeUnit.SECONDS), WaitStrategies.randomWait(100, TimeUnit.MILLISECONDS, 500, TimeUnit.MILLISECONDS) )) .withStopStrategy(StopStrategies.stopAfterAttempt(retryCount))
@Bean public Retryer retryer(RatesAppConfigHolder ratesAppConfig) { return RetryerBuilder.newBuilder() .retryIfExceptionOfType(IOException.class) .retryIfRuntimeException() .withWaitStrategy(randomWait(ratesAppConfig.getMinTimeWait(), TimeUnit.MILLISECONDS, ratesAppConfig.getMaxTimeWait(), TimeUnit.MILLISECONDS)) .withStopStrategy(stopAfterAttempt(ratesAppConfig.getMaxAttempts())) .build(); }
@Bean public Retryer retryer(KycConfigHolder kycConfigHolder) { return RetryerBuilder.newBuilder() .retryIfExceptionOfType(Exception.class) .retryIfRuntimeException() .withWaitStrategy(randomWait(kycConfigHolder.getMinTimeWait(), TimeUnit.MILLISECONDS, kycConfigHolder.getMaxTimeWait(), TimeUnit.MILLISECONDS)) .withStopStrategy(stopAfterAttempt(kycConfigHolder.getMaxAttempts())) .build(); }
.withWaitStrategy(WaitStrategies.randomWait(5, TimeUnit.MILLISECONDS)) .withStopStrategy(StopStrategies.stopAfterAttempt(10)) .build();
private <T> T retry(Callable<T> f) throws ExecutionException, RetryException { final Retryer<T> retryer = RetryerBuilder.<T>newBuilder() .retryIfException(Impl::isRetryableException) .withWaitStrategy(WaitStrategies.join(exponentialWait(), randomWait(1, SECONDS))) .withStopStrategy(retryStopStrategy) .withRetryListener(Impl::onRequestAttempt) .build(); return retryer.call(f); }
@Test public void testRandomWaitWithoutMinimum() { WaitStrategy randomWait = WaitStrategies.randomWait(2000L, TimeUnit.MILLISECONDS); Set<Long> times = Sets.newHashSet(); times.add(randomWait.computeSleepTime(failedAttempt(1, 6546L))); times.add(randomWait.computeSleepTime(failedAttempt(1, 6546L))); times.add(randomWait.computeSleepTime(failedAttempt(1, 6546L))); times.add(randomWait.computeSleepTime(failedAttempt(1, 6546L))); assertTrue(times.size() > 1); // if not, the random is not random for (long time : times) { assertTrue(time >= 0L); assertTrue(time <= 2000L); } }
@Test public void testRandomWait() { WaitStrategy randomWait = WaitStrategies.randomWait(1000L, TimeUnit.MILLISECONDS, 2000L, TimeUnit.MILLISECONDS); Set<Long> times = Sets.newHashSet(); times.add(randomWait.computeSleepTime(failedAttempt(1, 6546L))); times.add(randomWait.computeSleepTime(failedAttempt(1, 6546L))); times.add(randomWait.computeSleepTime(failedAttempt(1, 6546L))); times.add(randomWait.computeSleepTime(failedAttempt(1, 6546L))); assertTrue(times.size() > 1); // if not, the random is not random for (long time : times) { assertTrue(time >= 1000L); assertTrue(time <= 2000L); } }
@Bean public Retryer<PaymentLog> retryer() { return RetryerBuilder.<PaymentLog>newBuilder() .retryIfExceptionOfType(OptimisticLockingFailureException.class) .retryIfExceptionOfType(OptimisticLockException.class) .withWaitStrategy(randomWait(1000L, TimeUnit.MILLISECONDS)) .withStopStrategy(StopStrategies.neverStop()) .build(); }
@Bean public Retryer retryer(KycConfigHolder kycConfigHolder) { return RetryerBuilder.newBuilder() .retryIfExceptionOfType(Exception.class) .retryIfRuntimeException() .withWaitStrategy(randomWait(kycConfigHolder.getMinTimeWait(), TimeUnit.MILLISECONDS, kycConfigHolder.getMaxTimeWait(), TimeUnit.MILLISECONDS)) .withStopStrategy(stopAfterAttempt(kycConfigHolder.getMaxAttempts())) .build(); }