0
0
Kafkadevops~10 mins

Testing stream topologies in Kafka - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aprops
Bparameters
Csettings
Dconfig
Attempts:
3 left
💡 Hint
Common Mistakes
Passing an undefined variable instead of the configuration properties.
Using incorrect variable names like 'config' or 'settings'.
2fill in blank
medium

Complete 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'
AinputTopicName
BinputTopic
CtopicName
Dinput
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.
3fill in blank
hard

Fix 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'
AstringEncoder
BstringSerializer
CstringDecoder
DstringDeserializer
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.
4fill in blank
hard

Fill 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'
A"test-app"
B"localhost:9092"
C"kafka:9092"
D"app-test"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect bootstrap server addresses.
Using application IDs that are not strings.
5fill in blank
hard

Fill 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'
A"key1"
B"inputValue"
C"expectedValue"
D"outputValue"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up input and expected output values.
Using keys or values not matching the test scenario.