From e570cd892afa9d6cab84229e3f58c3595e6bd6c1 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 15 Dec 2024 09:49:18 +0100 Subject: [PATCH] TEST:start+stop --- .../java/de/juplo/kafka/ExampleConsumerTest.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/test/java/de/juplo/kafka/ExampleConsumerTest.java b/src/test/java/de/juplo/kafka/ExampleConsumerTest.java index 9b787abc..19a91702 100644 --- a/src/test/java/de/juplo/kafka/ExampleConsumerTest.java +++ b/src/test/java/de/juplo/kafka/ExampleConsumerTest.java @@ -6,6 +6,7 @@ import org.apache.kafka.clients.admin.RecordsToDelete; import org.apache.kafka.common.TopicPartition; import org.apache.kafka.common.serialization.LongSerializer; import org.awaitility.Awaitility; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -156,16 +157,29 @@ public class ExampleConsumerTest MockRecordHandler mockHandler; @Autowired AtomicBoolean isTerminatedExceptionally; + @Autowired + ExampleConsumer exampleConsumer; @BeforeEach - void resetTopic() { + void setUp() + { + if (!exampleConsumer.isRunning()) + { + exampleConsumer.start(); + } + } + + @AfterEach + void tearDown() throws InterruptedException + { adminClient.deleteRecords(Map.of( new TopicPartition(TOPIC, 0), deleteAllRecordsByPartition(0), new TopicPartition(TOPIC, 1), deleteAllRecordsByPartition(1))); nextMessage = 1; mockHandler.clear(); isTerminatedExceptionally.set(false); + exampleConsumer.stop(); } private RecordsToDelete deleteAllRecordsByPartition(int x) -- 2.20.1