use of org.apache.samza.table.descriptors.RemoteTableDescriptor in project samza by apache.
the class TestRemoteTableDescriptor method testReadWriteRateLimitToConfig.
@Test
public void testReadWriteRateLimitToConfig() {
Map<String, String> tableConfig = new RemoteTableDescriptor("1").withReadFunction(createMockTableReadFunction()).withReadRetryPolicy(new TableRetryPolicy()).withWriteRateLimit(1000).withReadRateLimit(2000).toConfig(new MapConfig());
Assert.assertEquals(String.valueOf(2000), tableConfig.get("tables.1.io.read.credits"));
Assert.assertEquals(String.valueOf(1000), tableConfig.get("tables.1.io.write.credits"));
}
use of org.apache.samza.table.descriptors.RemoteTableDescriptor in project samza by apache.
the class TestRemoteTableDescriptor method testSerializeNullReadFunction.
@Test(expected = IllegalArgumentException.class)
public void testSerializeNullReadFunction() {
RemoteTableDescriptor desc = new RemoteTableDescriptor("1");
Map<String, String> tableConfig = desc.toConfig(new MapConfig());
Assert.assertTrue(tableConfig.containsKey(RemoteTableDescriptor.READ_FN));
}
use of org.apache.samza.table.descriptors.RemoteTableDescriptor in project samza by apache.
the class TestRemoteTableDescriptor method doTestDeserializeReadFunctionAndLimiter.
private void doTestDeserializeReadFunctionAndLimiter(boolean rateOnly, boolean rlGets, boolean rlPuts) {
int numRateLimitOps = (rlGets ? 1 : 0) + (rlPuts ? 1 : 0);
RemoteTableDescriptor<String, String, String> desc = new RemoteTableDescriptor("1").withReadFunction(createMockTableReadFunction()).withReadRetryPolicy(new TableRetryPolicy().withRetryPredicate((ex) -> false)).withWriteFunction(createMockTableWriteFunction()).withAsyncCallbackExecutorPoolSize(10);
if (rateOnly) {
if (rlGets) {
desc.withReadRateLimit(1000);
} else {
desc.withReadRateLimiterDisabled();
}
if (rlPuts) {
desc.withWriteRateLimit(2000);
} else {
desc.withWriteRateLimiterDisabled();
}
} else {
if (numRateLimitOps > 0) {
Map<String, Integer> tagCredits = new HashMap<>();
if (rlGets) {
tagCredits.put(RemoteTableDescriptor.RL_READ_TAG, 1000);
} else {
desc.withReadRateLimiterDisabled();
}
if (rlPuts) {
tagCredits.put(RemoteTableDescriptor.RL_WRITE_TAG, 2000);
} else {
desc.withWriteRateLimiterDisabled();
}
// Spy the rate limiter to verify call count
RateLimiter rateLimiter = spy(new EmbeddedTaggedRateLimiter(tagCredits));
desc.withRateLimiter(rateLimiter, new CountingCreditFunction(), new CountingCreditFunction());
} else {
desc.withRateLimiterDisabled();
}
}
RemoteTableProvider provider = new RemoteTableProvider(desc.getTableId());
provider.init(createMockContext(desc));
Table table = provider.getTable();
Assert.assertTrue(table instanceof RemoteTable);
RemoteTable rwTable = (RemoteTable) table;
AsyncReadWriteUpdateTable delegate = TestUtils.getFieldValue(rwTable, "asyncTable");
Assert.assertTrue(delegate instanceof AsyncRetriableTable);
if (rlGets || rlPuts) {
delegate = TestUtils.getFieldValue(delegate, "table");
Assert.assertTrue(delegate instanceof AsyncRateLimitedTable);
}
delegate = TestUtils.getFieldValue(delegate, "table");
Assert.assertTrue(delegate instanceof AsyncRemoteTable);
if (numRateLimitOps > 0) {
TableRateLimiter readRateLimiter = TestUtils.getFieldValue(rwTable, "readRateLimiter");
TableRateLimiter writeRateLimiter = TestUtils.getFieldValue(rwTable, "writeRateLimiter");
Assert.assertTrue(!rlGets || readRateLimiter != null);
Assert.assertTrue(!rlPuts || writeRateLimiter != null);
}
ThreadPoolExecutor callbackExecutor = TestUtils.getFieldValue(rwTable, "callbackExecutor");
Assert.assertEquals(10, callbackExecutor.getCorePoolSize());
}
use of org.apache.samza.table.descriptors.RemoteTableDescriptor in project samza by apache.
the class TestRemoteTableDescriptor method testTablePartToConfigDefault.
@Test
public void testTablePartToConfigDefault() {
TableReadFunction readFn = createMockTableReadFunction();
when(readFn.toConfig(any(), any())).thenReturn(createConfigPair(1));
Map<String, String> tableConfig = new RemoteTableDescriptor("1").withReadFunction(readFn).withReadRateLimit(100).toConfig(new MapConfig());
verify(readFn, times(1)).toConfig(any(), any());
Assert.assertEquals("v1", tableConfig.get("tables.1.io.read.func.k1"));
}
use of org.apache.samza.table.descriptors.RemoteTableDescriptor 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");
}
Aggregations