Tests: Tests prüfen den Status des Consumers
authorKai Moritz <kai@juplo.de>
Fri, 15 Apr 2022 11:14:19 +0000 (13:14 +0200)
committerKai Moritz <kai@juplo.de>
Fri, 15 Apr 2022 11:14:19 +0000 (13:14 +0200)
src/test/java/de/juplo/kafka/ApplicationTests.java

index 4cc4f91..35d13cd 100644 (file)
@@ -6,6 +6,7 @@ import org.apache.kafka.clients.consumer.KafkaConsumer;
 import org.apache.kafka.clients.producer.KafkaProducer;
 import org.apache.kafka.clients.producer.ProducerRecord;
 import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.errors.RecordDeserializationException;
 import org.apache.kafka.common.serialization.BytesDeserializer;
 import org.apache.kafka.common.serialization.BytesSerializer;
 import org.apache.kafka.common.serialization.LongSerializer;
@@ -35,6 +36,8 @@ import static de.juplo.kafka.ApplicationTests.PARTITIONS;
 import static de.juplo.kafka.ApplicationTests.TOPIC;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.awaitility.Awaitility.*;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 
 @SpringJUnitConfig(initializers = ConfigDataApplicationContextInitializer.class)
@@ -91,6 +94,11 @@ class ApplicationTests
                                        checkSeenOffsetsForProgress();
                                        compareToCommitedOffsets(newOffsets);
                                });
+
+               assertThrows(
+                               IllegalStateException.class,
+                               () -> endlessConsumer.exitStatus(),
+                               "Consumer should still be running");
        }
 
        @Test
@@ -119,6 +127,13 @@ class ApplicationTests
                assertThat(receivedRecords.size())
                                .describedAs("Received not all sent events")
                                .isLessThan(100);
+
+               assertDoesNotThrow(
+                               () -> endlessConsumer.exitStatus(),
+                               "Consumer should not be running");
+               assertThat(endlessConsumer.exitStatus())
+                               .describedAs("Consumer should have exited abnormally")
+                               .containsInstanceOf(RecordDeserializationException.class);
        }