Search in sources :

Example 1 with MongodExecutable

use of de.flapdoodle.embed.mongo.MongodExecutable 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)

Example 2 with MongodExecutable

use of de.flapdoodle.embed.mongo.MongodExecutable in project embedmongo-maven-plugin by joelittlejohn.

the class StartMojo method executeStart.

@Override
@SuppressWarnings("unchecked")
public void executeStart() throws MojoExecutionException, MojoFailureException {
    MongodExecutable executable;
    try {
        final List<String> mongodArgs = this.createMongodArgsList();
        final ICommandLinePostProcessor commandLinePostProcessor = new ICommandLinePostProcessor() {

            @Override
            public List<String> process(final Distribution distribution, final List<String> args) {
                args.addAll(mongodArgs);
                return args;
            }
        };
        IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaults(Command.MongoD).processOutput(getOutputConfig()).artifactStore(getArtifactStore()).commandLinePostProcessor(commandLinePostProcessor).build();
        int port = getPort();
        if (isRandomPort()) {
            port = NetworkUtils.allocateRandomPort();
        }
        savePortToProjectProperties(port);
        IMongodConfig config = new MongodConfigBuilder().version(getVersion()).net(new Net(bindIp, port, NetworkUtils.localhostIsIPv6())).replication(new Storage(getDataDirectory(), null, 0)).cmdOptions(new MongoCmdOptionsBuilder().enableAuth(authEnabled).useNoJournal(!journal).useStorageEngine(storageEngine).build()).build();
        executable = MongodStarter.getInstance(runtimeConfig).prepare(config);
    } catch (DistributionException e) {
        throw new MojoExecutionException("Failed to download MongoDB distribution: " + e.withDistribution(), e);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to Config MongoDB: ", e);
    }
    try {
        MongodProcess mongod = executable.start();
        if (isWait()) {
            while (true) {
                try {
                    TimeUnit.MINUTES.sleep(5);
                } catch (InterruptedException e) {
                    break;
                }
            }
        }
        getPluginContext().put(MONGOD_CONTEXT_PROPERTY_NAME, mongod);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to start the mongod", e);
    }
}
Also used : ICommandLinePostProcessor(de.flapdoodle.embed.process.runtime.ICommandLinePostProcessor) MongodExecutable(de.flapdoodle.embed.mongo.MongodExecutable) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) IRuntimeConfig(de.flapdoodle.embed.process.config.IRuntimeConfig) Storage(de.flapdoodle.embed.mongo.config.Storage) Distribution(de.flapdoodle.embed.process.distribution.Distribution) MongodProcess(de.flapdoodle.embed.mongo.MongodProcess) IMongodConfig(de.flapdoodle.embed.mongo.config.IMongodConfig) ArrayList(java.util.ArrayList) List(java.util.List) DistributionException(de.flapdoodle.embed.process.exceptions.DistributionException) Net(de.flapdoodle.embed.mongo.config.Net) MongodConfigBuilder(de.flapdoodle.embed.mongo.config.MongodConfigBuilder) MongoCmdOptionsBuilder(de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder) RuntimeConfigBuilder(de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder)

Example 3 with MongodExecutable

use of de.flapdoodle.embed.mongo.MongodExecutable in project modesti by jlsalmon.

the class MongoConfig method embeddedMongo.

private Mongo embeddedMongo() throws IOException {
    int port = 12345;
    MongodConfigBuilder builder = new MongodConfigBuilder().version(Version.Main.PRODUCTION).net(new Net(port, Network.localhostIsIPv6()));
    if (env.containsProperty("mongodb.persistent") && env.getProperty("mongodb.persistent", Boolean.class).equals(true)) {
        builder.replication(new Storage("/tmp/mongodb-embedded", null, 0));
    }
    IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, log).processOutput(ProcessOutput.getDefaultInstanceSilent()).build();
    MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);
    MongodExecutable mongodExecutable = runtime.prepare(builder.build());
    mongodExecutable.start();
    return new MongoClient("localhost", port);
}
Also used : MongoClient(com.mongodb.MongoClient) MongodExecutable(de.flapdoodle.embed.mongo.MongodExecutable) MongodStarter(de.flapdoodle.embed.mongo.MongodStarter) IRuntimeConfig(de.flapdoodle.embed.process.config.IRuntimeConfig)

Aggregations

MongodExecutable (de.flapdoodle.embed.mongo.MongodExecutable)3 MongodStarter (de.flapdoodle.embed.mongo.MongodStarter)2 IMongodConfig (de.flapdoodle.embed.mongo.config.IMongodConfig)2 MongodConfigBuilder (de.flapdoodle.embed.mongo.config.MongodConfigBuilder)2 Net (de.flapdoodle.embed.mongo.config.Net)2 IRuntimeConfig (de.flapdoodle.embed.process.config.IRuntimeConfig)2 MongoClient (com.mongodb.MongoClient)1 MongodProcess (de.flapdoodle.embed.mongo.MongodProcess)1 MongoCmdOptionsBuilder (de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder)1 RuntimeConfigBuilder (de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder)1 Storage (de.flapdoodle.embed.mongo.config.Storage)1 Distribution (de.flapdoodle.embed.process.distribution.Distribution)1 DistributionException (de.flapdoodle.embed.process.exceptions.DistributionException)1 ICommandLinePostProcessor (de.flapdoodle.embed.process.runtime.ICommandLinePostProcessor)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1