use of com.mongodb.client.MongoClient 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.client.MongoClient 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.client.MongoClient in project spring-data-mongodb by spring-projects.
the class MongoVersionRule method fetchCurrentVersion.
private Version fetchCurrentVersion() {
try {
MongoClient client = MongoTestUtils.client(host, port);
MongoDatabase database = client.getDatabase("test");
Document result = database.runCommand(new Document("buildInfo", 1));
return Version.parse(result.get("version", String.class));
} catch (Exception e) {
return ANY;
}
}
use of com.mongodb.client.MongoClient in project spring-data-mongodb by spring-projects.
the class ReplicaSet method runsAsReplicaSet.
public boolean runsAsReplicaSet() {
if (runsAsReplicaSet.get() == null) {
MongoClient client = MongoTestUtils.client();
boolean tmp = client.getDatabase("admin").runCommand(new Document("getCmdLineOpts", "1")).get("argv", List.class).contains("--replSet");
runsAsReplicaSet.compareAndSet(null, tmp);
}
return runsAsReplicaSet.get();
}
use of com.mongodb.client.MongoClient in project brave by openzipkin.
the class ITMongoDB method initCollection.
@BeforeClass
public static void initCollection() {
try (MongoClient mongoClient = MongoClients.create(mongoClientSettingsBuilder().build())) {
MongoDatabase database = mongoClient.getDatabase(DATABASE_NAME);
MongoCollection<Document> collection = database.getCollection(COLLECTION_NAME);
Document document1 = new Document("id", 1);
Document document2 = new Document("id", 2);
collection.insertMany(Arrays.asList(document1, document2));
}
}
Aggregations