From f8ba656f22218deffb43394ee5416bdc23ddd0fd Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Mon, 8 Aug 2022 11:40:49 +0200 Subject: [PATCH] Add actuator-webflux-mgmt-port smoke test Closes gh-8 --- actuator-webflux-mgmt-port/README.adoc | 1 + actuator-webflux-mgmt-port/build.gradle | 21 ++++++ ...torWebFluxMgmtPortApplicationAotTests.java | 66 +++++++++++++++++++ .../ActuatorWebFluxMgmtPortApplication.java | 27 ++++++++ .../src/main/resources/application.properties | 9 +++ ...tuatorWebFluxMgmtPortApplicationTests.java | 14 ++++ ci/smoke-tests.yml | 1 + settings.gradle | 1 + 8 files changed, 140 insertions(+) create mode 100644 actuator-webflux-mgmt-port/README.adoc create mode 100644 actuator-webflux-mgmt-port/build.gradle create mode 100644 actuator-webflux-mgmt-port/src/aotTest/java/com/example/actuator/webflux/mgmtport/ActuatorWebFluxMgmtPortApplicationAotTests.java create mode 100644 actuator-webflux-mgmt-port/src/main/java/com/example/actuator/webflux/mgmtport/ActuatorWebFluxMgmtPortApplication.java create mode 100644 actuator-webflux-mgmt-port/src/main/resources/application.properties create mode 100644 actuator-webflux-mgmt-port/src/test/java/com/example/actuator/webflux/mgmtport/ActuatorWebFluxMgmtPortApplicationTests.java diff --git a/actuator-webflux-mgmt-port/README.adoc b/actuator-webflux-mgmt-port/README.adoc new file mode 100644 index 00000000..6060db4a --- /dev/null +++ b/actuator-webflux-mgmt-port/README.adoc @@ -0,0 +1 @@ +Tests the Spring Boot Actuator with dedicated management port on WebFlux. diff --git a/actuator-webflux-mgmt-port/build.gradle b/actuator-webflux-mgmt-port/build.gradle new file mode 100644 index 00000000..8e50e5bf --- /dev/null +++ b/actuator-webflux-mgmt-port/build.gradle @@ -0,0 +1,21 @@ +plugins { + id 'java' + id 'org.springframework.boot' + id 'org.springframework.aot.smoke-test' + id 'org.graalvm.buildtools.native' +} + +dependencies { + implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) + implementation("org.springframework.boot:spring-boot-starter-actuator") + implementation("org.springframework.boot:spring-boot-starter-webflux") + implementation(project(":aot-smoke-test-third-party-hints")) + + testImplementation("org.springframework.boot:spring-boot-starter-test") + + aotTestImplementation(project(":aot-smoke-test-support")) +} + +aotSmokeTest { + webApplication = true +} diff --git a/actuator-webflux-mgmt-port/src/aotTest/java/com/example/actuator/webflux/mgmtport/ActuatorWebFluxMgmtPortApplicationAotTests.java b/actuator-webflux-mgmt-port/src/aotTest/java/com/example/actuator/webflux/mgmtport/ActuatorWebFluxMgmtPortApplicationAotTests.java new file mode 100644 index 00000000..e799a5bd --- /dev/null +++ b/actuator-webflux-mgmt-port/src/aotTest/java/com/example/actuator/webflux/mgmtport/ActuatorWebFluxMgmtPortApplicationAotTests.java @@ -0,0 +1,66 @@ +package com.example.actuator.webflux.mgmtport; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import org.springframework.aot.smoketest.support.Output; +import org.springframework.aot.smoketest.support.junit.AotSmokeTest; +import org.springframework.test.web.reactive.server.WebTestClient; + +@AotSmokeTest +class ActuatorWebFluxMgmtPortApplicationAotTests { + + private static final Pattern MANAGEMENT_PORT_REGEX = Pattern.compile("^Management port: (\\d+)$"); + + private static WebTestClient client; + + @BeforeAll + static void beforeAll() { + client = buildManagementClient(); + } + + @Test + void shouldContainLinks() { + client.get().uri("/actuator").exchange().expectStatus().isOk().expectBody().jsonPath("$._links.self.templated") + .isEqualTo(false).jsonPath("$._links.env-toMatch.templated").isEqualTo(true); + } + + @Test + void shouldHaveReadiness() { + client.get().uri("/actuator/health/readiness").exchange().expectStatus().isOk().expectBody() + .jsonPath("$.status").isEqualTo("UP"); + } + + @Test + void shouldHaveEnvInfoProperties() { + client.get().uri("/actuator/info").exchange().expectStatus().isOk().expectBody().jsonPath("$.app.hello") + .isEqualTo("world"); + } + + @Test + void shouldHaveJavaInfoProperties() { + client.get().uri("/actuator/info").exchange().expectStatus().isOk().expectBody().jsonPath("$.java.version") + .isNotEmpty(); + } + + @Test + void shouldHaveOsInfoProperties() { + client.get().uri("/actuator/info").exchange().expectStatus().isOk().expectBody().jsonPath("$.os.name") + .isNotEmpty(); + } + + private static WebTestClient buildManagementClient() { + for (String line : Output.current().lines()) { + Matcher matcher = MANAGEMENT_PORT_REGEX.matcher(line); + if (matcher.matches()) { + int port = Integer.parseInt(matcher.group(1)); + return WebTestClient.bindToServer().baseUrl("http://localhost:%d/".formatted(port)).build(); + } + } + throw new IllegalStateException("No management port found in output"); + } + +} diff --git a/actuator-webflux-mgmt-port/src/main/java/com/example/actuator/webflux/mgmtport/ActuatorWebFluxMgmtPortApplication.java b/actuator-webflux-mgmt-port/src/main/java/com/example/actuator/webflux/mgmtport/ActuatorWebFluxMgmtPortApplication.java new file mode 100644 index 00000000..1a172e52 --- /dev/null +++ b/actuator-webflux-mgmt-port/src/main/java/com/example/actuator/webflux/mgmtport/ActuatorWebFluxMgmtPortApplication.java @@ -0,0 +1,27 @@ +package com.example.actuator.webflux.mgmtport; + +import org.springframework.aot.smoketest.thirdpartyhints.NettyRuntimeHints; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.reactive.context.ReactiveWebServerInitializedEvent; +import org.springframework.context.annotation.ImportRuntimeHints; +import org.springframework.context.event.EventListener; + +@SpringBootApplication +@ImportRuntimeHints(NettyRuntimeHints.class) +public class ActuatorWebFluxMgmtPortApplication { + + public static void main(String[] args) throws InterruptedException { + SpringApplication.run(ActuatorWebFluxMgmtPortApplication.class, args); + Thread.currentThread().join(); // To be able to measure memory consumption + } + + @EventListener + public void onAppEvent(ReactiveWebServerInitializedEvent e) { + // This is needed to get the management port in the AOT tests + if ("management".equals(e.getApplicationContext().getServerNamespace())) { + System.out.printf("Management port: %d%n", e.getWebServer().getPort()); + } + } + +} diff --git a/actuator-webflux-mgmt-port/src/main/resources/application.properties b/actuator-webflux-mgmt-port/src/main/resources/application.properties new file mode 100644 index 00000000..956f2750 --- /dev/null +++ b/actuator-webflux-mgmt-port/src/main/resources/application.properties @@ -0,0 +1,9 @@ +management.server.port=0 +management.endpoints.web.exposure.include=* +management.endpoint.health.show-details=always +management.endpoint.health.show-components=always +management.endpoint.health.probes.enabled=true +management.info.env.enabled=true +management.info.java.enabled=true +management.info.os.enabled=true +info.app.hello=world diff --git a/actuator-webflux-mgmt-port/src/test/java/com/example/actuator/webflux/mgmtport/ActuatorWebFluxMgmtPortApplicationTests.java b/actuator-webflux-mgmt-port/src/test/java/com/example/actuator/webflux/mgmtport/ActuatorWebFluxMgmtPortApplicationTests.java new file mode 100644 index 00000000..5f5d04f4 --- /dev/null +++ b/actuator-webflux-mgmt-port/src/test/java/com/example/actuator/webflux/mgmtport/ActuatorWebFluxMgmtPortApplicationTests.java @@ -0,0 +1,14 @@ +package com.example.actuator.webflux.mgmtport; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ActuatorWebFluxMgmtPortApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/ci/smoke-tests.yml b/ci/smoke-tests.yml index d0716e32..7a873712 100644 --- a/ci/smoke-tests.yml +++ b/ci/smoke-tests.yml @@ -1,5 +1,6 @@ smoke_tests: - actuator-webflux + - actuator-webflux-mgmt-port - actuator-webmvc - aspect - async diff --git a/settings.gradle b/settings.gradle index 96d28428..f2d806ef 100644 --- a/settings.gradle +++ b/settings.gradle @@ -28,6 +28,7 @@ include "aot-smoke-test-support" include "aot-smoke-test-third-party-hints" include "actuator-webflux" +include "actuator-webflux-mgmt-port" include "actuator-webmvc" include "aspect" include "async"