Search in sources :

Example 1 with IRuntimeConfig

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

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

the class GoraMongodbAuthenticationTestDriver method runScriptAndWait.

private void runScriptAndWait(String scriptText, String token, String[] failures, String dbName, String username, String password) throws IOException {
    IStreamProcessor mongoOutput;
    if (!isEmpty(token)) {
        mongoOutput = new LogWatchStreamProcessor(token, (failures != null) ? new HashSet<>(asList(failures)) : Collections.emptySet(), namedConsole("[mongo shell output]"));
    } else {
        mongoOutput = new NamedOutputStreamProcessor("[mongo shell output]", console());
    }
    IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaults(Command.Mongo).processOutput(new ProcessOutput(mongoOutput, namedConsole("[mongo shell error]"), console())).build();
    MongoShellStarter starter = MongoShellStarter.getInstance(runtimeConfig);
    final File scriptFile = writeTmpScriptFile(scriptText);
    final MongoShellConfigBuilder builder = new MongoShellConfigBuilder();
    if (!isEmpty(dbName)) {
        builder.dbName(dbName);
    }
    if (!isEmpty(username)) {
        builder.username(username);
    }
    if (!isEmpty(password)) {
        builder.password(password);
    }
    starter.prepare(builder.scriptName(scriptFile.getAbsolutePath()).version(mongodConfig.version()).net(mongodConfig.net()).build()).start();
    if (mongoOutput instanceof LogWatchStreamProcessor) {
        ((LogWatchStreamProcessor) mongoOutput).waitForResult(INIT_TIMEOUT_MS);
    }
}
Also used : IStreamProcessor(de.flapdoodle.embed.process.io.IStreamProcessor) NamedOutputStreamProcessor(de.flapdoodle.embed.process.io.NamedOutputStreamProcessor) ProcessOutput(de.flapdoodle.embed.process.config.io.ProcessOutput) LogWatchStreamProcessor(de.flapdoodle.embed.process.io.LogWatchStreamProcessor) File(java.io.File) IRuntimeConfig(de.flapdoodle.embed.process.config.IRuntimeConfig)

Example 3 with IRuntimeConfig

use of de.flapdoodle.embed.process.config.IRuntimeConfig in project raml-module-builder by folio-org.

the class PostgresClient method startEmbeddedPostgres.

/**
 * Start an embedded PostgreSQL using the configuration of {@link #getConnectionConfig()}.
 * It also sets embedded mode to true, see {@link #setIsEmbedded(boolean)}, but
 * doesn't change the configuration.
 *
 * @throws IOException  when starting embedded PostgreSQL fails
 */
public void startEmbeddedPostgres() throws IOException {
    // starting Postgres
    embeddedMode = true;
    if (postgresProcess == null || !postgresProcess.isProcessRunning()) {
        // turns off the default functionality of unzipping on every run.
        IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaults(Command.Postgres).artifactStore(new NonCachedPostgresArtifactStoreBuilder().defaults(Command.Postgres).download(new PostgresDownloadConfigBuilder().defaultsForCommand(Command.Postgres).build())).build();
        PostgresStarter<PostgresExecutable, PostgresProcess> runtime = PostgresStarter.getInstance(runtimeConfig);
        int port = postgreSQLClientConfig.getInteger(PORT);
        String username = postgreSQLClientConfig.getString(_USERNAME);
        String password = postgreSQLClientConfig.getString(_PASSWORD);
        String database = postgreSQLClientConfig.getString(DATABASE);
        String locale = "en_US.UTF-8";
        String OS = System.getProperty("os.name").toLowerCase();
        if (OS.indexOf("win") >= 0) {
            locale = "american_usa";
        }
        final PostgresConfig config = new PostgresConfig(Version.Main.V10, new AbstractPostgresConfig.Net(DEFAULT_IP, port), new AbstractPostgresConfig.Storage(database), new AbstractPostgresConfig.Timeout(20000), new AbstractPostgresConfig.Credentials(username, password));
        config.getAdditionalInitDbParams().addAll(Arrays.asList("-E", "UTF-8", "--locale", locale));
        postgresProcess = runtime.prepare(config).start();
        log.info("embedded postgress started....");
    } else {
        log.info("embedded postgress is already running...");
    }
}
Also used : PostgresConfig(ru.yandex.qatools.embed.postgresql.config.PostgresConfig) AbstractPostgresConfig(ru.yandex.qatools.embed.postgresql.config.AbstractPostgresConfig) NonCachedPostgresArtifactStoreBuilder(de.flapdoodle.embed.process.store.NonCachedPostgresArtifactStoreBuilder) PostgresExecutable(ru.yandex.qatools.embed.postgresql.PostgresExecutable) PostgresProcess(ru.yandex.qatools.embed.postgresql.PostgresProcess) IRuntimeConfig(de.flapdoodle.embed.process.config.IRuntimeConfig) AbstractPostgresConfig(ru.yandex.qatools.embed.postgresql.config.AbstractPostgresConfig) PostgresDownloadConfigBuilder(ru.yandex.qatools.embed.postgresql.config.PostgresDownloadConfigBuilder) RuntimeConfigBuilder(ru.yandex.qatools.embed.postgresql.config.RuntimeConfigBuilder)

Example 4 with IRuntimeConfig

use of de.flapdoodle.embed.process.config.IRuntimeConfig in project logging-log4j2 by apache.

the class MongoDb3TestRule method getMongodStarter.

private static MongodStarter getMongodStarter(final LoggingTarget loggingTarget) {
    if (loggingTarget == null) {
        return MongodStarter.getDefaultInstance();
    }
    switch(loggingTarget) {
        case NULL:
            final Logger logger = LoggerFactory.getLogger(MongoDb3TestRule.class.getName());
            final IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, logger).processOutput(ProcessOutput.getDefaultInstanceSilent()).build();
            return MongodStarter.getInstance(runtimeConfig);
        case CONSOLE:
            return MongodStarter.getDefaultInstance();
        default:
            throw new NotImplementedException(loggingTarget.toString());
    }
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) Logger(org.slf4j.Logger) IRuntimeConfig(de.flapdoodle.embed.process.config.IRuntimeConfig) RuntimeConfigBuilder(de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder)

Example 5 with IRuntimeConfig

use of de.flapdoodle.embed.process.config.IRuntimeConfig in project logging-log4j2 by apache.

the class MongoDb4TestRule method getMongodStarter.

private static MongodStarter getMongodStarter(final LoggingTarget loggingTarget) {
    if (loggingTarget == null) {
        return MongodStarter.getDefaultInstance();
    }
    switch(loggingTarget) {
        case NULL:
            final Logger logger = LoggerFactory.getLogger(MongoDb4TestRule.class.getName());
            final IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, logger).processOutput(ProcessOutput.getDefaultInstanceSilent()).build();
            return MongodStarter.getInstance(runtimeConfig);
        case CONSOLE:
            return MongodStarter.getDefaultInstance();
        default:
            throw new NotImplementedException(loggingTarget.toString());
    }
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) Logger(org.slf4j.Logger) IRuntimeConfig(de.flapdoodle.embed.process.config.IRuntimeConfig) RuntimeConfigBuilder(de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder)

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