Reputation: 1148
I am trying to setup a Kafka environment. I already have implemented a Kafka producer and consumer in my code.
Is there a Kafka test client I can use to test this setup? Basically, what I want is this:
my code publishes some event.
test client gets it.
my test client publishes some event.
My code gets it.
IS there a Kafka test client that can be used to do the above? I tried searching the Kafka website and found nothing.
Upvotes: 0
Views: 1427
Reputation: 1
Cucumblan-message library contains predefined Gherkin step definition for Kafka message/event testing.
No need to create any consumer or producer and this framework will take care. This code base will help to test any Kafka messages.
Refer the following code based from your sample:
https://tutorials.virtualan.io/#/Cucumblan-message
Need to implement simple class JSON based consumer class for read message and validate the message.
Scenario: check produce and consume event validation 1
Given Send inline message pets for event MOCK_REQUEST on pet with type JSON
| { "category": { "id": 100, "name": "Fish-POST" }, "id": 100, "name": "GoldFish-POST", "photoUrls": [ "/fish/" ], "status": "available", "tags": [ { "id": 100, "name": "Fish-POST" } ] } |
And Pause message PROCESSING for process for 2000 milliseconds
When Verify-by-elements for pets for event MOCK_RESPONSE contains 101 on pet with type JSON
| id | i~101 |
| category.name | german shepherd |
Then Verify for pets for event MOCK_RESPONSE contains 101 on pet with type JSON
| id,name, category/id:name,status |
| i~101,Rocky,i~100:german shepherd,available |
And Verify for pets for event MOCK_RESPONSE contains 101 on pet with type JSON
| id,name, category/id:name,tags/id:name,status,photoUrls |
| i~101,Rocky,i~100:german shepherd,i~101:brown\|,available,string\| |
Upvotes: 0
Reputation: 191711
The Java API comes with MockConsumer and MockProducer for unit testing, as well as TopologyTestDriver for Kafka Streams.
If you want integration testing with a real broker, you can use testcontainers (i.e. Docker), or use spring-test-kafka (Spring not required)
Upvotes: 1