use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.
the class MongoClientSettingsFactoryBean method createInstance.
@Override
protected MongoClientSettings createInstance() {
Builder builder = //
MongoClientSettings.builder().readPreference(//
readPreference).writeConcern(//
writeConcern).readConcern(//
readConcern).codecRegistry(//
codecRegistry).applicationName(//
applicationName).autoEncryptionSettings(//
autoEncryptionSettings).applyToClusterSettings((settings) -> {
settings.serverSelectionTimeout(clusterServerSelectionTimeoutMS, TimeUnit.MILLISECONDS);
if (clusterConnectionMode != null) {
settings.mode(clusterConnectionMode);
}
settings.requiredReplicaSetName(clusterRequiredReplicaSetName);
if (!CollectionUtils.isEmpty(clusterHosts)) {
settings.hosts(clusterHosts);
}
settings.localThreshold(clusterLocalThresholdMS, TimeUnit.MILLISECONDS);
// settings.maxWaitQueueSize(clusterMaxWaitQueueSize);
settings.requiredClusterType(custerRequiredClusterType);
if (StringUtils.hasText(clusterSrvHost)) {
settings.srvHost(clusterSrvHost);
}
}).applyToConnectionPoolSettings((settings) -> {
settings.minSize(poolMinSize);
settings.maxSize(poolMaxSize);
settings.maxConnectionIdleTime(poolMaxConnectionIdleTimeMS, TimeUnit.MILLISECONDS);
settings.maxWaitTime(poolMaxWaitTimeMS, TimeUnit.MILLISECONDS);
settings.maxConnectionLifeTime(poolMaxConnectionLifeTimeMS, TimeUnit.MILLISECONDS);
// settings.maxWaitQueueSize(poolMaxWaitQueueSize);
settings.maintenanceFrequency(poolMaintenanceFrequencyMS, TimeUnit.MILLISECONDS);
settings.maintenanceInitialDelay(poolMaintenanceInitialDelayMS, TimeUnit.MILLISECONDS);
}).applyToServerSettings((settings) -> {
settings.minHeartbeatFrequency(serverMinHeartbeatFrequencyMS, TimeUnit.MILLISECONDS);
settings.heartbeatFrequency(serverHeartbeatFrequencyMS, TimeUnit.MILLISECONDS);
}).applyToSocketSettings((settings) -> {
settings.connectTimeout(socketConnectTimeoutMS, TimeUnit.MILLISECONDS);
settings.readTimeout(socketReadTimeoutMS, TimeUnit.MILLISECONDS);
settings.receiveBufferSize(socketReceiveBufferSize);
settings.sendBufferSize(socketSendBufferSize);
}).applyToSslSettings((settings) -> {
settings.enabled(sslEnabled);
if (sslEnabled) {
settings.invalidHostNameAllowed(sslInvalidHostNameAllowed);
try {
settings.context(StringUtils.hasText(sslProvider) ? SSLContext.getInstance(sslProvider) : SSLContext.getDefault());
} catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}
});
if (streamFactoryFactory != null) {
builder = builder.streamFactoryFactory(streamFactoryFactory);
}
if (retryReads != null) {
builder = builder.retryReads(retryReads);
}
if (retryWrites != null) {
builder = builder.retryWrites(retryWrites);
}
if (uUidRepresentation != null) {
builder = builder.uuidRepresentation(uUidRepresentation);
}
if (serverApi != null) {
builder = builder.serverApi(serverApi);
}
return builder.build();
}
use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.
the class MongoClientNamespaceTests method clientWithServerVersion.
// GH-3820
@Test
public void clientWithServerVersion() {
assertThat(ctx.containsBean("client-with-server-api-settings")).isTrue();
MongoClientFactoryBean factoryBean = ctx.getBean("&client-with-server-api-settings", MongoClientFactoryBean.class);
MongoClientSettings settings = (MongoClientSettings) getField(factoryBean, "mongoClientSettings");
assertThat(settings.getServerApi()).isNotNull().satisfies(it -> {
assertThat(it.getVersion()).isEqualTo(ServerApiVersion.V1);
});
}
use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.
the class MongoNamespaceTests method testMongoSingletonWithSslEnabledAndCustomSslSocketFactory.
// DATAMONGO-764
@Test
public void testMongoSingletonWithSslEnabledAndCustomSslSocketFactory() throws Exception {
assertThat(ctx.containsBean("mongoSslWithCustomSslFactory")).isTrue();
MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&mongoSslWithCustomSslFactory");
MongoClientSettings options = (MongoClientSettings) getField(mfb, "mongoClientSettings");
assertThat(options.getSslSettings().getContext().getSocketFactory() instanceof SSLSocketFactory).as("socketFactory should be a SSLSocketFactory").isTrue();
assertThat(options.getSslSettings().getContext().getProvider().getName()).isEqualTo("SunJSSE");
}
use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.
the class MongoNamespaceTests method testMongoClientSingletonWithSslEnabled.
// DATAMONGO-1490
@Test
public void testMongoClientSingletonWithSslEnabled() {
assertThat(ctx.containsBean("mongoClientSsl")).isTrue();
MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&mongoClientSsl");
MongoClientSettings options = (MongoClientSettings) getField(mfb, "mongoClientSettings");
assertThat(options.getSslSettings().getContext().getSocketFactory() instanceof SSLSocketFactory).as("socketFactory should be a SSLSocketFactory").isTrue();
}
use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.
the class MongoClientFactoryBeanUnitTests method hostPortParametersNotOverriddenByDefaults.
// DATAMONGO-2427
@Test
void hostPortParametersNotOverriddenByDefaults() {
MongoClientFactoryBean factoryBean = new MongoClientFactoryBean();
factoryBean.setPort(2500);
factoryBean.setHost("db2.example.net");
factoryBean.setReplicaSet("rs0");
factoryBean.setMongoClientSettings(MongoClientSettings.builder().build());
MongoClientSettings settings = factoryBean.computeClientSetting();
assertThat(settings.getClusterSettings().getRequiredReplicaSetName()).isEqualTo("rs0");
assertThat(settings.getClusterSettings().getHosts()).containsExactly(new ServerAddress("db2.example.net", 2500));
}
Aggregations