Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset EmbeddedKafka After Every Test Method

I am writing a test class that has multiple methods that require Kafka. Each one requires different broker properties, so I want a separate instance of EmbeddedKafka for each. Doing

@EmbeddedKafka(
    partitions = 20,
    topics = {"topic"},
    controlledShutdown = false,
    brokerProperties = {
      "listeners=PLAINTEXT://localhost:9091",
      "port=9091",
      "auto.create.topics.enable=false",
      "delete.topic.enable=true"
    })

Uses the broker properties for each method in the class. I don't want this. One way to overcome this would be to put each test method in a separate class with different broker properties. But I don't want to do this, as this would blow up the number of files I need.

Is there some way around this?

like image 573
Prashant Pandey Avatar asked Jun 24 '26 08:06

Prashant Pandey


1 Answers

It's better to use different topics in each test. However, you can add @DirtiesContext to each test method or add @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) to the test class.

like image 162
Gary Russell Avatar answered Jun 27 '26 01:06

Gary Russell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!