Search in sources :

Example 1 with MongoDBContainer

use of org.testcontainers.containers.MongoDBContainer in project gora by apache.

the class GoraClientTest method setupMongoDBCluster.

/**
 * Setup MongoDB embed cluster. This function will auto provision a MongoDB
 * embeded cluster which will run locally on port 27017. It is called in the
 * {@link setUp() class} which is executed testUpdate after each test.
 */
private void setupMongoDBCluster() {
    try {
        if (!isMongoDBSetupDone) {
            mongo = new MongoDBContainer("mongo:3.6");
            mongo.start();
        }
        LOG.info("Started MongoDB Server on " + mongo.getReplicaSetUrl());
        isMongoDBSetupDone = true;
    } catch (Exception e) {
        LOG.info("Cannot Start MongoDB Server {}", e.getMessage(), e);
    }
}
Also used : MongoDBContainer(org.testcontainers.containers.MongoDBContainer) GoraException(org.apache.gora.util.GoraException)

Example 2 with MongoDBContainer

use of org.testcontainers.containers.MongoDBContainer in project drill by apache.

the class MongoBaseTest method initSingle.

private static String initSingle() {
    MongoDBContainer container = new MongoDBContainer(MONGO_IMAGE_NAME);
    container.start();
    containers.add(container);
    return String.format("mongodb://%s:%d", container.getContainerIpAddress(), container.getFirstMappedPort());
}
Also used : MongoDBContainer(org.testcontainers.containers.MongoDBContainer)

Example 3 with MongoDBContainer

use of org.testcontainers.containers.MongoDBContainer in project drill by apache.

the class MongoBaseTest method initMongos.

private static String initMongos(Network network) throws IOException, InterruptedException {
    String mongosHost = "m7";
    MongoDBContainer mongos = new MongoDBContainer(MONGO_IMAGE_NAME).withNetwork(network).withNetworkAliases(mongosHost).withExposedPorts(MONGO_PORT).withCommand(String.format("mongos --configdb %s/%s:%s --bind_ip " + "localhost,%s --port %3$s", CONFIG_REPL_SET, CONFIG_SERVER_HOST, MONGO_PORT, mongosHost));
    mongos.start();
    Container.ExecResult execResult = mongos.execInContainer("/bin/bash", "-c", String.format("echo 'sh.addShard(\"%s/m1,m2,m3\")' | mongo --port %s", SHARD_REPL_SET_0, MONGO_PORT));
    logger.debug(execResult.toString());
    execResult = mongos.execInContainer("/bin/bash", "-c", String.format("echo 'sh.addShard(\"%s/m4,m5,m6\")' | mongo --port %s", SHARD_REPL_SET_1, MONGO_PORT));
    logger.debug(execResult.toString());
    logger.debug("Execute list shards.");
    execResult = mongos.execInContainer("/bin/bash", "-c", "mongo --eval 'db" + ".adminCommand({ listShards: 1 })' --port " + MONGO_PORT);
    logger.debug(execResult.toString());
    containers.add(mongos);
    // the way how it work: client -> router(mongos) -> Shard1 ... ShardN
    return String.format("mongodb://%s:%s", mongos.getContainerIpAddress(), mongos.getMappedPort(MONGO_PORT));
}
Also used : MongoDBContainer(org.testcontainers.containers.MongoDBContainer) Container(org.testcontainers.containers.Container) MongoDBContainer(org.testcontainers.containers.MongoDBContainer) GenericContainer(org.testcontainers.containers.GenericContainer)

Aggregations

MongoDBContainer (org.testcontainers.containers.MongoDBContainer)3 GoraException (org.apache.gora.util.GoraException)1 Container (org.testcontainers.containers.Container)1 GenericContainer (org.testcontainers.containers.GenericContainer)1