Search in sources :

Example 6 with IRuntimeConfig

use of de.flapdoodle.embed.process.config.IRuntimeConfig in project gora by apache.

the class GoraMongodbAuthenticationTestDriver method doStart.

private void doStart() throws Exception {
    IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, log).processOutput(ProcessOutput.getDefaultInstanceSilent()).build();
    runtime = MongodStarter.getInstance(runtimeConfig);
    try {
        log.info("Starting the mongo server without authentications");
        startWithAuth();
        log.info("Adding admin user");
        addAdmin();
        if (this.authMechanisms.equals("SCRAM-SHA-1")) {
            setSCRAM_SHA_1Credentials();
        }
        if (this.authMechanisms.equals("MONGODB-CR")) {
            setMongoDB_CRCredentials();
            tearDownClass();
            auth = true;
            startWithAuth();
            addAdmin();
        }
        // 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);
        conf.set(MongoStoreParameters.PROP_MONGO_DB, "admin");
        conf.set(MongoStoreParameters.PROP_MONGO_AUTHENTICATION_TYPE, this.authMechanisms);
        conf.set(MongoStoreParameters.PROP_MONGO_LOGIN, adminUsername);
        conf.set(MongoStoreParameters.PROP_MONGO_SECRET, adminPassword);
    } catch (Exception e) {
        log.error("Error starting embedded Mongodb server... tearing down test driver.");
        tearDownClass();
    }
}
Also used : IOException(java.io.IOException) IRuntimeConfig(de.flapdoodle.embed.process.config.IRuntimeConfig)

Example 7 with IRuntimeConfig

use of de.flapdoodle.embed.process.config.IRuntimeConfig in project gradle-postgresql-embedded by honourednihilist.

the class EmbeddedPostgres method start.

public synchronized void start() throws IOException {
    if (process != null) {
        throw new IllegalStateException();
    }
    Command command = Command.Postgres;
    IDownloadConfig downloadConfig = new PostgresDownloadConfigBuilder().defaultsForCommand(command).artifactStorePath(new FixedPath(artifactStorePath)).build();
    ArtifactStoreBuilder artifactStoreBuilder = new PostgresArtifactStoreBuilder().defaults(command).download(downloadConfig);
    LogWatchStreamProcessor logWatch = new LogWatchStreamProcessor("started", new HashSet<>(singletonList("failed")), new Slf4jStreamProcessor(getLogger("postgres"), Slf4jLevel.TRACE));
    IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaults(command).processOutput(new ProcessOutput(logWatch, logWatch, logWatch)).artifactStore(artifactStoreBuilder).build();
    PostgresStarter<PostgresExecutable, PostgresProcess> starter = new PostgresStarter<>(PostgresExecutable.class, runtimeConfig);
    PostgresConfig config = new PostgresConfig(version, new AbstractPostgresConfig.Net(host, port == 0 ? Network.getFreeServerPort() : port), new AbstractPostgresConfig.Storage(dbName), new AbstractPostgresConfig.Timeout(), new AbstractPostgresConfig.Credentials(username, password));
    process = starter.prepare(config).start();
    jdbcUrl = "jdbc:postgresql://" + config.net().host() + ":" + config.net().port() + "/" + config.storage().dbName();
}
Also used : PostgresConfig(ru.yandex.qatools.embed.postgresql.config.PostgresConfig) AbstractPostgresConfig(ru.yandex.qatools.embed.postgresql.config.AbstractPostgresConfig) IDownloadConfig(de.flapdoodle.embed.process.config.store.IDownloadConfig) FixedPath(de.flapdoodle.embed.process.io.directories.FixedPath) PostgresArtifactStoreBuilder(de.flapdoodle.embed.process.store.PostgresArtifactStoreBuilder) LogWatchStreamProcessor(ru.yandex.qatools.embed.postgresql.ext.LogWatchStreamProcessor) ArtifactStoreBuilder(de.flapdoodle.embed.process.store.ArtifactStoreBuilder) PostgresArtifactStoreBuilder(de.flapdoodle.embed.process.store.PostgresArtifactStoreBuilder) PostgresExecutable(ru.yandex.qatools.embed.postgresql.PostgresExecutable) PostgresProcess(ru.yandex.qatools.embed.postgresql.PostgresProcess) IRuntimeConfig(de.flapdoodle.embed.process.config.IRuntimeConfig) PostgresStarter(ru.yandex.qatools.embed.postgresql.PostgresStarter) AbstractPostgresConfig(ru.yandex.qatools.embed.postgresql.config.AbstractPostgresConfig) Command(ru.yandex.qatools.embed.postgresql.Command) ProcessOutput(de.flapdoodle.embed.process.config.io.ProcessOutput) PostgresDownloadConfigBuilder(ru.yandex.qatools.embed.postgresql.config.PostgresDownloadConfigBuilder) Slf4jStreamProcessor(de.flapdoodle.embed.process.io.Slf4jStreamProcessor) RuntimeConfigBuilder(ru.yandex.qatools.embed.postgresql.config.RuntimeConfigBuilder)

Example 8 with IRuntimeConfig

use of de.flapdoodle.embed.process.config.IRuntimeConfig 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 9 with IRuntimeConfig

use of de.flapdoodle.embed.process.config.IRuntimeConfig 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

IRuntimeConfig (de.flapdoodle.embed.process.config.IRuntimeConfig)9 RuntimeConfigBuilder (de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder)4 IOException (java.io.IOException)3 MongoClient (com.mongodb.MongoClient)2 MongodExecutable (de.flapdoodle.embed.mongo.MongodExecutable)2 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 ProcessOutput (de.flapdoodle.embed.process.config.io.ProcessOutput)2 NotImplementedException (org.apache.commons.lang3.NotImplementedException)2 Logger (org.slf4j.Logger)2 PostgresExecutable (ru.yandex.qatools.embed.postgresql.PostgresExecutable)2 PostgresProcess (ru.yandex.qatools.embed.postgresql.PostgresProcess)2 AbstractPostgresConfig (ru.yandex.qatools.embed.postgresql.config.AbstractPostgresConfig)2 PostgresConfig (ru.yandex.qatools.embed.postgresql.config.PostgresConfig)2 PostgresDownloadConfigBuilder (ru.yandex.qatools.embed.postgresql.config.PostgresDownloadConfigBuilder)2 RuntimeConfigBuilder (ru.yandex.qatools.embed.postgresql.config.RuntimeConfigBuilder)2 MongodProcess (de.flapdoodle.embed.mongo.MongodProcess)1 MongoCmdOptionsBuilder (de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder)1