use of org.apache.samza.table.remote.AsyncRemoteTable in project samza by apache.
the class TestAsyncRetriableTable method testGetDelegation.
@Test
public void testGetDelegation() {
TableRetryPolicy policy = new TableRetryPolicy();
policy.withFixedBackoff(Duration.ofMillis(100));
TableReadFunction readFn = mock(TableReadFunction.class);
doReturn(CompletableFuture.completedFuture("bar")).when(readFn).getAsync(any());
doReturn(CompletableFuture.completedFuture("bar")).when(readFn).getAsync(any(), any());
Map<String, String> result = new HashMap<>();
result.put("foo", "bar");
doReturn(CompletableFuture.completedFuture(result)).when(readFn).getAllAsync(any());
doReturn(CompletableFuture.completedFuture(result)).when(readFn).getAllAsync(any(), any());
doReturn(CompletableFuture.completedFuture(5)).when(readFn).readAsync(anyInt(), any());
AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, null);
AsyncRetriableTable table = new AsyncRetriableTable("t1", delegate, policy, null, schedExec, readFn, null);
table.init(TestRemoteTable.getMockContext());
verify(readFn, times(0)).init(any(), any());
// GetAsync
verify(readFn, times(0)).getAsync(any());
verify(readFn, times(0)).getAsync(any(), any());
assertEquals("bar", table.getAsync("foo").join());
verify(readFn, times(1)).getAsync(any());
verify(readFn, times(0)).getAsync(any(), any());
assertEquals("bar", table.getAsync("foo", 1).join());
verify(readFn, times(1)).getAsync(any());
verify(readFn, times(1)).getAsync(any(), any());
// GetAllAsync
verify(readFn, times(0)).getAllAsync(any());
verify(readFn, times(0)).getAllAsync(any(), any());
assertEquals(result, table.getAllAsync(Arrays.asList("foo")).join());
verify(readFn, times(1)).getAllAsync(any());
verify(readFn, times(0)).getAllAsync(any(), any());
assertEquals(result, table.getAllAsync(Arrays.asList("foo"), Arrays.asList(1)).join());
verify(readFn, times(1)).getAllAsync(any());
verify(readFn, times(1)).getAllAsync(any(), any());
// ReadAsync
verify(readFn, times(0)).readAsync(anyInt(), any());
assertEquals(5, table.readAsync(1, 2).join());
verify(readFn, times(1)).readAsync(anyInt(), any());
table.close();
}
use of org.apache.samza.table.remote.AsyncRemoteTable in project samza by apache.
the class TestAsyncRetriableTable method testPutWithRetryDisabled.
@Test
public void testPutWithRetryDisabled() {
TableRetryPolicy policy = new TableRetryPolicy();
policy.withFixedBackoff(Duration.ofMillis(10));
policy.withStopAfterDelay(Duration.ofMillis(100));
TableReadFunction<String, String> readFn = mock(TableReadFunction.class);
TableWriteFunction<String, String, String> writeFn = mock(TableWriteFunction.class);
doReturn(false).when(writeFn).isRetriable(any());
CompletableFuture<String> future = new CompletableFuture();
future.completeExceptionally(new RuntimeException("test exception"));
doReturn(future).when(writeFn).putAsync(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.putAsync("foo", "bar").join();
fail();
} catch (Throwable t) {
}
verify(writeFn, times(1)).putAsync(any(), any());
assertEquals(0, table.writeRetryMetrics.retryCount.getCount());
assertEquals(0, table.writeRetryMetrics.successCount.getCount());
assertEquals(0, table.writeRetryMetrics.permFailureCount.getCount());
assertEquals(0, table.writeRetryMetrics.retryTimer.getSnapshot().getMax());
}
use of org.apache.samza.table.remote.AsyncRemoteTable in project samza by apache.
the class TestAsyncRetriableTable method testPutUpdateAndDeleteDelegation.
@Test
public void testPutUpdateAndDeleteDelegation() {
TableRetryPolicy policy = new TableRetryPolicy();
policy.withFixedBackoff(Duration.ofMillis(100));
TableReadFunction readFn = mock(TableReadFunction.class);
TableWriteFunction writeFn = mock(TableWriteFunction.class);
doReturn(true).when(writeFn).isRetriable(any());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).putAsync(any(), any());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).putAsync(any(), any(), any());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).putAllAsync(any());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).putAllAsync(any(), any());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).updateAsync(any(), any());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).updateAllAsync(any());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAsync(any());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAsync(any(), any());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAllAsync(any());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAllAsync(any(), any());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).writeAsync(anyInt(), any());
AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, writeFn);
AsyncRetriableTable table = new AsyncRetriableTable("t1", delegate, null, policy, schedExec, readFn, writeFn);
// PutAsync
verify(writeFn, times(0)).putAsync(any(), any());
verify(writeFn, times(0)).putAsync(any(), any(), any());
table.putAsync(1, 2).join();
verify(writeFn, times(1)).putAsync(any(), any());
verify(writeFn, times(0)).putAsync(any(), any(), any());
table.putAsync(1, 2, 3).join();
verify(writeFn, times(1)).putAsync(any(), any());
verify(writeFn, times(1)).putAsync(any(), any(), any());
// PutAllAsync
verify(writeFn, times(0)).putAllAsync(anyCollection());
verify(writeFn, times(0)).putAllAsync(anyCollection(), any());
table.putAllAsync(Arrays.asList(1)).join();
verify(writeFn, times(1)).putAllAsync(anyCollection());
verify(writeFn, times(0)).putAllAsync(anyCollection(), any());
table.putAllAsync(Arrays.asList(1), Arrays.asList(1)).join();
verify(writeFn, times(1)).putAllAsync(anyCollection());
verify(writeFn, times(1)).putAllAsync(anyCollection(), any());
// UpdateAsync
verify(writeFn, times(0)).updateAsync(any(), any());
table.updateAsync(1, 2).join();
verify(writeFn, times(1)).updateAsync(any(), any());
// UpdateAllAsync
verify(writeFn, times(0)).updateAllAsync(anyCollection());
table.updateAllAsync(Arrays.asList(new Entry<>(1, 2))).join();
verify(writeFn, times(1)).updateAllAsync(anyCollection());
// DeleteAsync
verify(writeFn, times(0)).deleteAsync(any());
verify(writeFn, times(0)).deleteAsync(any(), any());
table.deleteAsync(1).join();
verify(writeFn, times(1)).deleteAsync(any());
verify(writeFn, times(0)).deleteAsync(any(), any());
table.deleteAsync(1, 2).join();
verify(writeFn, times(1)).deleteAsync(any());
verify(writeFn, times(1)).deleteAsync(any(), any());
// DeleteAllAsync
verify(writeFn, times(0)).deleteAllAsync(anyCollection());
verify(writeFn, times(0)).deleteAllAsync(anyCollection(), any());
table.deleteAllAsync(Arrays.asList(1)).join();
verify(writeFn, times(1)).deleteAllAsync(anyCollection());
verify(writeFn, times(0)).deleteAllAsync(anyCollection(), any());
table.deleteAllAsync(Arrays.asList(1), Arrays.asList(2)).join();
verify(writeFn, times(1)).deleteAllAsync(anyCollection());
verify(writeFn, times(1)).deleteAllAsync(anyCollection(), any());
// WriteAsync
verify(writeFn, times(0)).writeAsync(anyInt(), any());
table.writeAsync(1, 2).join();
verify(writeFn, times(1)).writeAsync(anyInt(), any());
}
use of org.apache.samza.table.remote.AsyncRemoteTable in project samza by apache.
the class TestAsyncRetriableTable method testPutWithPermFailureOnTimeout.
@Test
public void testPutWithPermFailureOnTimeout() {
TableRetryPolicy policy = new TableRetryPolicy();
policy.withFixedBackoff(Duration.ofMillis(5));
policy.withStopAfterDelay(Duration.ofMillis(100));
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(readFn).getAsync(anyString());
AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, writeFn);
AsyncRetriableTable table = new AsyncRetriableTable("t1", delegate, null, policy, schedExec, readFn, writeFn);
table.init(TestRemoteTable.getMockContext());
try {
table.putAsync("foo", "bar").join();
fail();
} catch (Throwable t) {
}
verify(writeFn, atLeast(3)).putAsync(any(), any());
assertTrue(table.writeRetryMetrics.retryCount.getCount() >= 3);
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.remote.AsyncRemoteTable 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);
}
Aggregations