Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a test driver for a Kafka Streams topology.
Kafka
TopologyTestDriver driver = new TopologyTestDriver(topology, [1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing an undefined variable instead of the configuration properties.
Using incorrect variable names like 'config' or 'settings'.
✗ Incorrect
The TopologyTestDriver requires a Properties object named 'props' that contains the configuration for the test.
2fill in blank
mediumComplete the code to create an input topic for testing.
Kafka
TestInputTopic<String, String> inputTopic = driver.createInputTopic([1], stringSerializer, stringSerializer); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable that is not defined or does not hold the topic name.
Passing the wrong variable like 'inputTopic' which is the output variable.
✗ Incorrect
The method createInputTopic requires the name of the topic as a string variable, commonly named 'topicName'.
3fill in blank
hardFix the error in the code to read output records from the output topic.
Kafka
TestOutputTopic<String, String> outputTopic = driver.createOutputTopic(outputTopicName, stringDeserializer, [1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a serializer instead of a deserializer for output topic.
Using incorrect classes like 'stringEncoder' or 'stringDecoder' which are not Kafka classes.
✗ Incorrect
To read output records, you need to use a deserializer for the value, which is 'stringDeserializer'.
4fill in blank
hardFill both blanks to configure the properties for the test driver.
Kafka
Properties props = new Properties(); props.put(StreamsConfig.APPLICATION_ID_CONFIG, [1]); props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, [2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect bootstrap server addresses.
Using application IDs that are not strings.
✗ Incorrect
The application ID is usually a test name like 'test-app', and the bootstrap servers for local testing is 'localhost:9092'.
5fill in blank
hardFill all three blanks to send a record to the input topic and read from the output topic.
Kafka
inputTopic.pipeInput([1], [2]); KeyValue<String, String> outputRecord = outputTopic.readKeyValue(); assertEquals([3], outputRecord.value);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up input and expected output values.
Using keys or values not matching the test scenario.
✗ Incorrect
You send the key 'key1' and value 'inputValue' to the input topic, then expect 'expectedValue' as the output value.