/** * Helper method to add a config item to table configuration * @param key key of the config item * @param value value of the config item * @param tableConfig table configuration */ protected void addTableConfig(String key, String value, Map<String, String> tableConfig) { tableConfig.put(JavaTableConfig.buildKey(tableId, key), value); }
/** * Get table config value for a key * @param tableId Id of the table * @param key Key for the config item * @param defaultValue default value if absent in config * @return config value for the key */ public String getForTable(String tableId, String key, String defaultValue) { return get(buildKey(tableId, key), defaultValue); }
private void assertEquals(String expectedValue, String key, String tableId, Map<String, String> config) { String realKey = JavaTableConfig.buildKey(tableId, key); Assert.assertEquals(expectedValue, config.get(realKey)); } }
private void assertEquals(String expectedValue, String key, String tableId, Map<String, String> config) { String realKey = JavaTableConfig.buildKey(tableId, key); Assert.assertEquals(expectedValue, config.get(realKey)); } }
private void assertEquals(String expectedValue, String key, String tableId, Map<String, String> config) { String realKey = JavaTableConfig.buildKey(tableId, key); Assert.assertEquals(expectedValue, config.get(realKey)); } }
private void assertExists(String key, String tableId, Map<String, String> config) { String realKey = JavaTableConfig.buildKey(tableId, key); Assert.assertTrue(config.containsKey(realKey)); }
private void assertExists(String key, String tableId, Map<String, String> config) { String realKey = JavaTableConfig.buildKey(tableId, key); Assert.assertTrue(config.containsKey(realKey)); }
@Test public void testBuildKey() { String key = JavaTableConfig.buildKey("t1", "abc"); Assert.assertEquals("tables.t1.abc", key); }
private void doTestSerialize(RateLimiter rateLimiter, TableRateLimiter.CreditFunction readCredFn, TableRateLimiter.CreditFunction writeCredFn) { String tableId = "1"; RemoteTableDescriptor desc = new RemoteTableDescriptor(tableId) .withReadFunction(createMockTableReadFunction()) .withWriteFunction(createMockTableWriteFunction()); if (rateLimiter != null) { desc.withRateLimiter(rateLimiter, readCredFn, writeCredFn); } 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))); }
@Test public void testGetForTable() { Map<String, String> map = new HashMap<>(); map.put(JavaTableConfig.buildKey("t1", "abc"), "xyz"); JavaTableConfig tableConfig = new JavaTableConfig(new MapConfig(map)); Assert.assertEquals("xyz", tableConfig.getForTable("t1", "abc")); Assert.assertNull(tableConfig.getForTable("t1", "aaa")); Assert.assertEquals("xyz", tableConfig.getForTable("t1", "aaa", "xyz")); Assert.assertNull(tableConfig.getForTable("tt", "abc")); Assert.assertEquals("xyz", tableConfig.getForTable("tt", "abc", "xyz")); } }