Search in sources :

Example 6 with ProcessorTopologyTestDriver

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

use of org.apache.kafka.test.ProcessorTopologyTestDriver in project kafka by apache.

the class ProcessorTopologyTest method testDrivingMultiplexByNameTopology.

@Test
public void testDrivingMultiplexByNameTopology() {
    driver = new ProcessorTopologyTestDriver(config, createMultiplexByNameTopology());
    driver.process(INPUT_TOPIC_1, "key1", "value1", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key1", "value1(1)");
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key1", "value1(2)");
    driver.process(INPUT_TOPIC_1, "key2", "value2", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key2", "value2(1)");
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key2", "value2(2)");
    driver.process(INPUT_TOPIC_1, "key3", "value3", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key4", "value4", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key5", "value5", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key3", "value3(1)");
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key4", "value4(1)");
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key5", "value5(1)");
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key3", "value3(2)");
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key4", "value4(2)");
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key5", "value5(2)");
}
Also used : ProcessorTopologyTestDriver(org.apache.kafka.test.ProcessorTopologyTestDriver) Test(org.junit.Test)

Example 8 with ProcessorTopologyTestDriver

use of org.apache.kafka.test.ProcessorTopologyTestDriver in project kafka by apache.

the class ProcessorTopologyTest method testDrivingMultiplexingTopology.

@Test
public void testDrivingMultiplexingTopology() {
    driver = new ProcessorTopologyTestDriver(config, createMultiplexingTopology());
    driver.process(INPUT_TOPIC_1, "key1", "value1", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key1", "value1(1)");
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key1", "value1(2)");
    driver.process(INPUT_TOPIC_1, "key2", "value2", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key2", "value2(1)");
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key2", "value2(2)");
    driver.process(INPUT_TOPIC_1, "key3", "value3", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key4", "value4", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key5", "value5", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key3", "value3(1)");
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key4", "value4(1)");
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key5", "value5(1)");
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key3", "value3(2)");
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key4", "value4(2)");
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key5", "value5(2)");
}
Also used : ProcessorTopologyTestDriver(org.apache.kafka.test.ProcessorTopologyTestDriver) Test(org.junit.Test)

Example 9 with ProcessorTopologyTestDriver

use of org.apache.kafka.test.ProcessorTopologyTestDriver in project kafka by apache.

the class ProcessorTopologyTest method testDrivingForwardToSourceTopology.

@Test
public void testDrivingForwardToSourceTopology() {
    driver = new ProcessorTopologyTestDriver(config, createForwardToSourceTopology());
    driver.process(INPUT_TOPIC_1, "key1", "value1", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key2", "value2", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key3", "value3", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key1", "value1");
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key2", "value2");
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key3", "value3");
}
Also used : ProcessorTopologyTestDriver(org.apache.kafka.test.ProcessorTopologyTestDriver) Test(org.junit.Test)

Example 10 with ProcessorTopologyTestDriver

use of org.apache.kafka.test.ProcessorTopologyTestDriver in project kafka by apache.

the class ProcessorTopologyTest method testDrivingSimpleTopology.

@Test
public void testDrivingSimpleTopology() {
    int partition = 10;
    driver = new ProcessorTopologyTestDriver(config, createSimpleTopology(partition));
    driver.process(INPUT_TOPIC_1, "key1", "value1", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key1", "value1", partition);
    assertNoOutputRecord(OUTPUT_TOPIC_2);
    driver.process(INPUT_TOPIC_1, "key2", "value2", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key2", "value2", partition);
    assertNoOutputRecord(OUTPUT_TOPIC_2);
    driver.process(INPUT_TOPIC_1, "key3", "value3", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key4", "value4", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key5", "value5", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNoOutputRecord(OUTPUT_TOPIC_2);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key3", "value3", partition);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key4", "value4", partition);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key5", "value5", partition);
}
Also used : ProcessorTopologyTestDriver(org.apache.kafka.test.ProcessorTopologyTestDriver) Test(org.junit.Test)

Aggregations

ProcessorTopologyTestDriver (org.apache.kafka.test.ProcessorTopologyTestDriver)10 Test (org.junit.Test)10 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Properties (java.util.Properties)1 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)1 StreamsConfig (org.apache.kafka.streams.StreamsConfig)1 StreamsException (org.apache.kafka.streams.errors.StreamsException)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