@Override protected void validate() { super.validate(); Preconditions.checkArgument(cache != null, "Must provide a Guava cache instance."); } }
@Override public <K, V> Table<KV<K, V>> getTable(TableDescriptor<K, V, ?> tableDescriptor) { addTableDescriptor(tableDescriptor); BaseTableDescriptor baseTableDescriptor = (BaseTableDescriptor) tableDescriptor; getOrCreateTableSerdes(baseTableDescriptor.getTableId(), baseTableDescriptor.getSerde()); return new TableImpl(baseTableDescriptor.getTableSpec()); }
@Override public Map<String, String> toConfig(Config jobConfig) { Map<String, String> tableConfig = new HashMap<>(super.toConfig(jobConfig)); addTableConfig(GUAVA_CACHE, SerdeUtils.serialize("Guava cache", cache), tableConfig); return Collections.unmodifiableMap(tableConfig); }
@Override public Map<String, String> toConfig(Config jobConfig) { Preconditions.checkNotNull(jobConfig, "Job config is null"); validate(); Map<String, String> tableConfig = new HashMap<>(config); tableConfig.put( String.format(JavaTableConfig.TABLE_PROVIDER_FACTORY, tableId), getProviderFactoryClassName()); return Collections.unmodifiableMap(tableConfig); }
@Override public TaskApplicationDescriptor withTable(TableDescriptor tableDescriptor) { addTableDescriptor(tableDescriptor); BaseTableDescriptor baseTableDescriptor = (BaseTableDescriptor) tableDescriptor; getOrCreateTableSerdes(baseTableDescriptor.getTableId(), baseTableDescriptor.getSerde()); return this; }
/** * Get list of table specs given a list of table descriptors. * @param tableDescs the list of tableDescriptors * @return list of tableSpecs */ static public List<TableSpec> getTableSpecs(List<TableDescriptor> tableDescs) { Map<TableSpec, TableImpl> tableSpecs = new LinkedHashMap<>(); tableDescs.forEach(tableDesc -> { TableSpec tableSpec = ((BaseTableDescriptor) tableDesc).getTableSpec(); if (tableSpecs.containsKey(tableSpec)) { throw new IllegalStateException( String.format("getTable() invoked multiple times with the same tableId: %s", tableDesc.getTableId())); } tableSpecs.put(tableSpec, new TableImpl(tableSpec)); }); return new ArrayList<>(tableSpecs.keySet()); } }
private TableDescriptor createDummyTableDescriptor(String tableId) { BaseTableDescriptor tableDescriptor = mock(BaseTableDescriptor.class); when(tableDescriptor.getTableId()).thenReturn(tableId); return tableDescriptor; }
@Test public void testCustomConfig() { Map<String, String> tableConfig = createTableDescriptor(TABLE_ID) .withConfig("abc", "xyz") .toConfig(new MapConfig()); Assert.assertEquals(2, tableConfig.size()); Assert.assertEquals("xyz", tableConfig.get("abc")); }
@Override protected void generateTableSpecConfig(Map<String, String> tableSpecConfig) { super.generateTableSpecConfig(tableSpecConfig); tableSpecConfig.put(INTERNAL_ENABLE_CHANGELOG, String.valueOf(enableChangelog)); if (enableChangelog) { if (changelogStream != null) { tableSpecConfig.put(INTERNAL_CHANGELOG_STREAM, changelogStream); } if (changelogReplicationFactor != null) { tableSpecConfig.put(INTERNAL_CHANGELOG_REPLICATION_FACTOR, String.valueOf(changelogReplicationFactor)); } } }
private TableSpecJson buildTableJson(TableDescriptor tableDescriptor) { TableSpecJson tableSpecJson = new TableSpecJson(); tableSpecJson.id = tableDescriptor.getTableId(); tableSpecJson.providerFactory = ((BaseTableDescriptor) tableDescriptor).getProviderFactoryClassName(); return tableSpecJson; } }
@Override public TaskApplicationDescriptor withTable(TableDescriptor tableDescriptor) { addTableDescriptor(tableDescriptor); BaseTableDescriptor baseTableDescriptor = (BaseTableDescriptor) tableDescriptor; getOrCreateTableSerdes(baseTableDescriptor.getTableId(), baseTableDescriptor.getSerde()); return this; }
/** * Get list of table specs given a list of table descriptors. * @param tableDescs the list of tableDescriptors * @return list of tableSpecs */ static public List<TableSpec> getTableSpecs(List<TableDescriptor> tableDescs) { Map<TableSpec, TableImpl> tableSpecs = new LinkedHashMap<>(); tableDescs.forEach(tableDesc -> { TableSpec tableSpec = ((BaseTableDescriptor) tableDesc).getTableSpec(); if (tableSpecs.containsKey(tableSpec)) { throw new IllegalStateException( String.format("getTable() invoked multiple times with the same tableId: %s", tableDesc.getTableId())); } tableSpecs.put(tableSpec, new TableImpl(tableSpec)); }); return new ArrayList<>(tableSpecs.keySet()); } }
@Test(expected = IllegalStateException.class) public void testGetTableWithBadId() { Config mockConfig = getConfig(); new StreamApplicationDescriptorImpl(appDesc -> { BaseTableDescriptor mockTableDescriptor = mock(BaseTableDescriptor.class); when(mockTableDescriptor.getTableId()).thenReturn("my.table"); appDesc.getTable(mockTableDescriptor); }, mockConfig); }
@Override protected void generateTableSpecConfig(Map<String, String> tableSpecConfig) { super.generateTableSpecConfig(tableSpecConfig); tableSpecConfig.put(INTERNAL_ENABLE_CHANGELOG, String.valueOf(enableChangelog)); if (enableChangelog) { if (changelogStream != null) { tableSpecConfig.put(INTERNAL_CHANGELOG_STREAM, changelogStream); } if (changelogReplicationFactor != null) { tableSpecConfig.put(INTERNAL_CHANGELOG_REPLICATION_FACTOR, String.valueOf(changelogReplicationFactor)); } } }
@Override public <K, V> Table<KV<K, V>> getTable(TableDescriptor<K, V, ?> tableDescriptor) { addTableDescriptor(tableDescriptor); BaseTableDescriptor baseTableDescriptor = (BaseTableDescriptor) tableDescriptor; getOrCreateTableSerdes(baseTableDescriptor.getTableId(), baseTableDescriptor.getSerde()); return new TableImpl(baseTableDescriptor.getTableSpec()); }
@Override protected void validate() { super.validate(); Preconditions.checkArgument(cache != null, "Must provide a Guava cache instance."); } }
@Override public TaskApplicationDescriptor withTable(TableDescriptor tableDescriptor) { addTableDescriptor(tableDescriptor); BaseTableDescriptor baseTableDescriptor = (BaseTableDescriptor) tableDescriptor; getOrCreateTableSerdes(baseTableDescriptor.getTableId(), baseTableDescriptor.getSerde()); return this; }
/** * Get list of table specs given a list of table descriptors. * @param tableDescs the list of tableDescriptors * @return list of tableSpecs */ static public List<TableSpec> getTableSpecs(List<TableDescriptor> tableDescs) { Map<TableSpec, TableImpl> tableSpecs = new LinkedHashMap<>(); tableDescs.forEach(tableDesc -> { TableSpec tableSpec = ((BaseTableDescriptor) tableDesc).getTableSpec(); if (tableSpecs.containsKey(tableSpec)) { throw new IllegalStateException( String.format("getTable() invoked multiple times with the same tableId: %s", tableDesc.getTableId())); } tableSpecs.put(tableSpec, new TableImpl(tableSpec)); }); return new ArrayList<>(tableSpecs.keySet()); } }
@Test public void testGetTable() throws Exception { Config mockConfig = getConfig(); String tableId = "t1"; BaseTableDescriptor mockTableDescriptor = mock(BaseTableDescriptor.class); when(mockTableDescriptor.getTableId()).thenReturn(tableId); AtomicReference<TableImpl> table = new AtomicReference<>(); StreamApplicationDescriptorImpl streamAppDesc = new StreamApplicationDescriptorImpl(appDesc -> { table.set((TableImpl) appDesc.getTable(mockTableDescriptor)); }, mockConfig); assertEquals(tableId, table.get().getTableId()); }
public Map<String, String> toConfig(Config jobConfig) { Map<String, String> tableConfig = new HashMap<>(super.toConfig(jobConfig));