Search in sources :

Example 16 with ProcessorTopologyTestDriver

use of org.apache.kafka.test.ProcessorTopologyTestDriver 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)

Example 17 with ProcessorTopologyTestDriver

use of org.apache.kafka.test.ProcessorTopologyTestDriver in project apache-kafka-on-k8s by banzaicloud.

the class ProcessorTopologyTest method shouldConsiderModifiedTimeStamps.

@Test
public void shouldConsiderModifiedTimeStamps() {
    final int partition = 10;
    driver = new ProcessorTopologyTestDriver(config, createTimestampTopology(partition).internalTopologyBuilder);
    driver.process(INPUT_TOPIC_1, "key1", "value1", STRING_SERIALIZER, STRING_SERIALIZER, 10L);
    driver.process(INPUT_TOPIC_1, "key2", "value2", STRING_SERIALIZER, STRING_SERIALIZER, 20L);
    driver.process(INPUT_TOPIC_1, "key3", "value3", STRING_SERIALIZER, STRING_SERIALIZER, 30L);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key1", "value1", partition, 20L);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key2", "value2", partition, 30L);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key3", "value3", partition, 40L);
}
Also used : ProcessorTopologyTestDriver(org.apache.kafka.test.ProcessorTopologyTestDriver) Test(org.junit.Test)

Aggregations

ProcessorTopologyTestDriver (org.apache.kafka.test.ProcessorTopologyTestDriver)17 Test (org.junit.Test)17 Properties (java.util.Properties)4 StreamsException (org.apache.kafka.streams.errors.StreamsException)4 StreamsConfig (org.apache.kafka.streams.StreamsConfig)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)1 TopologyBuilderException (org.apache.kafka.streams.errors.TopologyBuilderException)1 StateStoreSupplier (org.apache.kafka.streams.processor.StateStoreSupplier)1 TopologyBuilder (org.apache.kafka.streams.processor.TopologyBuilder)1 KeyValueStore (org.apache.kafka.streams.state.KeyValueStore)1 MockStateStore (org.apache.kafka.test.MockStateStore)1