Given the following Kafka Streams topology test code snippet, what will be the output printed by the test?
TopologyTestDriver driver = new TopologyTestDriver(topology, props); TestInputTopic<String, String> inputTopic = driver.createInputTopic("input-topic", Serdes.String().serializer(), Serdes.String().serializer()); TestOutputTopic<String, String> outputTopic = driver.createOutputTopic("output-topic", Serdes.String().deserializer(), Serdes.String().deserializer()); inputTopic.pipeInput("key1", "value1"); inputTopic.pipeInput("key2", "value2"); List<KeyValue<String, String>> results = outputTopic.readKeyValuesToList(); System.out.println(results);
Consider if the topology transforms input values to uppercase before output.
The topology converts input values to uppercase before forwarding them to the output topic. Hence, the output values are uppercase.
In Kafka Streams testing, which component allows you to simulate sending records into the topology?
Think about the component that feeds data into the topology during tests.
TestInputTopic is used to simulate input records into the topology for testing purposes.
Consider this test snippet:
TopologyTestDriver driver = new TopologyTestDriver(topology, props); TestInputTopicinputTopic = driver.createInputTopic("input", Serdes.String().serializer(), Serdes.Integer().serializer()); inputTopic.pipeInput("key", 123); TestOutputTopic outputTopic = driver.createOutputTopic("output", Serdes.String().deserializer(), Serdes.String().deserializer()); List > results = outputTopic.readKeyValuesToList();
Why does this test throw a SerializationException?
Check if the output deserializer matches the output data type.
The output topic expects String values but the topology outputs Integer values, causing a SerializationException during deserialization.
Which of the following code snippets correctly creates a TopologyTestDriver with the required properties?
Check the type of properties and constructor parameters.
TopologyTestDriver requires a Properties object with required configs passed to its constructor.
Given this topology test code:
TopologyTestDriver driver = new TopologyTestDriver(topology, props); TestInputTopicinput = driver.createInputTopic("input", Serdes.String().serializer(), Serdes.String().serializer()); TestOutputTopic output = driver.createOutputTopic("output", Serdes.String().deserializer(), Serdes.String().deserializer()); input.pipeInput("k1", "v1"); input.pipeInput("k2", "v2"); input.pipeInput("k1", "v3"); List > results = output.readKeyValuesToList(); // The topology filters out records where value contains '3'
How many records will results contain?
Remember the filter removes records with '3' in the value.
The input has 3 records but the one with value 'v3' is filtered out, so only 2 records remain in output.