From 9d3fa83eb656617162d54a14e1bfcb330fa4ee3a Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 15 Apr 2022 13:14:19 +0200 Subject: [PATCH] =?utf8?q?Tests:=20Tests=20pr=C3=BCfen=20den=20Status=20de?= =?utf8?q?s=20Consumers?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/de/juplo/kafka/ApplicationTests.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/de/juplo/kafka/ApplicationTests.java b/src/test/java/de/juplo/kafka/ApplicationTests.java index 4cc4f91..35d13cd 100644 --- a/src/test/java/de/juplo/kafka/ApplicationTests.java +++ b/src/test/java/de/juplo/kafka/ApplicationTests.java @@ -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); } -- 2.20.1