|
31 | 31 | import org.springframework.boot.autoconfigure.AutoConfigurations; |
32 | 32 | import org.springframework.boot.micrometer.metrics.autoconfigure.MetricsAutoConfiguration.MeterRegistryCloser; |
33 | 33 | import org.springframework.boot.micrometer.observation.autoconfigure.ObservationHandlerGroup; |
| 34 | +import org.springframework.boot.test.context.assertj.AssertableApplicationContext; |
34 | 35 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
| 36 | +import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
35 | 37 | import org.springframework.context.annotation.Bean; |
36 | 38 | import org.springframework.context.annotation.Configuration; |
| 39 | +import org.springframework.context.support.GenericApplicationContext; |
37 | 40 | import org.springframework.core.annotation.Order; |
38 | 41 | import org.springframework.test.util.ReflectionTestUtils; |
39 | 42 |
|
|
47 | 50 | * @author Andy Wilkinson |
48 | 51 | * @author Moritz Halbritter |
49 | 52 | * @author Phillip Webb |
| 53 | + * @author Michael Berry |
50 | 54 | */ |
51 | 55 | class MetricsAutoConfigurationTests { |
52 | 56 |
|
@@ -95,6 +99,21 @@ void meterRegistryCloserShouldCloseRegistryOnShutdown() { |
95 | 99 | }); |
96 | 100 | } |
97 | 101 |
|
| 102 | + @Test |
| 103 | + void meterRegistryCloserShouldNotCloseOnNonRootContextClosing() { |
| 104 | + this.contextRunner.withUserConfiguration(MeterRegistryConfiguration.class).run((context) -> { |
| 105 | + MeterRegistry meterRegistry = context.getBean(MeterRegistry.class); |
| 106 | + GenericApplicationContext childContext = new GenericApplicationContext(); |
| 107 | + childContext.setParent(context); |
| 108 | + childContext.refresh(); |
| 109 | + childContext.close(); |
| 110 | + assertThat(meterRegistry.isClosed()).isFalse(); |
| 111 | + context.close(); |
| 112 | + assertThat(meterRegistry.isClosed()).isTrue(); |
| 113 | + }); |
| 114 | + } |
| 115 | + |
| 116 | + |
98 | 117 | @Test |
99 | 118 | void supplyHandlerAndGroup() { |
100 | 119 | this.contextRunner.run((context) -> { |
|
0 commit comments