From: Kai Moritz Date: Thu, 6 Jun 2024 17:47:52 +0000 (+0200) Subject: counter: 1.2.15 - Fixed race-condition in `CounterApplicationIT` X-Git-Tag: counter-1.2.15~6 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=236aa3a7521bf44e2e397fa7b90373cc3cf59341;p=demos%2Fkafka%2Fwordcount counter: 1.2.15 - Fixed race-condition in `CounterApplicationIT` --- diff --git a/src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java b/src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java index 2f1e0c3..cb0a5b7 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java @@ -73,7 +73,7 @@ public class CounterApplicationIT await("Expected messages") .atMost(Duration.ofSeconds(10)) - .untilAsserted(() -> TestData.assertExpectedMessages(consumer.getReceivedMessages())); + .untilAsserted(() -> consumer.enforceAssertion(TestData.expectedMessagesAssertion())); } @@ -90,9 +90,10 @@ public class CounterApplicationIT received.add(word, counter); } - synchronized MultiValueMap getReceivedMessages() + synchronized void enforceAssertion( + java.util.function.Consumer> assertion) { - return received; + assertion.accept(received); } } diff --git a/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java b/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java index 777537b..8d87793 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java @@ -7,6 +7,7 @@ import org.apache.kafka.streams.KeyValue; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import java.util.function.Consumer; import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; @@ -59,6 +60,11 @@ class TestData return Stream.of(TestData.INPUT_MESSAGES); } + static Consumer> expectedMessagesAssertion() + { + return receivedMessages -> assertExpectedMessages(receivedMessages); + } + static void assertExpectedMessages(MultiValueMap receivedMessages) { expectedMessages().forEach(