From: Kai Moritz Date: Thu, 26 Sep 2024 12:53:14 +0000 (+0200) Subject: Steuerung und Abfrage über die Actuator-REST-API von ermöglicht X-Git-Tag: producer/spring-producer--fixedsharding--null~6 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=5bfbea8027e3755279e1573b707f592441499509;p=demos%2Fkafka%2Ftraining Steuerung und Abfrage über die Actuator-REST-API von ermöglicht --- diff --git a/pom.xml b/pom.xml index 02707b9..841299b 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,14 @@ + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + org.springframework.boot spring-boot-configuration-processor diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d102dd0..0d5752c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -6,7 +6,31 @@ producer: batch-size: 16384 linger-ms: 0 compression-type: gzip +management: + endpoint: + shutdown: + enabled: true + endpoints: + web: + exposure: + include: "*" + info: + env: + enabled: true + java: + enabled: true +info: + kafka: + bootstrap-server: ${producer.bootstrap-server} + client-id: ${producer.client-id} + topic: ${producer.topic} + acks: ${producer.acks} + batch-size: ${producer.batch-size} + linger-ms: ${producer.linger-ms} + compression-type: ${producer.compression-type} logging: level: root: INFO de.juplo: TRACE +server: + port: 8880 diff --git a/src/test/java/de/juplo/kafka/ApplicationTests.java b/src/test/java/de/juplo/kafka/ApplicationTests.java index 71b9bf6..394007b 100644 --- a/src/test/java/de/juplo/kafka/ApplicationTests.java +++ b/src/test/java/de/juplo/kafka/ApplicationTests.java @@ -5,11 +5,13 @@ import org.apache.kafka.clients.consumer.ConsumerRecord; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.kafka.annotation.KafkaListener; import org.springframework.kafka.test.context.EmbeddedKafka; +import org.springframework.test.web.servlet.MockMvc; import java.time.Duration; import java.util.LinkedList; @@ -18,6 +20,9 @@ import java.util.List; import static de.juplo.kafka.ApplicationTests.PARTITIONS; import static de.juplo.kafka.ApplicationTests.TOPIC; import static org.awaitility.Awaitility.await; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @SpringBootTest( @@ -26,6 +31,7 @@ import static org.awaitility.Awaitility.await; "spring.kafka.consumer.auto-offset-reset=earliest", "producer.bootstrap-server=${spring.embedded.kafka.brokers}", "producer.topic=" + TOPIC}) +@AutoConfigureMockMvc @EmbeddedKafka(topics = TOPIC, partitions = PARTITIONS) @Slf4j public class ApplicationTests @@ -33,6 +39,8 @@ public class ApplicationTests static final String TOPIC = "FOO"; static final int PARTITIONS = 10; + @Autowired + MockMvc mockMvc; @Autowired Consumer consumer; @@ -47,6 +55,12 @@ public class ApplicationTests @Test public void testApplicationStartup() { + await("Application is healthy") + .atMost(Duration.ofSeconds(5)) + .untilAsserted(() -> mockMvc + .perform(get("/actuator/health")) + .andExpect(status().isOk()) + .andExpect(jsonPath("status").value("UP"))); } @Test