From 39a1c854d8f8a64800466a19cf19bde572bf4a82 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Sun, 5 Sep 2021 17:36:27 +0200 Subject: [PATCH] Polish "Auto-configure JVM heap pressure metrics" See gh-27868 --- .../JvmMetricsAutoConfigurationTests.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfigurationTests.java index f4d640532f..93761e2b66 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfigurationTests.java @@ -55,6 +55,12 @@ class JvmMetricsAutoConfigurationTests { .run(assertMetricsBeans().andThen((context) -> assertThat(context).hasBean("customJvmGcMetrics"))); } + @Test + void allowsCustomJvmHeapPressureMetricsToBeUsed() { + this.contextRunner.withUserConfiguration(CustomJvmHeapPressureMetricsConfiguration.class).run( + assertMetricsBeans().andThen((context) -> assertThat(context).hasBean("customJvmHeapPressureMetrics"))); + } + @Test void allowsCustomJvmMemoryMetricsToBeUsed() { this.contextRunner.withUserConfiguration(CustomJvmMemoryMetricsConfiguration.class) @@ -74,9 +80,9 @@ class JvmMetricsAutoConfigurationTests { } private ContextConsumer assertMetricsBeans() { - return (context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class).hasSingleBean(JvmMemoryMetrics.class) - .hasSingleBean(JvmHeapPressureMetrics.class).hasSingleBean(JvmThreadMetrics.class) - .hasSingleBean(ClassLoaderMetrics.class); + return (context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class) + .hasSingleBean(JvmHeapPressureMetrics.class).hasSingleBean(JvmMemoryMetrics.class) + .hasSingleBean(JvmThreadMetrics.class).hasSingleBean(ClassLoaderMetrics.class); } @Configuration(proxyBeanMethods = false) @@ -89,6 +95,16 @@ class JvmMetricsAutoConfigurationTests { } + @Configuration(proxyBeanMethods = false) + static class CustomJvmHeapPressureMetricsConfiguration { + + @Bean + JvmHeapPressureMetrics customJvmHeapPressureMetrics() { + return new JvmHeapPressureMetrics(); + } + + } + @Configuration(proxyBeanMethods = false) static class CustomJvmMemoryMetricsConfiguration {