use of com.mongodb.ServerAddress in project spring-data-mongodb by spring-projects.
the class MongoNamespaceReplicaSetTests method testMongoWithReplicaSets.
@Test
@Ignore("CI infrastructure does not yet support replica sets")
public void testMongoWithReplicaSets() {
MongoClient mongo = ctx.getBean(MongoClient.class);
assertThat(mongo.getClusterDescription().getClusterSettings().getHosts()).isEqualTo(2);
List<ServerAddress> servers = mongo.getClusterDescription().getClusterSettings().getHosts();
assertThat(servers.get(0).getHost()).isEqualTo("127.0.0.1");
assertThat(servers.get(1).getHost()).isEqualTo("localhost");
assertThat(servers.get(0).getPort()).isEqualTo(10001);
assertThat(servers.get(1).getPort()).isEqualTo(10002);
MongoTemplate template = new MongoTemplate(mongo, "admin");
Document result = template.executeCommand("{replSetGetStatus : 1}");
assertThat(result.get("set").toString()).isEqualTo("blort");
}
use of com.mongodb.ServerAddress in project spring-data-mongodb by spring-projects.
the class MongoNamespaceTests method testSecondMongoDbFactory.
@Test
public void testSecondMongoDbFactory() {
assertThat(ctx.containsBean("secondMongoDbFactory")).isTrue();
MongoDatabaseFactory dbf = (MongoDatabaseFactory) ctx.getBean("secondMongoDbFactory");
MongoClient mongo = (MongoClient) getField(dbf, "mongoClient");
assertThat(mongo.getClusterDescription().getClusterSettings().getHosts()).containsExactly(new ServerAddress());
assertThat(getField(dbf, "databaseName")).isEqualTo("database");
}
use of com.mongodb.ServerAddress in project spring-data-mongodb by spring-projects.
the class MongoExceptionTranslatorUnitTests method translateSocketExceptionSubclasses.
// GH-3568
@Test
void translateSocketExceptionSubclasses() {
expectExceptionWithCauseMessage(translator.translateExceptionIfPossible(new MongoSocketWriteException("intermediate message", new ServerAddress(), new Exception(EXCEPTION_MESSAGE))), DataAccessResourceFailureException.class, EXCEPTION_MESSAGE);
expectExceptionWithCauseMessage(translator.translateExceptionIfPossible(new MongoSocketReadTimeoutException("intermediate message", new ServerAddress(), new Exception(EXCEPTION_MESSAGE))), DataAccessResourceFailureException.class, EXCEPTION_MESSAGE);
}
use of com.mongodb.ServerAddress 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));
}
use of com.mongodb.ServerAddress in project spring-data-mongodb by spring-projects.
the class DbRefMappingBenchmark method setUp.
@Setup
public void setUp() throws Exception {
client = new MongoClient(new ServerAddress());
template = new MongoTemplate(client, DB_NAME);
List<RefObject> refObjects = new ArrayList<>();
for (int i = 0; i < 1; i++) {
RefObject o = new RefObject();
template.save(o);
refObjects.add(o);
}
ObjectWithDBRef singleDBRef = new ObjectWithDBRef();
singleDBRef.ref = refObjects.iterator().next();
template.save(singleDBRef);
ObjectWithDBRef multipleDBRefs = new ObjectWithDBRef();
multipleDBRefs.refList = refObjects;
template.save(multipleDBRefs);
queryObjectWithDBRef = query(where("id").is(singleDBRef.id));
queryObjectWithDBRefList = query(where("id").is(multipleDBRefs.id));
}
Aggregations