Steuerung und Abfrage über die Actuator-REST-API von ermöglicht
authorKai Moritz <kai@juplo.de>
Thu, 26 Sep 2024 12:53:14 +0000 (14:53 +0200)
committerKai Moritz <kai@juplo.de>
Fri, 8 Nov 2024 17:05:08 +0000 (18:05 +0100)
pom.xml
src/main/resources/application.yml
src/test/java/de/juplo/kafka/ApplicationTests.java

diff --git a/pom.xml b/pom.xml
index 02707b9..841299b 100644 (file)
--- a/pom.xml
+++ b/pom.xml
   </properties>
 
   <dependencies>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter-web</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter-actuator</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-configuration-processor</artifactId>
index a019c27..ce70629 100644 (file)
@@ -6,7 +6,31 @@ producer:
   batch-size: 16384
   linger: 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: ${producer.linger}
+    compression-type: ${producer.compression-type}
 logging:
   level:
     root: INFO
     de.juplo: TRACE
+server:
+  port: 8880
index 71b9bf6..394007b 100644 (file)
@@ -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