private static void testBasicRetriesToSuccess(int expectedRetries, boolean wrapWithApplicationException)
throws Exception
{
RetryPolicy retryPolicy = new RetryPolicy(
new DriftClientConfig()
.setMaxRetries(expectedRetries + 10)
.setMinBackoffDelay(new Duration(1, SECONDS))
.setMaxBackoffDelay(new Duration(1, DAYS))
.setBackoffScaleFactor(2.0),
new TestingExceptionClassifier());
TestingMethodInvocationStat stat = new TestingMethodInvocationStat();
AtomicInteger attempts = new AtomicInteger();
MockMethodInvoker invoker = new MockMethodInvoker(() -> {
int currentAttempts = attempts.getAndIncrement();
if (currentAttempts < expectedRetries) {
return immediateFailedFuture(createClassifiedException(true, NORMAL, wrapWithApplicationException));
}
return immediateFuture(SUCCESS);
});
DriftMethodInvocation<?> methodInvocation = createDriftMethodInvocation(retryPolicy, stat, invoker, new TestingAddressSelector(100), systemTicker());
assertEquals(methodInvocation.get(), SUCCESS);
assertEquals(attempts.get(), expectedRetries + 1);
stat.assertSuccess(expectedRetries);
assertDelays(invoker, retryPolicy, expectedRetries);
}