use of org.apache.samza.table.remote.AsyncRemoteTable in project samza by apache.
the class TestAsyncRetriableTable method testGetAllWithOneRetry.
@Test
public void testGetAllWithOneRetry() {
TableRetryPolicy policy = new TableRetryPolicy();
policy.withFixedBackoff(Duration.ofMillis(10));
TableReadFunction<String, String> readFn = mock(TableReadFunction.class);
doReturn(true).when(readFn).isRetriable(any());
AtomicInteger times = new AtomicInteger();
Map<String, String> map = new HashMap<>();
map.put("foo1", "bar1");
map.put("foo2", "bar2");
doAnswer(invocation -> {
CompletableFuture<Map<String, String>> future = new CompletableFuture();
if (times.get() > 0) {
future.complete(map);
} else {
times.incrementAndGet();
future.completeExceptionally(new RuntimeException("test exception"));
}
return future;
}).when(readFn).getAllAsync(anyCollection());
AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, null);
AsyncRetriableTable table = new AsyncRetriableTable("t1", delegate, policy, null, schedExec, readFn, null);
table.init(TestRemoteTable.getMockContext());
assertEquals(map, table.getAllAsync(Arrays.asList("foo1", "foo2")).join());
verify(readFn, times(2)).getAllAsync(any());
assertEquals(1, table.readRetryMetrics.retryCount.getCount());
assertEquals(0, table.readRetryMetrics.successCount.getCount());
assertEquals(0, table.readRetryMetrics.permFailureCount.getCount());
assertTrue(table.readRetryMetrics.retryTimer.getSnapshot().getMax() > 0);
}
Aggregations