use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.
the class MongoNamespaceReplicaSetTests method testParsingWithPropertyPlaceHolder.
@Test
@SuppressWarnings("unchecked")
public void testParsingWithPropertyPlaceHolder() throws Exception {
assertThat(ctx.containsBean("manyReplicaSetMongo")).isTrue();
MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&manyReplicaSetMongo");
MongoClientSettings settings = (MongoClientSettings) ReflectionTestUtils.getField(mfb, "mongoClientSettings");
List<ServerAddress> replicaSetSeeds = settings.getClusterSettings().getHosts();
assertThat(replicaSetSeeds).isNotNull();
assertThat(replicaSetSeeds).hasSize(3);
List<Integer> ports = new ArrayList<Integer>();
for (ServerAddress replicaSetSeed : replicaSetSeeds) {
ports.add(replicaSetSeed.getPort());
}
assertThat(ports).contains(27017, 27018, 27019);
}
use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.
the class MongoClientFactoryBeanUnitTests method explicitSettingsOverrideConnectionStringOnes.
// DATAMONGO-2427
@Test
void explicitSettingsOverrideConnectionStringOnes() {
MongoClientFactoryBean factoryBean = new MongoClientFactoryBean();
factoryBean.setConnectionString(CONNECTION_STRING);
factoryBean.setMongoClientSettings(MongoClientSettings.builder().applyToClusterSettings(it -> it.requiredReplicaSetName("rs0")).applyToSocketSettings(it -> it.connectTimeout(100, TimeUnit.MILLISECONDS)).build());
MongoClientSettings settings = factoryBean.computeClientSetting();
assertThat(settings.getClusterSettings().getRequiredReplicaSetName()).isEqualTo("rs0");
assertThat(settings.getSocketSettings().getConnectTimeout(TimeUnit.MILLISECONDS)).isEqualTo(100);
assertThat(settings.getClusterSettings().getHosts()).hasSize(2);
}
use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.
the class MongoClientFactoryBeanUnitTests method connectionStringParametersNotOverriddenByDefaults.
// DATAMONGO-2427
@Test
void connectionStringParametersNotOverriddenByDefaults() {
MongoClientFactoryBean factoryBean = new MongoClientFactoryBean();
factoryBean.setConnectionString(CONNECTION_STRING);
factoryBean.setMongoClientSettings(MongoClientSettings.builder().build());
MongoClientSettings settings = factoryBean.computeClientSetting();
assertThat(settings.getClusterSettings().getRequiredReplicaSetName()).isEqualTo("test");
assertThat(settings.getSocketSettings().getConnectTimeout(TimeUnit.MILLISECONDS)).isEqualTo(300000);
assertThat(settings.getClusterSettings().getHosts()).hasSize(2);
}
use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.
the class MongoClientNamespaceTests method clientWithClusterSettings.
// DATAMONGO-2384
@Test
public void clientWithClusterSettings() {
assertThat(ctx.containsBean("client-with-cluster-settings")).isTrue();
MongoClientFactoryBean factoryBean = ctx.getBean("&client-with-cluster-settings", MongoClientFactoryBean.class);
MongoClientSettings settings = (MongoClientSettings) getField(factoryBean, "mongoClientSettings");
assertThat(settings.getClusterSettings().getRequiredClusterType()).isEqualTo(ClusterType.REPLICA_SET);
assertThat(settings.getClusterSettings().getServerSelectionTimeout(TimeUnit.MILLISECONDS)).isEqualTo(10);
assertThat(settings.getClusterSettings().getLocalThreshold(TimeUnit.MILLISECONDS)).isEqualTo(5);
assertThat(settings.getClusterSettings().getHosts()).contains(new ServerAddress("localhost", 27018), new ServerAddress("localhost", 27019), new ServerAddress("localhost", 27020));
}
use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.
the class MongoClientNamespaceTests method clientWithConnectionPoolSettings.
// DATAMONGO-2384
@Test
public void clientWithConnectionPoolSettings() {
assertThat(ctx.containsBean("client-with-connection-pool-settings")).isTrue();
MongoClientFactoryBean factoryBean = ctx.getBean("&client-with-connection-pool-settings", MongoClientFactoryBean.class);
MongoClientSettings settings = (MongoClientSettings) getField(factoryBean, "mongoClientSettings");
assertThat(settings.getConnectionPoolSettings().getMaxConnectionLifeTime(TimeUnit.MILLISECONDS)).isEqualTo(10);
assertThat(settings.getConnectionPoolSettings().getMinSize()).isEqualTo(10);
assertThat(settings.getConnectionPoolSettings().getMaxSize()).isEqualTo(20);
assertThat(settings.getConnectionPoolSettings().getMaintenanceFrequency(TimeUnit.MILLISECONDS)).isEqualTo(10);
assertThat(settings.getConnectionPoolSettings().getMaintenanceInitialDelay(TimeUnit.MILLISECONDS)).isEqualTo(11);
assertThat(settings.getConnectionPoolSettings().getMaxConnectionIdleTime(TimeUnit.MILLISECONDS)).isEqualTo(30);
assertThat(settings.getConnectionPoolSettings().getMaxWaitTime(TimeUnit.MILLISECONDS)).isEqualTo(15);
}
Aggregations