Search in sources :

Example 1 with MongodStarter

use of de.flapdoodle.embed.mongo.MongodStarter in project gora by apache.

the class GoraMongodbTestDriver method setUpClass.

/**
   * Initiate the MongoDB server on the default port
   */
@Override
public void setUpClass() throws IOException {
    IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, log).processOutput(ProcessOutput.getDefaultInstanceSilent()).build();
    MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);
    int port = Network.getFreeServerPort();
    IMongodConfig mongodConfig = new MongodConfigBuilder().version(version).net(new Net(port, Network.localhostIsIPv6())).build();
    // Store Mongo server "host:port" in Hadoop configuration
    // so that MongoStore will be able to get it latter
    conf.set(MongoStoreParameters.PROP_MONGO_SERVERS, "127.0.0.1:" + port);
    log.info("Starting embedded Mongodb server on {} port.", port);
    try {
        _mongodExe = runtime.prepare(mongodConfig);
        _mongod = _mongodExe.start();
        _mongo = new MongoClient("localhost", port);
    } catch (Exception e) {
        log.error("Error starting embedded Mongodb server... tearing down test driver.");
        tearDownClass();
    }
}
Also used : MongoClient(com.mongodb.MongoClient) 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) IOException(java.io.IOException) IRuntimeConfig(de.flapdoodle.embed.process.config.IRuntimeConfig) RuntimeConfigBuilder(de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder)

Example 2 with MongodStarter

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

the class SlingLaunchpadNosqlMongoIT 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 3 with MongodStarter

use of de.flapdoodle.embed.mongo.MongodStarter 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 4 with MongodStarter

use of de.flapdoodle.embed.mongo.MongodStarter 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 5 with MongodStarter

use of de.flapdoodle.embed.mongo.MongodStarter in project spring-boot by spring-projects.

the class EmbeddedMongoAutoConfiguration method embeddedMongoServer.

@Bean(initMethod = "start", destroyMethod = "stop")
@ConditionalOnMissingBean
public MongodExecutable embeddedMongoServer(IMongodConfig mongodConfig) throws IOException {
    Integer configuredPort = this.properties.getPort();
    if (configuredPort == null || configuredPort == 0) {
        setEmbeddedPort(mongodConfig.net().getPort());
    }
    MongodStarter mongodStarter = getMongodStarter(this.runtimeConfig);
    return mongodStarter.prepare(mongodConfig);
}
Also used : MongodStarter(de.flapdoodle.embed.mongo.MongodStarter) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ReactiveMongoClientFactoryBean(org.springframework.data.mongodb.core.ReactiveMongoClientFactoryBean) MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

MongodStarter (de.flapdoodle.embed.mongo.MongodStarter)8 IMongodConfig (de.flapdoodle.embed.mongo.config.IMongodConfig)5 MongodConfigBuilder (de.flapdoodle.embed.mongo.config.MongodConfigBuilder)5 Net (de.flapdoodle.embed.mongo.config.Net)5 MongoClient (com.mongodb.MongoClient)3 MongodExecutable (de.flapdoodle.embed.mongo.MongodExecutable)2 IRuntimeConfig (de.flapdoodle.embed.process.config.IRuntimeConfig)2 IOException (java.io.IOException)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 Bean (org.springframework.context.annotation.Bean)2 MongoClientFactoryBean (org.springframework.data.mongodb.core.MongoClientFactoryBean)2 ReactiveMongoClientFactoryBean (org.springframework.data.mongodb.core.ReactiveMongoClientFactoryBean)2 MongoDatabase (com.mongodb.client.MongoDatabase)1 RuntimeConfigBuilder (de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder)1 HashMap (java.util.HashMap)1 Document (org.bson.Document)1