private static void testPropagateCancel(int expectedRetries, boolean interrupt)
throws Exception
{
RetryPolicy retryPolicy = new RetryPolicy(new DriftClientConfig().setMaxRetries(expectedRetries + 10), new TestingExceptionClassifier());
TestingMethodInvocationStat stat = new TestingMethodInvocationStat();
AtomicInteger attempts = new AtomicInteger();
TestFuture future = new TestFuture();
CountDownLatch settableFutureFetched = new CountDownLatch(1);
DriftMethodInvocation<?> methodInvocation = createDriftMethodInvocation(
retryPolicy,
stat,
() -> {
attempts.getAndIncrement();
if (attempts.get() > expectedRetries) {
settableFutureFetched.countDown();
return future;
}
return immediateFailedFuture(createClassifiedException(true, NORMAL));
});
settableFutureFetched.await();
methodInvocation.cancel(interrupt);
assertTrue(future.isCancelled());
assertEquals(future.checkWasInterrupted(), interrupt);
assertEquals(attempts.get(), expectedRetries + 1);
}