use of org.apache.samza.table.AsyncReadWriteUpdateTable in project samza by apache.
the class TestAsyncRetriableTable method testUpdateWithPermFailureOnMaxCount.
@Test
public void testUpdateWithPermFailureOnMaxCount() {
TableRetryPolicy policy = new TableRetryPolicy();
policy.withFixedBackoff(Duration.ofMillis(5));
policy.withStopAfterAttempts(5);
TableReadFunction<String, String> readFn = mock(TableReadFunction.class);
TableWriteFunction<String, String, String> writeFn = mock(TableWriteFunction.class);
doReturn(true).when(writeFn).isRetriable(any());
CompletableFuture<String> future = new CompletableFuture();
future.completeExceptionally(new RuntimeException("test exception"));
doReturn(future).when(writeFn).updateAsync(any(), any());
AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, writeFn);
AsyncRetriableTable table = new AsyncRetriableTable("t1", delegate, null, policy, schedExec, readFn, writeFn);
table.init(TestRemoteTable.getMockContext());
try {
table.updateAsync(1, 2).join();
fail();
} catch (Throwable t) {
}
verify(writeFn, atLeast(6)).updateAsync(any(), any());
assertEquals(5, table.writeRetryMetrics.retryCount.getCount());
assertEquals(0, table.writeRetryMetrics.successCount.getCount());
assertEquals(1, table.writeRetryMetrics.permFailureCount.getCount());
assertTrue(table.writeRetryMetrics.retryTimer.getSnapshot().getMax() > 0);
}
use of org.apache.samza.table.AsyncReadWriteUpdateTable 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