@Override public Map<String, String> toConfig(Config jobConfig) { Map<String, String> tableConfig = new HashMap<>(super.toConfig(jobConfig)); if (cache != null) { addTableConfig(CACHE_TABLE_ID, cache.getTableId(), tableConfig); } else { if (readTtl != null) { addTableConfig(READ_TTL_MS, String.valueOf(readTtl.toMillis()), tableConfig); } if (writeTtl != null) { addTableConfig(WRITE_TTL_MS, String.valueOf(writeTtl.toMillis()), tableConfig); } if (cacheSize > 0) { addTableConfig(CACHE_SIZE, String.valueOf(cacheSize), tableConfig); } } addTableConfig(REAL_TABLE_ID, table.getTableId(), tableConfig); addTableConfig(WRITE_AROUND, String.valueOf(isWriteAround), tableConfig); return Collections.unmodifiableMap(tableConfig); }
private void doTestSerialize(TableDescriptor cache) { CachingTableDescriptor desc; TableDescriptor table = createDummyTableDescriptor("2"); if (cache == null) { desc = new CachingTableDescriptor("1", table) .withReadTtl(Duration.ofMinutes(3)) .withWriteTtl(Duration.ofMinutes(4)) .withCacheSize(1000); } else { desc = new CachingTableDescriptor("1", table, cache); } desc.withWriteAround(); Map<String, String> tableConfig = desc.toConfig(new MapConfig()); assertEquals("2", CachingTableDescriptor.REAL_TABLE_ID, "1", tableConfig); if (cache == null) { assertEquals("180000", CachingTableDescriptor.READ_TTL_MS, "1", tableConfig); assertEquals("240000", CachingTableDescriptor.WRITE_TTL_MS, "1", tableConfig); } else { assertEquals(cache.getTableId(), CachingTableDescriptor.CACHE_TABLE_ID, "1", tableConfig); } assertEquals("true", CachingTableDescriptor.WRITE_AROUND, "1", tableConfig); }
private void doTestCacheOps(boolean isWriteAround) { CachingTableDescriptor desc = new CachingTableDescriptor("1", createDummyTableDescriptor("realTable"), createDummyTableDescriptor("cacheTable")); if (isWriteAround) { desc.withWriteAround(); Map<String, String> tableConfig = desc.toConfig(new MapConfig()); when(context.getJobContext().getConfig()).thenReturn(new MapConfig(tableConfig)); CachingTableProvider tableProvider = new CachingTableProvider(desc.getTableId()); tableProvider.init(context);