|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
21 | 21 | import ch.qos.logback.classic.Logger;
|
22 | 22 | import ch.qos.logback.classic.LoggerContext;
|
23 | 23 | import io.micrometer.core.instrument.MeterRegistry;
|
| 24 | +import io.micrometer.core.instrument.Metrics; |
24 | 25 | import io.micrometer.core.instrument.binder.MeterBinder;
|
25 | 26 | import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
|
26 | 27 | import org.junit.jupiter.api.Test;
|
|
45 | 46 | * {@link MetricsAutoConfiguration}.
|
46 | 47 | *
|
47 | 48 | * @author Jon Schneider
|
| 49 | + * @author Yanming Zhou |
48 | 50 | */
|
49 | 51 | class MetricsAutoConfigurationMeterRegistryPostProcessorIntegrationTests {
|
50 | 52 |
|
@@ -104,6 +106,20 @@ void counterIsIncrementedOncePerEventWithCompositeMeterRegistry() {
|
104 | 106 | });
|
105 | 107 | }
|
106 | 108 |
|
| 109 | + @Test |
| 110 | + void excludeAutoConfiguredCompositeFromGlobalRegistry() { |
| 111 | + this.contextRunner.withConfiguration(AutoConfigurations.of(MetricsAutoConfiguration.class)) |
| 112 | + .withPropertyValues("management.metrics.use-global-registry=true") |
| 113 | + .run((context) -> { |
| 114 | + assertThat(context).hasSingleBean(AutoConfiguredCompositeMeterRegistry.class); |
| 115 | + assertThat(Metrics.globalRegistry.getRegistries()).isNotEmpty(); |
| 116 | + assertThat(Metrics.globalRegistry.getRegistries() |
| 117 | + .stream() |
| 118 | + .filter(AutoConfiguredCompositeMeterRegistry.class::isInstance) |
| 119 | + .findAny()).isEmpty(); |
| 120 | + }); |
| 121 | + } |
| 122 | + |
107 | 123 | @Configuration(proxyBeanMethods = false)
|
108 | 124 | static class TestConfiguration {
|
109 | 125 |
|
|
0 commit comments