use of org.apache.samza.table.AsyncReadWriteUpdateTable in project samza by apache.
the class TestAsyncRetriableTable method testGetWithPermFailureOnTimeout.
@Test
public void testGetWithPermFailureOnTimeout() {
TableRetryPolicy policy = new TableRetryPolicy();
policy.withFixedBackoff(Duration.ofMillis(5));
policy.withStopAfterDelay(Duration.ofMillis(100));
TableReadFunction<String, String> readFn = mock(TableReadFunction.class);
doReturn(true).when(readFn).isRetriable(any());
CompletableFuture<String> future = new CompletableFuture();
future.completeExceptionally(new RuntimeException("test exception"));
doReturn(future).when(readFn).getAsync(anyString());
AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, null);
AsyncRetriableTable table = new AsyncRetriableTable("t1", delegate, policy, null, schedExec, readFn, null);
table.init(TestRemoteTable.getMockContext());
try {
table.getAsync("foo").join();
fail();
} catch (Throwable t) {
}
verify(readFn, atLeast(3)).getAsync(any());
assertTrue(table.readRetryMetrics.retryCount.getCount() >= 3);
assertEquals(0, table.readRetryMetrics.successCount.getCount());
assertEquals(1, table.readRetryMetrics.permFailureCount.getCount());
assertTrue(table.readRetryMetrics.retryTimer.getSnapshot().getMax() > 0);
}
use of org.apache.samza.table.AsyncReadWriteUpdateTable in project samza by apache.
the class TestAsyncRetriableTable method testFlushAndClose.
@Test
public void testFlushAndClose() {
TableRetryPolicy policy = new TableRetryPolicy();
policy.withFixedBackoff(Duration.ofMillis(100));
TableReadFunction readFn = mock(TableReadFunction.class);
TableWriteFunction writeFn = mock(TableWriteFunction.class);
AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, writeFn);
AsyncRetriableTable table = new AsyncRetriableTable("t1", delegate, null, policy, schedExec, readFn, writeFn);
table.flush();
verify(writeFn, times(1)).flush();
table.close();
verify(readFn, times(1)).close();
verify(writeFn, times(1)).close();
}
use of org.apache.samza.table.AsyncReadWriteUpdateTable in project samza by apache.
the class TestAsyncRateLimitedTable method testFlushAndClose.
@Test
public void testFlushAndClose() {
TableRateLimiter readRateLimiter = mock(TableRateLimiter.class);
TableRateLimiter writeRateLimiter = mock(TableRateLimiter.class);
TableReadFunction<String, String> readFn = mock(TableReadFunction.class);
TableWriteFunction<String, String, String> writeFn = mock(TableWriteFunction.class);
AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, writeFn);
AsyncRateLimitedTable table = new AsyncRateLimitedTable("t1", delegate, readRateLimiter, writeRateLimiter, writeRateLimiter, schedExec);
table.init(TestRemoteTable.getMockContext());
table.flush();
verify(writeFn, times(1)).flush();
table.close();
verify(readFn, times(1)).close();
verify(writeFn, times(1)).close();
}
use of org.apache.samza.table.AsyncReadWriteUpdateTable in project samza by apache.
the class TestAsyncRateLimitedTable method prepare.
@Before
public void prepare() {
// Read part
readRateLimiter = mock(TableRateLimiter.class);
readFn = mock(TableReadFunction.class);
doReturn(CompletableFuture.completedFuture("bar")).when(readFn).getAsync(any());
doReturn(CompletableFuture.completedFuture("bar")).when(readFn).getAsync(any(), any());
readMap.put("foo", "bar");
doReturn(CompletableFuture.completedFuture(readMap)).when(readFn).getAllAsync(any());
doReturn(CompletableFuture.completedFuture(readMap)).when(readFn).getAllAsync(any(), any());
doReturn(CompletableFuture.completedFuture(5)).when(readFn).readAsync(anyInt(), any());
AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, null);
readTable = new AsyncRateLimitedTable("t1", delegate, readRateLimiter, null, null, schedExec);
readTable.init(TestRemoteTable.getMockContext());
// Write part
writeRateLimiter = mock(TableRateLimiter.class);
writeFn = mock(TableWriteFunction.class);
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).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(5)).when(writeFn).writeAsync(anyInt(), any());
// update part
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).updateAsync(any(), any());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).updateAllAsync(any());
delegate = new AsyncRemoteTable(readFn, writeFn);
writeTable = new AsyncRateLimitedTable("t1", delegate, readRateLimiter, writeRateLimiter, writeRateLimiter, schedExec);
writeTable.init(TestRemoteTable.getMockContext());
}
use of org.apache.samza.table.AsyncReadWriteUpdateTable in project samza by apache.
the class TestRemoteTable method testInit.
@Test
public void testInit() {
String tableId = "testInit";
TableReadFunction<String, String> readFn = mock(TableReadFunction.class);
TableWriteFunction<String, String, String> writeFn = mock(TableWriteFunction.class);
RemoteTable<String, String, String> table = getTable(tableId, readFn, writeFn, true);
// AsyncRetriableTable
AsyncReadWriteUpdateTable innerTable = TestUtils.getFieldValue(table, "asyncTable");
Assert.assertTrue(innerTable instanceof AsyncRetriableTable);
Assert.assertNotNull(TestUtils.getFieldValue(innerTable, "readRetryMetrics"));
Assert.assertNotNull(TestUtils.getFieldValue(innerTable, "writeRetryMetrics"));
// AsyncRateLimitedTable
innerTable = TestUtils.getFieldValue(innerTable, "table");
Assert.assertTrue(innerTable instanceof AsyncRateLimitedTable);
// AsyncRemoteTable
innerTable = TestUtils.getFieldValue(innerTable, "table");
Assert.assertTrue(innerTable instanceof AsyncRemoteTable);
// Verify table functions are initialized
verify(readFn, times(1)).init(any(), any());
verify(writeFn, times(1)).init(any(), any());
}
Aggregations