use of org.apache.samza.table.remote.TableWriteFunction in project samza by apache.
the class TestRemoteTableDescriptor method testTablePartToConfig.
@Test
public void testTablePartToConfig() {
int key = 0;
TableReadFunction readFn = createMockTableReadFunction();
when(readFn.toConfig(any(), any())).thenReturn(createConfigPair(key));
TableWriteFunction writeFn = createMockTableWriteFunction();
when(writeFn.toConfig(any(), any())).thenReturn(createConfigPair(key));
RateLimiter rateLimiter = createMockRateLimiter();
when(((TablePart) rateLimiter).toConfig(any(), any())).thenReturn(createConfigPair(key));
CreditFunction readCredFn = createMockCreditFunction();
when(readCredFn.toConfig(any(), any())).thenReturn(createConfigPair(key));
CreditFunction writeCredFn = createMockCreditFunction();
when(writeCredFn.toConfig(any(), any())).thenReturn(createConfigPair(key));
TableRetryPolicy readRetryPolicy = createMockTableRetryPolicy();
when(readRetryPolicy.toConfig(any(), any())).thenReturn(createConfigPair(key));
TableRetryPolicy writeRetryPolicy = createMockTableRetryPolicy();
when(writeRetryPolicy.toConfig(any(), any())).thenReturn(createConfigPair(key));
Map<String, String> tableConfig = new RemoteTableDescriptor("1").withReadFunction(readFn).withWriteFunction(writeFn).withRateLimiter(rateLimiter, readCredFn, writeCredFn).withReadRetryPolicy(readRetryPolicy).withWriteRetryPolicy(writeRetryPolicy).toConfig(new MapConfig());
verify(readFn, times(1)).toConfig(any(), any());
verify(writeFn, times(1)).toConfig(any(), any());
verify((TablePart) rateLimiter, times(1)).toConfig(any(), any());
verify(readCredFn, times(1)).toConfig(any(), any());
verify(writeCredFn, times(1)).toConfig(any(), any());
verify(readRetryPolicy, times(1)).toConfig(any(), any());
verify(writeRetryPolicy, times(1)).toConfig(any(), any());
Assert.assertEquals(tableConfig.get("tables.1.io.read.func.k0"), "v0");
Assert.assertEquals(tableConfig.get("tables.1.io.write.func.k0"), "v0");
Assert.assertEquals(tableConfig.get("tables.1.io.ratelimiter.k0"), "v0");
Assert.assertEquals(tableConfig.get("tables.1.io.read.credit.func.k0"), "v0");
Assert.assertEquals(tableConfig.get("tables.1.io.write.credit.func.k0"), "v0");
Assert.assertEquals(tableConfig.get("tables.1.io.read.retry.policy.k0"), "v0");
Assert.assertEquals(tableConfig.get("tables.1.io.write.retry.policy.k0"), "v0");
}
use of org.apache.samza.table.remote.TableWriteFunction in project samza by apache.
the class TestAsyncRetriableTable method testUpdateWithoutRetry.
@Test
public void testUpdateWithoutRetry() {
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).updateAsync(any(), any());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).updateAllAsync(any());
AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, writeFn);
AsyncRetriableTable table = new AsyncRetriableTable("t1", delegate, null, policy, schedExec, readFn, writeFn);
int times = 0;
table.init(TestRemoteTable.getMockContext());
verify(readFn, times(0)).init(any(), any());
verify(writeFn, times(0)).init(any(), any());
table.updateAsync("foo", "bar").join();
verify(writeFn, times(1)).updateAsync(any(), any());
assertEquals(++times, table.writeRetryMetrics.successCount.getCount());
table.updateAllAsync(Arrays.asList(new Entry<>("1", "2"))).join();
verify(writeFn, times(1)).updateAllAsync(any());
assertEquals(++times, table.writeRetryMetrics.successCount.getCount());
assertEquals(0, table.writeRetryMetrics.retryCount.getCount());
assertEquals(0, table.writeRetryMetrics.retryTimer.getSnapshot().getMax());
assertEquals(0, table.writeRetryMetrics.permFailureCount.getCount());
assertNull(table.readRetryMetrics);
}
use of org.apache.samza.table.remote.TableWriteFunction 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.remote.TableWriteFunction in project samza by apache.
the class TestAsyncRetriableTable method testPutWithoutRetry.
@Test
public void testPutWithoutRetry() {
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).putAllAsync(any());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAsync(any());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAllAsync(any());
AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, writeFn);
AsyncRetriableTable table = new AsyncRetriableTable("t1", delegate, null, policy, schedExec, readFn, writeFn);
int times = 0;
table.init(TestRemoteTable.getMockContext());
verify(readFn, times(0)).init(any(), any());
verify(writeFn, times(0)).init(any(), any());
table.putAsync("foo", "bar").join();
verify(writeFn, times(1)).putAsync(any(), any());
assertEquals(++times, table.writeRetryMetrics.successCount.getCount());
table.putAllAsync(Arrays.asList(new Entry("1", "2"))).join();
verify(writeFn, times(1)).putAllAsync(any());
assertEquals(++times, table.writeRetryMetrics.successCount.getCount());
table.deleteAsync("1").join();
verify(writeFn, times(1)).deleteAsync(any());
assertEquals(++times, table.writeRetryMetrics.successCount.getCount());
table.deleteAllAsync(Arrays.asList("1", "2")).join();
verify(writeFn, times(1)).deleteAllAsync(any());
assertEquals(++times, table.writeRetryMetrics.successCount.getCount());
assertEquals(0, table.writeRetryMetrics.retryCount.getCount());
assertEquals(0, table.writeRetryMetrics.retryTimer.getSnapshot().getMax());
assertEquals(0, table.writeRetryMetrics.permFailureCount.getCount());
assertNull(table.readRetryMetrics);
}
use of org.apache.samza.table.remote.TableWriteFunction 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());
}
Aggregations