-
Notifications
You must be signed in to change notification settings - Fork 689
Unit testing Kafka Streams example with TopologyTestDriver #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit testing Kafka Streams example with TopologyTestDriver #144
Conversation
…sion need to be kept in sync manually
Changed non used key type from Object to Bytes to use BytesSerde Added default contructor to support JsonSerde Added toString for better test output
…TopologyTestDriver
|
@jukkakarvanen Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
|
@jukkakarvanen Thank you for signing the Contributor License Agreement! |
|
@jukkakarvanen Thank you very much for this PR. This has been in the backlog for a while but never got to it. This will be very useful for the community. I will review it soon and merge. |
|
@jukkakarvanen I am reviewing the changes now. What do you mean by these statements in the PR description: |
With this I was meaning because now this Stream logic class WordCountProcessorApplication and also the data model class WordCount are internal class of KafkaStreamsWordCountApplication, the reference are more complex if those would be normal classes. See for example lines 52,53,57,77, 78 in WordCountProcessorApplicationTests.java
This was refererring Sprint annotation of @StreamListener(INPUT_TOPIC), @sendto(OUTPUT_TOPIC) Also these methods readOutput and getOutputList are something you end up easily writing with current kafka-streams-test-utils. That's why I am proposing some addition to Kafka project: https://cwiki.apache.org/confluence/display/KAFKA/KIP-456%3A+Helper+classes+to+make+it+simpler+to+write+test+logic+with+TopologyTestDriver |
|
@jukkakarvanen Ok that makes sense. With the current setup, the |
|
@jukkakarvanen Thank you for the PR. Merged upstream after minor polishing. Looking forward to seeing more PR's from you. |
|
@sobychacko, You are welcome.
One improvement idea worth considering: would it be a good idea to add kafka-streams-test-utils as dependence to spring-kafka-test or add separate spring-kafka-streams-test package? Adding spring-kafka-streams-test to drag in kafka-streams-test-utils would be the ideal solution, but when spring-kafka-test is mainly in test scope, so adding dependency to it would not impact to runtime dependencies needed if kafka streams not used. |
|
@garyrussell Is the above ^^ something that we can do with boot dependencies the way we pick up other Kafka dependencies? |
|
Yes, we can add a streams test module to the spring-kafka project; but it will also need a change to initializr to pull it in to test scope when KafkaStreams is selected (like is currently done for s-k-test when kafka is selected). Please open an issue against spring-kafka. |
|
Issue to spring-kafka added. |
Example to Unit Test KafkaStreamsWordCountApplication.WordCountProcessorApplication using TopologyTestDriver. So this is partly related to #110.
This is a better way to unit test stream logic than using EmbeddedKafka. See testing instructions:
https://kafka.apache.org/20/documentation/streams/developer-guide/testing.html
This TopologyTestDriver is now in dependency package org.apache-kafka:kafka-streams-test-utils.
Not seen this referenced in spring-kafka or spring-cloud packages. So now kafka.version property in pom should be kept in sync with spring-kafka-test kafka version.
The type of unused key type changed from Object to Bytes to able to use BytesSerde.
The current example utilization of internal classes causes more complex reference to those classes if those would be normal classes.
I hope someone would invent a way to avoid some of this boilerplate code in this test class example.