use of org.apache.samza.table.descriptors.RemoteTableDescriptor in project samza by apache.
the class TestRemoteTableDescriptor method doTestSerialize.
private void doTestSerialize(RateLimiter rateLimiter, CreditFunction readCredFn, CreditFunction writeCredFn) {
String tableId = "1";
RemoteTableDescriptor desc = new RemoteTableDescriptor(tableId).withReadFunction(createMockTableReadFunction()).withWriteFunction(createMockTableWriteFunction());
if (rateLimiter != null) {
desc.withRateLimiter(rateLimiter, readCredFn, writeCredFn);
if (readCredFn == null) {
desc.withReadRateLimiterDisabled();
}
if (writeCredFn == null) {
desc.withWriteRateLimiterDisabled();
}
} else {
desc.withReadRateLimit(100);
desc.withWriteRateLimit(200);
}
Map<String, String> tableConfig = desc.toConfig(new MapConfig());
assertExists(RemoteTableDescriptor.RATE_LIMITER, tableId, tableConfig);
Assert.assertEquals(readCredFn != null, tableConfig.containsKey(JavaTableConfig.buildKey(tableId, RemoteTableDescriptor.READ_CREDIT_FN)));
Assert.assertEquals(writeCredFn != null, tableConfig.containsKey(JavaTableConfig.buildKey(tableId, RemoteTableDescriptor.WRITE_CREDIT_FN)));
}
use of org.apache.samza.table.descriptors.RemoteTableDescriptor in project samza by apache.
the class TestRemoteTableDescriptor method testTableRetryPolicyToConfig.
@Test
public void testTableRetryPolicyToConfig() {
Map<String, String> tableConfig = new RemoteTableDescriptor("1").withReadFunction(createMockTableReadFunction()).withReadRetryPolicy(new TableRetryPolicy()).withRateLimiterDisabled().toConfig(new MapConfig());
Assert.assertEquals(tableConfig.get("tables.1.io.read.retry.policy.TableRetryPolicy"), "{\"exponentialFactor\":0.0,\"backoffType\":\"NONE\",\"retryPredicate\":{}}");
}
use of org.apache.samza.table.descriptors.RemoteTableDescriptor in project samza by apache.
the class TestRemoteTableDescriptor method testValidateOnlyReadOrWriteFn.
@Test
public void testValidateOnlyReadOrWriteFn() {
// Only read defined
String tableId = "1";
RemoteTableDescriptor desc = new RemoteTableDescriptor(tableId).withReadFunction(createMockTableReadFunction()).withReadRateLimiterDisabled();
Map<String, String> tableConfig = desc.toConfig(new MapConfig());
Assert.assertNotNull(tableConfig);
// Only write defined
String tableId2 = "2";
RemoteTableDescriptor desc2 = new RemoteTableDescriptor(tableId2).withWriteFunction(createMockTableWriteFunction()).withWriteRateLimiterDisabled();
tableConfig = desc2.toConfig(new MapConfig());
Assert.assertNotNull(tableConfig);
// Neither read or write defined (Failure case)
String tableId3 = "3";
RemoteTableDescriptor desc3 = new RemoteTableDescriptor(tableId3);
try {
desc3.toConfig(new MapConfig());
Assert.fail("Should not allow neither readFn or writeFn defined");
} catch (Exception e) {
Assert.assertTrue(e instanceof IllegalArgumentException);
Assert.assertTrue(e.getMessage().contains("Must have one of TableReadFunction or TableWriteFunction"));
}
}
use of org.apache.samza.table.descriptors.RemoteTableDescriptor in project samza by apache.
the class TestRemoteTableDescriptor method testSerializeNullWriteFunction.
@Test
public void testSerializeNullWriteFunction() {
String tableId = "1";
RemoteTableDescriptor desc = new RemoteTableDescriptor(tableId).withReadFunction(createMockTableReadFunction()).withRateLimiterDisabled();
Map<String, String> tableConfig = desc.toConfig(new MapConfig());
assertExists(RemoteTableDescriptor.READ_FN, tableId, tableConfig);
assertEquals(null, RemoteTableDescriptor.WRITE_FN, tableId, tableConfig);
}
Aggregations