Search in sources :

Example 6 with StateStoreSupplier

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"));
}
Also used : TopologyBuilder(org.apache.kafka.streams.processor.TopologyBuilder) ProcessorTopologyTestDriver(org.apache.kafka.test.ProcessorTopologyTestDriver) StateStoreSupplier(org.apache.kafka.streams.processor.StateStoreSupplier) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 7 with StateStoreSupplier

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;
}
Also used : StateStoreSupplier(org.apache.kafka.streams.processor.StateStoreSupplier) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore)

Example 8 with StateStoreSupplier

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"));
}
Also used : StateStoreSupplier(org.apache.kafka.streams.processor.StateStoreSupplier) Test(org.junit.Test)

Aggregations

StateStoreSupplier (org.apache.kafka.streams.processor.StateStoreSupplier)8 Test (org.junit.Test)5 KeyValueStore (org.apache.kafka.streams.state.KeyValueStore)3 GlobalKTableImpl (org.apache.kafka.streams.kstream.internals.GlobalKTableImpl)1 KTableImpl (org.apache.kafka.streams.kstream.internals.KTableImpl)1 KTableSource (org.apache.kafka.streams.kstream.internals.KTableSource)1 TopologyBuilder (org.apache.kafka.streams.processor.TopologyBuilder)1 RocksDBKeyValueStoreSupplier (org.apache.kafka.streams.state.internals.RocksDBKeyValueStoreSupplier)1 ProcessorTopologyTestDriver (org.apache.kafka.test.ProcessorTopologyTestDriver)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1