*/
class RetryFutureTest {
+ private static final int TIMEOUT_MS = 1000;
private ScheduledExecutorService scheduler;
@BeforeEach
}
@Test
- void callWithRetryNormal() throws InterruptedException {
+ void callWithRetryNormal() {
Future<String> retryFuture = RetryFuture.callWithRetry(() -> "test", scheduler);
try {
- assertEquals("test", retryFuture.get(100, TimeUnit.MILLISECONDS));
+ assertEquals("test", retryFuture.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
} catch (InterruptedException | ExecutionException | TimeoutException e) {
fail(e);
}
}
@Test
- void callWithRetry1() throws InterruptedException {
+ void callWithRetry1() {
AtomicInteger visitCount = new AtomicInteger();
Future<String> retryFuture = RetryFuture.callWithRetry(() -> {
if (visitCount.getAndIncrement() == 0) {
return "test";
}, scheduler);
try {
- assertEquals("test", retryFuture.get(100, TimeUnit.MILLISECONDS));
+ assertEquals("test", retryFuture.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
} catch (InterruptedException | ExecutionException | TimeoutException e) {
fail(e);
}
}
@Test
- void composeWithRetryNormal() throws InterruptedException {
+ void composeWithRetryNormal() {
CompletableFuture<?> composedFuture = new CompletableFuture<>();
Future<?> retryFuture = RetryFuture.composeWithRetry(() -> {
}, scheduler);
try {
- retryFuture.get(100, TimeUnit.MILLISECONDS);
+ retryFuture.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
fail(e);
}
}
@Test
- void composeWithRetryThrow() throws InterruptedException {
+ void composeWithRetryThrow() {
CompletableFuture<?> composedFuture = new CompletableFuture<>();
Future<?> retryFuture = RetryFuture.composeWithRetry(() -> {
}, scheduler);
try {
- retryFuture.get(100, TimeUnit.MILLISECONDS);
+ retryFuture.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
} catch (InterruptedException | TimeoutException e) {
fail(e);
} catch (ExecutionException ex) {
}, scheduler);
try {
- assertEquals("test", retryFuture.get(100, TimeUnit.MILLISECONDS));
+ assertEquals("test", retryFuture.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
} catch (InterruptedException | ExecutionException | TimeoutException e) {
fail(e);
}
}
@Test
- void composeWithRetry1Cancel() throws InterruptedException {
+ void composeWithRetry1Cancel() {
CountDownLatch latch = new CountDownLatch(1);
AtomicInteger visitCount = new AtomicInteger();
CompletableFuture<String> composedFuture = new CompletableFuture<>();
}, scheduler);
try {
- if (!latch.await(100, TimeUnit.MILLISECONDS)) {
+ if (!latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
fail("Timeout while waiting for latch");
}
Thread.sleep(1);