Search in sources :

Example 6 with MongodConfigBuilder

use of de.flapdoodle.embed.mongo.config.MongodConfigBuilder in project sling by apache.

the class SlingLaunchpadOakMongoIT method startMongo.

protected void startMongo(final int port) throws IOException {
    final MongodStarter starter = MongodStarter.getDefaultInstance();
    final Net net = new Net(port, Network.localhostIsIPv6());
    final IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.PRODUCTION).net(net).build();
    executable = starter.prepare(mongodConfig);
    process = executable.start();
}
Also used : MongodStarter(de.flapdoodle.embed.mongo.MongodStarter) IMongodConfig(de.flapdoodle.embed.mongo.config.IMongodConfig) Net(de.flapdoodle.embed.mongo.config.Net) MongodConfigBuilder(de.flapdoodle.embed.mongo.config.MongodConfigBuilder)

Example 7 with MongodConfigBuilder

use of de.flapdoodle.embed.mongo.config.MongodConfigBuilder in project jnosql-diana-driver by eclipse.

the class MongoDbHelper method startMongoDb.

public static void startMongoDb() throws IOException {
    _mongodExe = starter.prepare(new MongodConfigBuilder().version(Version.Main.PRODUCTION).net(new Net("localhost", 27017, Network.localhostIsIPv6())).build());
    _mongod = _mongodExe.start();
    _mongo = new MongoClient("localhost", 27017);
}
Also used : MongoClient(com.mongodb.MongoClient) Net(de.flapdoodle.embed.mongo.config.Net) MongodConfigBuilder(de.flapdoodle.embed.mongo.config.MongodConfigBuilder)

Example 8 with MongodConfigBuilder

use of de.flapdoodle.embed.mongo.config.MongodConfigBuilder in project logging-log4j2 by apache.

the class MongoDb3TestRule method apply.

@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            final String value = Objects.requireNonNull(System.getProperty(portSystemPropertyName), "System property '" + portSystemPropertyName + "' is null");
            final int port = Integer.parseInt(value);
            try {
                mongodExecutable = starter.prepare(// @formatter:off
                new MongodConfigBuilder().version(Version.Main.PRODUCTION).timeout(new Timeout(BUILDER_TIMEOUT_MILLIS)).net(new Net("localhost", port, Network.localhostIsIPv6())).build());
            // @formatter:on
            } catch (final IllegalArgumentException e) {
                if (e.getMessage().contains("this version does not support 32Bit")) {
                    throw new AssumptionViolatedException("Unsupported platform: " + e.getMessage());
                }
            }
            mongodProcess = mongodExecutable.start();
            mongoClient = new MongoClient("localhost", port);
            try {
                base.evaluate();
            } finally {
                if (mongodProcess != null) {
                    mongodProcess.stop();
                    mongodProcess = null;
                }
                if (mongodExecutable != null) {
                    mongodExecutable.stop();
                    mongodExecutable = null;
                }
            }
        }
    };
}
Also used : MongoClient(com.mongodb.MongoClient) AssumptionViolatedException(org.junit.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) Timeout(de.flapdoodle.embed.mongo.config.Timeout) Net(de.flapdoodle.embed.mongo.config.Net) MongodConfigBuilder(de.flapdoodle.embed.mongo.config.MongodConfigBuilder)

Example 9 with MongodConfigBuilder

use of de.flapdoodle.embed.mongo.config.MongodConfigBuilder in project logging-log4j2 by apache.

the class MongoDb4TestRule method apply.

@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            final String value = Objects.requireNonNull(System.getProperty(portSystemPropertyName), "System property '" + portSystemPropertyName + "' is null");
            final int port = Integer.parseInt(value);
            try {
                mongodExecutable = starter.prepare(// @formatter:off
                new MongodConfigBuilder().version(Version.Main.PRODUCTION).timeout(new Timeout(BUILDER_TIMEOUT_MILLIS)).net(new Net("localhost", port, Network.localhostIsIPv6())).build());
            // @formatter:on
            } catch (final IllegalArgumentException e) {
                if (e.getMessage().contains("this version does not support 32Bit")) {
                    throw new AssumptionViolatedException("Unsupported platform: " + e.getMessage());
                }
            }
            mongodProcess = mongodExecutable.start();
            mongoClient = MongoClients.create("mongodb://localhost:" + port);
            try {
                base.evaluate();
            } finally {
                if (mongodProcess != null) {
                    mongodProcess.stop();
                    mongodProcess = null;
                }
                if (mongodExecutable != null) {
                    mongodExecutable.stop();
                    mongodExecutable = null;
                }
            }
        }
    };
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) Timeout(de.flapdoodle.embed.mongo.config.Timeout) Net(de.flapdoodle.embed.mongo.config.Net) MongodConfigBuilder(de.flapdoodle.embed.mongo.config.MongodConfigBuilder)

Example 10 with MongodConfigBuilder

use of de.flapdoodle.embed.mongo.config.MongodConfigBuilder in project pinpoint by naver.

the class MongoDBITBase method startDB.

public void startDB() throws Exception {
    MongodStarter starter = MongodStarter.getDefaultInstance();
    IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.PRODUCTION).net(new Net(MongoDBITConstants.BIND_ADDRESS, MongoDBITConstants.PORT, Network.localhostIsIPv6())).build();
    MongodExecutable mongodExecutable = starter.prepare(mongodConfig);
    // replaced via awaitCompleted()
    // //give time for previous DB close to finish and port to be released"
    // Thread.sleep(200L);
    mongod = mongodExecutable.start();
    setClient();
}
Also used : MongodExecutable(de.flapdoodle.embed.mongo.MongodExecutable) MongodStarter(de.flapdoodle.embed.mongo.MongodStarter) IMongodConfig(de.flapdoodle.embed.mongo.config.IMongodConfig) Net(de.flapdoodle.embed.mongo.config.Net) MongodConfigBuilder(de.flapdoodle.embed.mongo.config.MongodConfigBuilder)

Aggregations

MongodConfigBuilder (de.flapdoodle.embed.mongo.config.MongodConfigBuilder)19 Net (de.flapdoodle.embed.mongo.config.Net)19 IMongodConfig (de.flapdoodle.embed.mongo.config.IMongodConfig)14 MongoClient (com.mongodb.MongoClient)8 Storage (de.flapdoodle.embed.mongo.config.Storage)7 MongoCmdOptionsBuilder (de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder)6 MongodStarter (de.flapdoodle.embed.mongo.MongodStarter)5 IOException (java.io.IOException)5 BeforeClass (org.junit.BeforeClass)5 Document (org.bson.Document)3 Before (org.junit.Before)3 DB (com.mongodb.DB)2 MongoDatabase (com.mongodb.client.MongoDatabase)2 GridFS (com.mongodb.gridfs.GridFS)2 GridFSInputFile (com.mongodb.gridfs.GridFSInputFile)2 MongodExecutable (de.flapdoodle.embed.mongo.MongodExecutable)2 RuntimeConfigBuilder (de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder)2 Timeout (de.flapdoodle.embed.mongo.config.Timeout)2 IRuntimeConfig (de.flapdoodle.embed.process.config.IRuntimeConfig)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2