Skip to content

Fix MongoMetricsAutoConfigurationTests #25952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* Tests for {@link MongoMetricsAutoConfiguration}.
*
* @author Chris Bono
* @author Johnny Lim
*/
class MongoMetricsAutoConfigurationTests {

Expand Down Expand Up @@ -80,13 +81,13 @@ void whenThereIsAMeterRegistryThenMetricsConnectionPoolListenerIsAdded() {
@Test
void whenThereIsNoMeterRegistryThenNoMetricsCommandListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.run((context) -> assertThatMetricsCommandListenerNotAdded());
.run(assertThatMetricsCommandListenerNotAdded());
}

@Test
void whenThereIsNoMeterRegistryThenNoMetricsConnectionPoolListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.run((context) -> assertThatMetricsConnectionPoolListenerNotAdded());
.run(assertThatMetricsConnectionPoolListenerNotAdded());
}

@Test
Expand Down Expand Up @@ -114,44 +115,50 @@ void whenThereIsACustomMetricsConnectionPoolTagsProviderItIsUsed() {

@Test
void whenThereIsNoMongoClientSettingsOnClasspathThenNoMetricsCommandListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
this.contextRunner.with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.withClassLoader(new FilteredClassLoader(MongoClientSettings.class))
.run((context) -> assertThatMetricsCommandListenerNotAdded());
.run(assertThatMetricsCommandListenerNotAdded());
}

@Test
void whenThereIsNoMongoClientSettingsOnClasspathThenNoMetricsConnectionPoolListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
this.contextRunner.with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.withClassLoader(new FilteredClassLoader(MongoClientSettings.class))
.run((context) -> assertThatMetricsConnectionPoolListenerNotAdded());
.run(assertThatMetricsConnectionPoolListenerNotAdded());
}

@Test
void whenThereIsNoMongoMetricsCommandListenerOnClasspathThenNoMetricsCommandListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
this.contextRunner.with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.withClassLoader(new FilteredClassLoader(MongoMetricsCommandListener.class))
.run((context) -> assertThatMetricsCommandListenerNotAdded());
.run(assertThatMetricsCommandListenerNotAdded());
}

@Test
void whenThereIsNoMongoMetricsConnectionPoolListenerOnClasspathThenNoMetricsConnectionPoolListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
this.contextRunner.with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.withClassLoader(new FilteredClassLoader(MongoMetricsConnectionPoolListener.class))
.run((context) -> assertThatMetricsConnectionPoolListenerNotAdded());
.run(assertThatMetricsConnectionPoolListenerNotAdded());
}

@Test
void whenMetricsCommandListenerEnabledPropertyFalseThenNoMetricsCommandListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
this.contextRunner.with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.withPropertyValues("management.metrics.mongo.command.enabled:false")
.run((context) -> assertThatMetricsCommandListenerNotAdded());
.run(assertThatMetricsCommandListenerNotAdded());
}

@Test
void whenMetricsConnectionPoolListenerEnabledPropertyFalseThenNoMetricsConnectionPoolListenerIsAdded() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
this.contextRunner.with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class))
.withPropertyValues("management.metrics.mongo.connectionpool.enabled:false")
.run((context) -> assertThatMetricsConnectionPoolListenerNotAdded());
.run(assertThatMetricsConnectionPoolListenerNotAdded());
}

private ContextConsumer<AssertableApplicationContext> assertThatMetricsCommandListenerNotAdded() {
Expand Down