Search in sources :

Example 11 with StateStoreSupplier

use of org.apache.kafka.streams.processor.StateStoreSupplier in project apache-kafka-on-k8s by banzaicloud.

the class InternalTopologyBuilderTest method testAddStateStore.

@SuppressWarnings("deprecation")
@Test
public void testAddStateStore() {
    final StateStoreSupplier supplier = new MockStateStoreSupplier("store-1", false);
    builder.addStateStore(supplier);
    builder.setApplicationId("X");
    builder.addSource(null, "source-1", null, null, null, "topic-1");
    builder.addProcessor("processor-1", new MockProcessorSupplier(), "source-1");
    assertEquals(0, builder.build(null).stateStores().size());
    builder.connectProcessorAndStateStores("processor-1", "store-1");
    final List<StateStore> suppliers = builder.build(null).stateStores();
    assertEquals(1, suppliers.size());
    assertEquals(supplier.name(), suppliers.get(0).name());
}
Also used : MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) StateStoreSupplier(org.apache.kafka.streams.processor.StateStoreSupplier) MockStateStoreSupplier(org.apache.kafka.test.MockStateStoreSupplier) StateStore(org.apache.kafka.streams.processor.StateStore) MockStateStoreSupplier(org.apache.kafka.test.MockStateStoreSupplier) Test(org.junit.Test)

Example 12 with StateStoreSupplier

use of org.apache.kafka.streams.processor.StateStoreSupplier in project apache-kafka-on-k8s by banzaicloud.

the class StoresTest method shouldCreateInMemoryStoreSupplierNotLogged.

@SuppressWarnings("deprecation")
@Test
public void shouldCreateInMemoryStoreSupplierNotLogged() {
    final StateStoreSupplier supplier = Stores.create("store").withKeys(Serdes.String()).withValues(Serdes.String()).inMemory().disableLogging().build();
    assertFalse(supplier.loggingEnabled());
}
Also used : StateStoreSupplier(org.apache.kafka.streams.processor.StateStoreSupplier) Test(org.junit.Test)

Example 13 with StateStoreSupplier

use of org.apache.kafka.streams.processor.StateStoreSupplier in project apache-kafka-on-k8s by banzaicloud.

the class StoresTest method shouldCreateInMemoryStoreSupplierWithLoggedConfig.

@SuppressWarnings("deprecation")
@Test
public void shouldCreateInMemoryStoreSupplierWithLoggedConfig() {
    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)

Example 14 with StateStoreSupplier

use of org.apache.kafka.streams.processor.StateStoreSupplier in project apache-kafka-on-k8s by banzaicloud.

the class StoresTest method shouldCreatePersistenStoreSupplierWithLoggedConfig.

@SuppressWarnings("deprecation")
@Test
public void shouldCreatePersistenStoreSupplierWithLoggedConfig() {
    final StateStoreSupplier supplier = Stores.create("store").withKeys(Serdes.String()).withValues(Serdes.String()).persistent().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)

Example 15 with StateStoreSupplier

use of org.apache.kafka.streams.processor.StateStoreSupplier in project apache-kafka-on-k8s by banzaicloud.

the class ProcessorTopologyTest method shouldDriveGlobalStore.

@SuppressWarnings("unchecked")
@Test
public void shouldDriveGlobalStore() {
    final String storeName = "my-store";
    final StateStoreSupplier storeSupplier = Stores.create(storeName).withStringKeys().withStringValues().inMemory().disableLogging().build();
    final String global = "global";
    final String topic = "topic";
    final TopologyBuilder topologyBuilder = this.builder.addGlobalStore(storeSupplier, global, STRING_DESERIALIZER, STRING_DESERIALIZER, topic, "processor", define(new StatefulProcessor(storeName)));
    driver = new ProcessorTopologyTestDriver(config, topologyBuilder.internalTopologyBuilder);
    final KeyValueStore<String, String> globalStore = (KeyValueStore<String, String>) topologyBuilder.globalStateStores().get(storeName);
    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)

Aggregations

StateStoreSupplier (org.apache.kafka.streams.processor.StateStoreSupplier)15 Test (org.junit.Test)11 KeyValueStore (org.apache.kafka.streams.state.KeyValueStore)3 TopologyBuilder (org.apache.kafka.streams.processor.TopologyBuilder)2 MockProcessorSupplier (org.apache.kafka.test.MockProcessorSupplier)2 MockStateStoreSupplier (org.apache.kafka.test.MockStateStoreSupplier)2 HashMap (java.util.HashMap)1 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)1 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 StateStore (org.apache.kafka.streams.processor.StateStore)1 RocksDBKeyValueStoreSupplier (org.apache.kafka.streams.state.internals.RocksDBKeyValueStoreSupplier)1 ProcessorTopologyTestDriver (org.apache.kafka.test.ProcessorTopologyTestDriver)1 IterativeJoin (org.apache.rya.api.function.join.IterativeJoin)1 LeftOuterJoin (org.apache.rya.api.function.join.LeftOuterJoin)1 NaturalJoin (org.apache.rya.api.function.join.NaturalJoin)1 VisibilityBindingSetSerde (org.apache.rya.streams.kafka.serialization.VisibilityBindingSetSerde)1 VisibilityStatementDeserializer (org.apache.rya.streams.kafka.serialization.VisibilityStatementDeserializer)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1