From 90369996a9410bb52e5b0c381c5d32d2845b901c Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Tue, 19 Dec 2017 07:41:32 +0900 Subject: [PATCH] Apply customize() to createCredentialNetworkMongoClient() See gh-11376 --- .../mongo/ReactiveMongoClientFactory.java | 9 ++++++--- .../mongo/ReactiveMongoClientFactoryTests.java | 10 ++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactory.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactory.java index 3a9e4e1db5..b8912d61ad 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactory.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactory.java @@ -92,6 +92,10 @@ public class ReactiveMongoClientFactory { ClusterSettings clusterSettings = ClusterSettings.builder() .hosts(Collections.singletonList(new ServerAddress(host, port))).build(); builder.clusterSettings(clusterSettings); + return createMongoClient(builder); + } + + private MongoClient createMongoClient(Builder builder) { customize(builder); return MongoClients.create(builder.build()); } @@ -102,7 +106,7 @@ public class ReactiveMongoClientFactory { } ConnectionString connectionString = new ConnectionString( this.properties.determineUri()); - return MongoClients.create(createBuilder(settings, connectionString).build()); + return createMongoClient(createBuilder(settings, connectionString)); } private MongoClient createCredentialNetworkMongoClient(MongoClientSettings settings) { @@ -117,7 +121,7 @@ public class ReactiveMongoClientFactory { ServerAddress serverAddress = new ServerAddress(host, port); builder.clusterSettings(ClusterSettings.builder() .hosts(Collections.singletonList(serverAddress)).build()); - return MongoClients.create(builder.build()); + return createMongoClient(builder); } private void applyCredentials(Builder builder) { @@ -155,7 +159,6 @@ public class ReactiveMongoClientFactory { if (connection.getApplicationName() != null) { builder.applicationName(connection.getApplicationName()); } - customize(builder); return builder; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactoryTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactoryTests.java index 33962435dd..48eb1144a5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactoryTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactoryTests.java @@ -160,6 +160,16 @@ public class ReactiveMongoClientFactoryTests { verify(customizer).customize(any(MongoClientSettings.Builder.class)); } + @Test + public void customizerIsInvokedWhenHostIsSet() { + MongoProperties properties = new MongoProperties(); + properties.setHost("localhost"); + MongoClientSettingsBuilderCustomizer customizer = mock( + MongoClientSettingsBuilderCustomizer.class); + createMongoClient(properties, this.environment, customizer); + verify(customizer).customize(any(MongoClientSettings.Builder.class)); + } + @Test public void customizerIsInvokedForEmbeddedMongo() { MongoProperties properties = new MongoProperties();