|
|
@ -16,8 +16,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.metrics.export.graphite;
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.metrics.export.graphite;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import io.micrometer.core.instrument.Clock;
|
|
|
|
import io.micrometer.core.instrument.Clock;
|
|
|
|
import io.micrometer.core.instrument.Tags;
|
|
|
|
import io.micrometer.core.instrument.Tags;
|
|
|
|
import io.micrometer.graphite.GraphiteConfig;
|
|
|
|
import io.micrometer.graphite.GraphiteConfig;
|
|
|
@ -25,16 +23,12 @@ import io.micrometer.graphite.GraphiteMeterRegistry;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
|
|
|
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Import;
|
|
|
|
import org.springframework.context.annotation.Import;
|
|
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.mockito.Mockito.spy;
|
|
|
|
|
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Tests for {@link GraphiteMetricsExportAutoConfiguration}.
|
|
|
|
* Tests for {@link GraphiteMetricsExportAutoConfiguration}.
|
|
|
@ -106,27 +100,14 @@ public class GraphiteMetricsExportAutoConfigurationTests {
|
|
|
|
public void stopsMeterRegistryWhenContextIsClosed() {
|
|
|
|
public void stopsMeterRegistryWhenContextIsClosed() {
|
|
|
|
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
GraphiteMeterRegistry registry = spyOnDisposableBean(
|
|
|
|
GraphiteMeterRegistry registry = context
|
|
|
|
GraphiteMeterRegistry.class, context);
|
|
|
|
.getBean(GraphiteMeterRegistry.class);
|
|
|
|
|
|
|
|
assertThat(registry.isClosed()).isFalse();
|
|
|
|
context.close();
|
|
|
|
context.close();
|
|
|
|
verify(registry).stop();
|
|
|
|
assertThat(registry.isClosed()).isTrue();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
|
|
|
private <T> T spyOnDisposableBean(Class<T> type,
|
|
|
|
|
|
|
|
AssertableApplicationContext context) {
|
|
|
|
|
|
|
|
String[] names = context.getBeanNamesForType(type);
|
|
|
|
|
|
|
|
assertThat(names).hasSize(1);
|
|
|
|
|
|
|
|
String registryBeanName = names[0];
|
|
|
|
|
|
|
|
Map<String, Object> disposableBeans = (Map<String, Object>) ReflectionTestUtils
|
|
|
|
|
|
|
|
.getField(context.getAutowireCapableBeanFactory(), "disposableBeans");
|
|
|
|
|
|
|
|
Object registryAdapter = disposableBeans.get(registryBeanName);
|
|
|
|
|
|
|
|
T registry = (T) spy(ReflectionTestUtils.getField(registryAdapter, "bean"));
|
|
|
|
|
|
|
|
ReflectionTestUtils.setField(registryAdapter, "bean", registry);
|
|
|
|
|
|
|
|
return registry;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
static class BaseConfiguration {
|
|
|
|
static class BaseConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|