Skip to content

Commit

Permalink
Merge branch '2.3.x' into 2.4.x
Browse files Browse the repository at this point in the history
Closes gh-25185
  • Loading branch information
wilkinsona committed Feb 11, 2021
2 parents 75fc896 + bd64e05 commit 9ba28a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,7 +42,7 @@
@AutoConfigureAfter({ MetricsAutoConfiguration.class, RabbitAutoConfiguration.class,
SimpleMetricsExportAutoConfiguration.class })
@ConditionalOnClass({ ConnectionFactory.class, AbstractConnectionFactory.class })
@ConditionalOnBean({ AbstractConnectionFactory.class, MeterRegistry.class })
@ConditionalOnBean({ org.springframework.amqp.rabbit.connection.ConnectionFactory.class, MeterRegistry.class })
public class RabbitMetricsAutoConfiguration {

@Bean
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,10 +19,14 @@
import io.micrometer.core.instrument.MeterRegistry;
import org.junit.jupiter.api.Test;

import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -45,6 +49,15 @@ void autoConfiguredConnectionFactoryIsInstrumented() {
});
}

@Test
void abstractConnectionFactoryDefinedAsAConnectionFactoryIsInstrumented() {
this.contextRunner.withUserConfiguration(ConnectionFactoryConfiguration.class).run((context) -> {
assertThat(context).hasBean("customConnectionFactory");
MeterRegistry registry = context.getBean(MeterRegistry.class);
registry.get("rabbitmq.connections").meter();
});
}

@Test
void rabbitmqNativeConnectionFactoryInstrumentationCanBeDisabled() {
this.contextRunner.withPropertyValues("management.metrics.enable.rabbitmq=false").run((context) -> {
Expand All @@ -53,4 +66,14 @@ void rabbitmqNativeConnectionFactoryInstrumentationCanBeDisabled() {
});
}

@Configuration
static class ConnectionFactoryConfiguration {

@Bean
ConnectionFactory customConnectionFactory() {
return new CachingConnectionFactory();
}

}

}

0 comments on commit 9ba28a8

Please sign in to comment.