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"));
}
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)");
}
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)");
}
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");
}
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);
}
Aggregations