Tests: Fehlerfall-Test prüft, dass nicht alle Nachrichten gelesen wurden
[demos/kafka/training] / src / test / java / de / juplo / kafka / ApplicationTests.java
index e35b223..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);
@@ -97,19 +99,35 @@ class ApplicationTests
 
        @Test
        @Order(2)
-       void commitsNoOffsetsOnError()
+       void commitsOffsetOfErrorForReprocessingOnError()
        {
                send100Messages(counter ->
                                counter == 77
                                                ? 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());
+
+               checkSeenOffsetsForProgress();
+               compareToCommitedOffsets(newOffsets);
+
+               endlessConsumer.start();
                await("Consumer failed")
                                .atMost(Duration.ofSeconds(30))
                                .until(() -> !endlessConsumer.running());
 
                checkSeenOffsetsForProgress();
-               compareToCommitedOffsets(oldOffsets);
+               compareToCommitedOffsets(newOffsets);
+               assertThat(received.size())
+                               .describedAs("Received not all sent events")
+                               .isLessThan(100);
        }
 
 
@@ -121,7 +139,9 @@ class ApplicationTests
                {
                        Long expected = offsetsToCheck.get(tp) + 1;
                        log.debug("Checking, if the offset for {} is {}", tp, expected);
-                       assertThat(offset).isEqualTo(expected);
+                       assertThat(offset)
+                                       .describedAs("Committed offset corresponds to the offset of the consumer")
+                                       .isEqualTo(expected);
                });
        }
 
@@ -139,7 +159,9 @@ class ApplicationTests
                                withProgress.add(tp);
                        }
                });
-               assertThat(withProgress).isNotEmpty().describedAs("Found no partitions with any offset-progress");
+               assertThat(withProgress)
+                               .describedAs("Some offsets must have changed, compared to the old offset-positions")
+                               .isNotEmpty();
        }
 
 
@@ -234,8 +256,6 @@ class ApplicationTests
                                                properties.getTopic(),
                                                kafkaConsumer,
                                                captureOffsetAndExecuteTestHandler);
-
-               endlessConsumer.start();
        }
 
        @AfterEach