|
30 | 30 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
31 | 31 | import org.springframework.context.annotation.Bean; |
32 | 32 | import org.springframework.context.annotation.Configuration; |
33 | | -import org.springframework.context.support.GenericApplicationContext; |
34 | 33 | import org.springframework.core.annotation.Order; |
35 | 34 | import org.springframework.test.util.ReflectionTestUtils; |
36 | 35 |
|
@@ -92,17 +91,21 @@ void meterRegistryCloserShouldCloseRegistryOnShutdown() { |
92 | 91 | } |
93 | 92 |
|
94 | 93 | @Test |
95 | | - void meterRegistryCloserShouldNotCloseOnNonRootContextClosing() { |
96 | | - this.contextRunner.withUserConfiguration(MeterRegistryConfiguration.class).run((context) -> { |
97 | | - MeterRegistry meterRegistry = context.getBean(MeterRegistry.class); |
98 | | - GenericApplicationContext childContext = new GenericApplicationContext(); |
99 | | - childContext.setParent(context); |
100 | | - childContext.refresh(); |
101 | | - childContext.close(); |
102 | | - assertThat(meterRegistry.isClosed()).isFalse(); |
103 | | - context.close(); |
104 | | - assertThat(meterRegistry.isClosed()).isTrue(); |
| 94 | + void meterRegistryCloserShouldOnlyCloseRegistriesBelongingToContextBeingClosed() { |
| 95 | + MeterRegistry parentMeterRegistry = new SimpleMeterRegistry(); |
| 96 | + MeterRegistry childMeterRegistry = new SimpleMeterRegistry(); |
| 97 | + this.contextRunner.withBean(MeterRegistry.class, () -> parentMeterRegistry).run((parent) -> { |
| 98 | + this.contextRunner.withBean(MeterRegistry.class, () -> childMeterRegistry) |
| 99 | + .withParent(parent) |
| 100 | + .run((child) -> { |
| 101 | + assertThat(childMeterRegistry.isClosed()).isFalse(); |
| 102 | + assertThat(parentMeterRegistry.isClosed()).isFalse(); |
| 103 | + }); |
| 104 | + assertThat(childMeterRegistry.isClosed()).isTrue(); |
| 105 | + assertThat(parentMeterRegistry.isClosed()).isFalse(); |
105 | 106 | }); |
| 107 | + assertThat(childMeterRegistry.isClosed()).isTrue(); |
| 108 | + assertThat(parentMeterRegistry.isClosed()).isTrue(); |
106 | 109 | } |
107 | 110 |
|
108 | 111 | @Configuration(proxyBeanMethods = false) |
|
0 commit comments