use of org.apache.samza.table.remote.TablePart in project samza by apache.
the class RemoteTableDescriptor method writeRateLimiterConfig.
// Handle rate limiter
private void writeRateLimiterConfig(Config jobConfig, Map<String, String> tableConfig) {
if (!tagCreditsMap.isEmpty()) {
RateLimiter defaultRateLimiter;
try {
@SuppressWarnings("unchecked") Class<? extends RateLimiter> clazz = (Class<? extends RateLimiter>) Class.forName(DEFAULT_RATE_LIMITER_CLASS_NAME);
Constructor<? extends RateLimiter> ctor = clazz.getConstructor(Map.class);
defaultRateLimiter = ctor.newInstance(tagCreditsMap);
} catch (Exception ex) {
throw new SamzaException("Failed to create default rate limiter", ex);
}
addTableConfig(RATE_LIMITER, SerdeUtils.serialize("rate limiter", defaultRateLimiter), tableConfig);
if (defaultRateLimiter instanceof TablePart) {
addTablePartConfig(RATE_LIMITER, (TablePart) defaultRateLimiter, jobConfig, tableConfig);
}
} else if (rateLimiter != null) {
addTableConfig(RATE_LIMITER, SerdeUtils.serialize("rate limiter", rateLimiter), tableConfig);
if (rateLimiter instanceof TablePart) {
addTablePartConfig(RATE_LIMITER, (TablePart) rateLimiter, jobConfig, tableConfig);
}
}
// Write table api read/write rate limit
if (this.enableReadRateLimiter && tagCreditsMap.containsKey(RL_READ_TAG)) {
addTableConfig(READ_CREDITS, String.valueOf(tagCreditsMap.get(RL_READ_TAG)), tableConfig);
}
if (this.enableWriteRateLimiter && tagCreditsMap.containsKey(RL_WRITE_TAG)) {
addTableConfig(WRITE_CREDITS, String.valueOf(tagCreditsMap.get(RL_WRITE_TAG)), tableConfig);
}
}
use of org.apache.samza.table.remote.TablePart 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