use of org.apache.kafka.streams.processor.StateStore in project kafka by apache.
the class AbstractTask method initializeStateStores.
protected void initializeStateStores() {
// set initial offset limits
initializeOffsetLimits();
for (StateStore store : this.topology.stateStores()) {
log.trace("task [{}] Initializing store {}", id(), store.name());
store.init(this.processorContext, store);
}
}
use of org.apache.kafka.streams.processor.StateStore in project kafka by apache.
the class GlobalStateManagerImpl method flush.
public void flush(final InternalProcessorContext context) {
log.debug("Flushing all global stores registered in the state manager");
for (StateStore store : this.stores.values()) {
try {
log.trace("Flushing global store={}", store.name());
store.flush();
} catch (Exception e) {
throw new ProcessorStateException(String.format("Failed to flush global state store %s", store.name()), e);
}
}
}
use of org.apache.kafka.streams.processor.StateStore in project kafka by apache.
the class KStreamBuilderTest method shouldAddGlobalTablesToEachGroup.
@Test
public void shouldAddGlobalTablesToEachGroup() throws Exception {
final String one = "globalTable";
final String two = "globalTable2";
final GlobalKTable<String, String> globalTable = builder.globalTable("table", one);
final GlobalKTable<String, String> globalTable2 = builder.globalTable("table2", two);
builder.table("not-global", "not-global");
final KeyValueMapper<String, String, String> kvMapper = new KeyValueMapper<String, String, String>() {
@Override
public String apply(final String key, final String value) {
return value;
}
};
final KStream<String, String> stream = builder.stream("t1");
stream.leftJoin(globalTable, kvMapper, MockValueJoiner.TOSTRING_JOINER);
final KStream<String, String> stream2 = builder.stream("t2");
stream2.leftJoin(globalTable2, kvMapper, MockValueJoiner.TOSTRING_JOINER);
final Map<Integer, Set<String>> nodeGroups = builder.nodeGroups();
for (Integer groupId : nodeGroups.keySet()) {
final ProcessorTopology topology = builder.build(groupId);
final List<StateStore> stateStores = topology.globalStateStores();
final Set<String> names = new HashSet<>();
for (StateStore stateStore : stateStores) {
names.add(stateStore.name());
}
assertEquals(2, stateStores.size());
assertTrue(names.contains(one));
assertTrue(names.contains(two));
}
}
use of org.apache.kafka.streams.processor.StateStore in project kafka by apache.
the class KStreamBuilderTest method shouldBuildGlobalTopologyWithAllGlobalTables.
@Test
public void shouldBuildGlobalTopologyWithAllGlobalTables() throws Exception {
builder.globalTable("table", "globalTable");
builder.globalTable("table2", "globalTable2");
final ProcessorTopology topology = builder.buildGlobalStateTopology();
final List<StateStore> stateStores = topology.globalStateStores();
final Set<String> sourceTopics = topology.sourceTopics();
assertEquals(Utils.mkSet("table", "table2"), sourceTopics);
assertEquals(2, stateStores.size());
}
use of org.apache.kafka.streams.processor.StateStore in project kafka by apache.
the class KStreamBuilderTest method shouldBuildSimpleGlobalTableTopology.
@Test
public void shouldBuildSimpleGlobalTableTopology() throws Exception {
builder.globalTable("table", "globalTable");
final ProcessorTopology topology = builder.buildGlobalStateTopology();
final List<StateStore> stateStores = topology.globalStateStores();
assertEquals(1, stateStores.size());
assertEquals("globalTable", stateStores.get(0).name());
}
Aggregations