counter: 1.2.15 - Fixed race-condition in `CounterApplicationIT`
authorKai Moritz <kai@juplo.de>
Thu, 6 Jun 2024 17:47:52 +0000 (19:47 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 8 Jun 2024 11:33:30 +0000 (13:33 +0200)
src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java
src/test/java/de/juplo/kafka/wordcount/counter/TestData.java

index 2f1e0c3..cb0a5b7 100644 (file)
@@ -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<TestOutputWord, TestOutputWordCounter> getReceivedMessages()
+               synchronized void enforceAssertion(
+                               java.util.function.Consumer<MultiValueMap<TestOutputWord, TestOutputWordCounter>> assertion)
                {
-                       return received;
+                       assertion.accept(received);
                }
        }
 
index 777537b..8d87793 100644 (file)
@@ -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<MultiValueMap<TestOutputWord, TestOutputWordCounter>> expectedMessagesAssertion()
+       {
+               return receivedMessages -> assertExpectedMessages(receivedMessages);
+       }
+
        static void assertExpectedMessages(MultiValueMap<TestOutputWord, TestOutputWordCounter> receivedMessages)
        {
                expectedMessages().forEach(