use of org.apache.kafka.streams.processor.StateStoreSupplier in project kafka by apache.
the class ProcessorTopologyTest method shouldDriveGlobalStore.
@SuppressWarnings("unchecked")
@Test
public void shouldDriveGlobalStore() throws Exception {
final StateStoreSupplier storeSupplier = Stores.create("my-store").withStringKeys().withStringValues().inMemory().disableLogging().build();
final String global = "global";
final String topic = "topic";
final KeyValueStore<String, String> globalStore = (KeyValueStore<String, String>) storeSupplier.get();
final TopologyBuilder topologyBuilder = this.builder.addGlobalStore(globalStore, global, STRING_DESERIALIZER, STRING_DESERIALIZER, topic, "processor", define(new StatefulProcessor("my-store")));
driver = new ProcessorTopologyTestDriver(config, topologyBuilder);
driver.process(topic, "key1", "value1", STRING_SERIALIZER, STRING_SERIALIZER);
driver.process(topic, "key2", "value2", STRING_SERIALIZER, STRING_SERIALIZER);
assertEquals("value1", globalStore.get("key1"));
assertEquals("value2", globalStore.get("key2"));
}
use of org.apache.kafka.streams.processor.StateStoreSupplier in project kafka by apache.
the class InMemoryLRUCacheStoreTest method createKeyValueStore.
@SuppressWarnings("unchecked")
@Override
protected <K, V> KeyValueStore<K, V> createKeyValueStore(ProcessorContext context, Class<K> keyClass, Class<V> valueClass, boolean useContextSerdes) {
StateStoreSupplier supplier;
if (useContextSerdes) {
supplier = Stores.create("my-store").withKeys(context.keySerde()).withValues(context.valueSerde()).inMemory().maxEntries(10).build();
} else {
supplier = Stores.create("my-store").withKeys(keyClass).withValues(valueClass).inMemory().maxEntries(10).build();
}
KeyValueStore<K, V> store = (KeyValueStore<K, V>) supplier.get();
store.init(context, store);
return store;
}
use of org.apache.kafka.streams.processor.StateStoreSupplier in project kafka by apache.
the class StoresTest method shouldCreateInMemoryStoreSupplierWithLoggedConfig.
@Test
public void shouldCreateInMemoryStoreSupplierWithLoggedConfig() throws Exception {
final StateStoreSupplier supplier = Stores.create("store").withKeys(Serdes.String()).withValues(Serdes.String()).inMemory().enableLogging(Collections.singletonMap("retention.ms", "1000")).build();
final Map<String, String> config = supplier.logConfig();
assertTrue(supplier.loggingEnabled());
assertEquals("1000", config.get("retention.ms"));
}
Aggregations