Commit bae6b311 authored by Stephane Nicoll's avatar Stephane Nicoll

Merge pull request #11376 from izeye:customize

* pr/11376:
  Polish "Apply customize() to createCredentialNetworkMongoClient()"
  Apply customize() to createCredentialNetworkMongoClient()
parents 601b5e4d c709ff8e
......@@ -92,8 +92,7 @@ public class ReactiveMongoClientFactory {
ClusterSettings clusterSettings = ClusterSettings.builder()
.hosts(Collections.singletonList(new ServerAddress(host, port))).build();
builder.clusterSettings(clusterSettings);
customize(builder);
return MongoClients.create(builder.build());
return createMongoClient(builder);
}
private MongoClient createNetworkMongoClient(MongoClientSettings settings) {
......@@ -102,7 +101,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 +116,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) {
......@@ -134,6 +133,11 @@ public class ReactiveMongoClientFactory {
return (value == null ? defaultValue : value);
}
private MongoClient createMongoClient(Builder builder) {
customize(builder);
return MongoClients.create(builder.build());
}
private Builder createBuilder(MongoClientSettings settings,
ConnectionString connection) {
Builder builder = builder(settings);
......@@ -155,7 +159,6 @@ public class ReactiveMongoClientFactory {
if (connection.getApplicationName() != null) {
builder.applicationName(connection.getApplicationName());
}
customize(builder);
return builder;
}
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment