Tests: Fehlerfall-Test prüft, dass nicht alle Nachrichten gelesen wurden
authorKai Moritz <kai@juplo.de>
Fri, 15 Apr 2022 10:17:23 +0000 (12:17 +0200)
committerKai Moritz <kai@juplo.de>
Fri, 15 Apr 2022 10:19:45 +0000 (12:19 +0200)
src/test/java/de/juplo/kafka/ApplicationTests.java

index f541093..61e0a8d 100644 (file)
@@ -82,6 +82,8 @@ class ApplicationTests
                Set<ConsumerRecord<String, Long>> received = new HashSet<>();
                testHandler = record -> received.add(record);
 
+               endlessConsumer.start();
+
                await("100 records received")
                                .atMost(Duration.ofSeconds(30))
                                .until(() -> received.size() >= 100);
@@ -104,6 +106,11 @@ class ApplicationTests
                                                ? new Bytes(stringSerializer.serialize(TOPIC, "BOOM!"))
                                                : new Bytes(longSerializer.serialize(TOPIC, counter)));
 
+               Set<ConsumerRecord<String, Long>> received = new HashSet<>();
+               testHandler = record -> received.add(record);
+
+               endlessConsumer.start();
+
                await("Consumer failed")
                                .atMost(Duration.ofSeconds(30))
                                .until(() -> !endlessConsumer.running());
@@ -118,6 +125,9 @@ class ApplicationTests
 
                checkSeenOffsetsForProgress();
                compareToCommitedOffsets(newOffsets);
+               assertThat(received.size())
+                               .describedAs("Received not all sent events")
+                               .isLessThan(100);
        }
 
 
@@ -246,8 +256,6 @@ class ApplicationTests
                                                properties.getTopic(),
                                                kafkaConsumer,
                                                captureOffsetAndExecuteTestHandler);
-
-               endlessConsumer.start();
        }
 
        @AfterEach