Tests: Umbau für einen Commit im Fehlerfall und Anpassung des Tests deserialization-synchroner-test
authorKai Moritz <kai@juplo.de>
Sun, 10 Apr 2022 12:50:50 +0000 (14:50 +0200)
committerKai Moritz <kai@juplo.de>
Mon, 11 Apr 2022 13:25:37 +0000 (15:25 +0200)
src/main/java/de/juplo/kafka/EndlessConsumer.java
src/test/java/de/juplo/kafka/ApplicationTests.java

index 0a95b2c..b173b12 100644 (file)
@@ -4,6 +4,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.kafka.clients.consumer.*;
 import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.errors.RecordDeserializationException;
 import org.apache.kafka.common.errors.WakeupException;
 
 import javax.annotation.PreDestroy;
@@ -128,6 +129,20 @@ public class EndlessConsumer<K, V> implements Runnable
       consumer.commitSync();
       shutdown();
     }
+    catch(RecordDeserializationException e)
+    {
+      TopicPartition tp = e.topicPartition();
+      long offset = e.offset();
+      log.error(
+          "{} - Could not deserialize  message on topic {} with offset={}: {}",
+          id,
+          tp,
+          offset,
+          e.getCause().toString());
+
+      consumer.commitSync();
+      shutdown(e);
+    }
     catch(Exception e)
     {
       log.error("{} - Unexpected error: {}", id, e.toString(), e);
index 6aaff52..17d8431 100644 (file)
@@ -87,7 +87,7 @@ class ApplicationTests
 
        @Test
        @Order(2)
-       void commitsNoOffsetsOnError()
+       void commitsOffsetOfErrorForReprocessingOnError()
        {
                send100Messages(counter ->
                                counter == 77
@@ -97,7 +97,7 @@ class ApplicationTests
                runEndlessConsumer((record) -> {});
 
                checkSeenOffsetsForProgress();
-               compareToCommitedOffsets(oldOffsets);
+               compareToCommitedOffsets(newOffsets);
        }