use of com.mongodb.MongoClient 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));
}
use of com.mongodb.MongoClient in project spring-data-mongodb by spring-projects.
the class MongoResultsWriter method write.
@Override
public void write(Collection<RunResult> results) {
Date now = new Date();
StandardEnvironment env = new StandardEnvironment();
String projectVersion = env.getProperty("project.version", "unknown");
String gitBranch = env.getProperty("git.branch", "unknown");
String gitDirty = env.getProperty("git.dirty", "no");
String gitCommitId = env.getProperty("git.commit.id", "unknown");
MongoClientURI uri = new MongoClientURI(this.uri);
MongoClient client = new MongoClient(uri);
String dbName = StringUtils.hasText(uri.getDatabase()) ? uri.getDatabase() : "spring-data-mongodb-benchmarks";
MongoDatabase db = client.getDatabase(dbName);
for (BasicDBObject dbo : (List<BasicDBObject>) JSON.parse(ResultsWriter.jsonifyResults(results))) {
String collectionName = extractClass(dbo.get("benchmark").toString());
Document sink = new Document();
sink.append("_version", projectVersion);
sink.append("_branch", gitBranch);
sink.append("_commit", gitCommitId);
sink.append("_dirty", gitDirty);
sink.append("_method", extractBenchmarkName(dbo.get("benchmark").toString()));
sink.append("_date", now);
sink.append("_snapshot", projectVersion.toLowerCase().contains("snapshot"));
sink.putAll(dbo);
db.getCollection(collectionName).insertOne(fixDocumentKeys(sink));
}
client.close();
}
use of com.mongodb.MongoClient in project spring-data-mongodb by spring-projects.
the class MongoVersionRule method fetchCurrentVersion.
private Version fetchCurrentVersion() {
try {
MongoClient client;
client = new MongoClient(host, port);
MongoDatabase database = client.getDatabase("test");
Document result = database.runCommand(new Document("buildInfo", 1));
client.close();
return Version.parse(result.get("version", String.class));
} catch (Exception e) {
return ANY;
}
}
use of com.mongodb.MongoClient in project spring-data-mongodb by spring-projects.
the class ReplicaSet method runsAsReplicaSet.
public boolean runsAsReplicaSet() {
if (runsAsReplicaSet.get() == null) {
try (MongoClient client = new MongoClient()) {
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.MongoClient in project spring-data-mongodb by spring-projects.
the class DefaultMessageListenerContainerTests method setUp.
@Before
public void setUp() {
dbFactory = new SimpleMongoDbFactory(new MongoClient(), DATABASE_NAME);
template = new MongoTemplate(dbFactory);
template.dropCollection(COLLECTION_NAME);
collection = template.getCollection(COLLECTION_NAME);
messageListener = new CollectingMessageListener<>();
}
Aggregations