use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.
the class MongoConfigurationSupport method mongoClientSettings.
/**
* Return the {@link MongoClientSettings} used to create the actual {@literal MongoClient}. <br />
* Override either this method, or use {@link #configureClientSettings(Builder)} to alter the setup.
*
* @return never {@literal null}.
* @since 3.0
*/
protected MongoClientSettings mongoClientSettings() {
MongoClientSettings.Builder builder = MongoClientSettings.builder();
builder.uuidRepresentation(UuidRepresentation.JAVA_LEGACY);
configureClientSettings(builder);
return builder.build();
}
use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.
the class MongoClientParserIntegrationTests method createsMongoClientWithServerSelectionTimeoutCorrectly.
// DATAMONGO-1620
@Test
public void createsMongoClientWithServerSelectionTimeoutCorrectly() {
reader.loadBeanDefinitions(new ClassPathResource("namespace/mongoClient-bean.xml"));
try (AbstractApplicationContext context = new GenericApplicationContext(factory)) {
context.refresh();
MongoClientSettings settings = extractClientSettingsFromBean(context, "mongo-client-with-server-selection-timeout");
assertThat(settings.getClusterSettings().getServerSelectionTimeout(TimeUnit.MILLISECONDS)).isEqualTo(100);
}
}
use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.
the class MongoClientParserIntegrationTests method createsMongoClientWithCredentialsCorrectly.
// DATAMONGO-1158
@Test
public void createsMongoClientWithCredentialsCorrectly() {
reader.loadBeanDefinitions(new ClassPathResource("namespace/mongoClient-bean.xml"));
try (AbstractApplicationContext context = new GenericApplicationContext(factory)) {
context.refresh();
MongoClientSettings settings = extractClientSettingsFromBean(context, "mongo-client-with-credentials");
assertThat(settings.getCredential()).isEqualTo(MongoCredential.createPlainCredential("jon", "snow", "warg".toCharArray()));
}
}
use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.
the class MongoClientParserIntegrationTests method createsMongoClientWithOptionsCorrectly.
// DATAMONGO-1158, DATAMONGO-2199
@Test
public void createsMongoClientWithOptionsCorrectly() {
reader.loadBeanDefinitions(new ClassPathResource("namespace/mongoClient-bean.xml"));
try (AbstractApplicationContext context = new GenericApplicationContext(factory)) {
context.refresh();
MongoClientSettings settings = extractClientSettingsFromBean(context, "mongo-client-with-options-for-write-concern-and-read-preference");
assertThat(settings.getReadPreference()).isEqualTo(ReadPreference.secondary());
assertThat(settings.getWriteConcern()).isEqualTo(WriteConcern.UNACKNOWLEDGED);
}
}
use of com.mongodb.MongoClientSettings in project spring-data-mongodb by spring-projects.
the class MongoNamespaceReplicaSetTests method testParsingMongoWithReplicaSets.
@Test
@SuppressWarnings("unchecked")
public void testParsingMongoWithReplicaSets() throws Exception {
assertThat(ctx.containsBean("replicaSetMongo")).isTrue();
MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&replicaSetMongo");
MongoClientSettings settings = (MongoClientSettings) ReflectionTestUtils.getField(mfb, "mongoClientSettings");
List<ServerAddress> replicaSetSeeds = settings.getClusterSettings().getHosts();
assertThat(replicaSetSeeds).isNotNull();
assertThat(replicaSetSeeds).contains(new ServerAddress(InetAddress.getByName("127.0.0.1"), 10001), new ServerAddress(InetAddress.getByName("localhost"), 10002));
}
Aggregations