1864 do not configure trace for async mongodb (#1869)
* Do not autoconfigure Branve Mongo DB trace for async mongo db * Fix checkstyle violations * Add Junit to test BraveMongoDBAutoConfig for async mongo db driver * Minor fixes * Use JUnit 5
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -90,6 +90,7 @@
|
||||
<awaitility.version>4.0.3</awaitility.version>
|
||||
<brave-propagation-aws.version>0.21.3</brave-propagation-aws.version>
|
||||
<archunit-junit5.version>0.14.1</archunit-junit5.version>
|
||||
<mongodb-driver-reactivestreams.version>4.0.0</mongodb-driver-reactivestreams.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
@@ -277,6 +278,11 @@
|
||||
<artifactId>archunit-junit5</artifactId>
|
||||
<version>${archunit-junit5.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongodb-driver-reactivestreams</artifactId>
|
||||
<version>${mongodb-driver-reactivestreams.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
@@ -375,6 +375,11 @@
|
||||
<artifactId>awaitility</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongodb-driver-reactivestreams</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Brave -->
|
||||
<dependency>
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.mongo.MongoClientSettingsBuilderCustomizer;
|
||||
@@ -41,6 +42,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @since 3.0.0
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnMissingClass("com.mongodb.reactivestreams.client.MongoClient")
|
||||
@ConditionalOnBean(Tracing.class)
|
||||
@AutoConfigureAfter(BraveAutoConfiguration.class)
|
||||
@AutoConfigureBefore(MongoAutoConfiguration.class)
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2013-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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.sleuth.autoconfig.brave.instrument.mongodb;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.cloud.sleuth.autoconfig.brave.BraveAutoConfiguration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Chintan Radia
|
||||
*/
|
||||
class BraveMongoDbAutoConfigurationAsyncDriverTest {
|
||||
|
||||
@Test
|
||||
void should_not_auto_configure_brave_mongo_db() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(BraveAutoConfiguration.class, BraveMongoDbAutoConfiguration.class))
|
||||
.run(context -> assertThat(context).doesNotHaveBean(BraveMongoDbAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_auto_configure_brave_mongo_db() {
|
||||
new ApplicationContextRunner()
|
||||
.withClassLoader(new FilteredClassLoader("com.mongodb.reactivestreams.client.MongoClient"))
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(BraveAutoConfiguration.class, BraveMongoDbAutoConfiguration.class))
|
||||
.run(context -> assertThat(context).hasSingleBean(BraveMongoDbAutoConfiguration.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user