Search in sources :

Example 1 with ReplicaSet

use of com.antwerkz.bottlerocket.clusters.ReplicaSet in project morphia by mongodb.

the class TestBase method startMongo.

private void startMongo() {
    String mongodb = System.getenv("MONGODB");
    Builder builder = MongoClientSettings.builder();
    try {
        builder.uuidRepresentation(mapperOptions.getUuidRepresentation());
    } catch (Exception ignored) {
    // not a 4.0 driver
    }
    if (mongodb != null) {
        File mongodbRoot = new File("target/mongo");
        try {
            FileUtils.deleteDirectory(mongodbRoot);
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
        Version version = Version.valueOf(mongodb);
        final MongoCluster cluster = version.lessThan(Version.valueOf("4.0.0")) ? new SingleNode(mongodbRoot, "morphia_test", version) : new ReplicaSet(mongodbRoot, "morphia_test", version);
        cluster.configure(c -> {
            c.systemLog(s -> {
                s.setTraceAllExceptions(true);
                s.setVerbosity(Verbosity.FIVE);
                return null;
            });
            return null;
        });
        cluster.clean();
        cluster.start();
        mongoClient = cluster.getClient(builder);
    } else {
        mongoClient = MongoClients.create(builder.build());
    }
}
Also used : MongoCluster(com.antwerkz.bottlerocket.clusters.MongoCluster) Version(com.github.zafarkhaja.semver.Version) Builder(com.mongodb.MongoClientSettings.Builder) IOException(java.io.IOException) File(java.io.File) ReplicaSet(com.antwerkz.bottlerocket.clusters.ReplicaSet) SkipException(org.testng.SkipException) IOException(java.io.IOException) SingleNode(com.antwerkz.bottlerocket.clusters.SingleNode)

Aggregations

MongoCluster (com.antwerkz.bottlerocket.clusters.MongoCluster)1 ReplicaSet (com.antwerkz.bottlerocket.clusters.ReplicaSet)1 SingleNode (com.antwerkz.bottlerocket.clusters.SingleNode)1 Version (com.github.zafarkhaja.semver.Version)1 Builder (com.mongodb.MongoClientSettings.Builder)1 File (java.io.File)1 IOException (java.io.IOException)1 SkipException (org.testng.SkipException)1