Search in sources :

Example 1 with ProcessOutput

use of de.flapdoodle.embed.process.config.io.ProcessOutput 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 2 with ProcessOutput

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

Aggregations

IRuntimeConfig (de.flapdoodle.embed.process.config.IRuntimeConfig)2 ProcessOutput (de.flapdoodle.embed.process.config.io.ProcessOutput)2 IDownloadConfig (de.flapdoodle.embed.process.config.store.IDownloadConfig)1 IStreamProcessor (de.flapdoodle.embed.process.io.IStreamProcessor)1 LogWatchStreamProcessor (de.flapdoodle.embed.process.io.LogWatchStreamProcessor)1 NamedOutputStreamProcessor (de.flapdoodle.embed.process.io.NamedOutputStreamProcessor)1 Slf4jStreamProcessor (de.flapdoodle.embed.process.io.Slf4jStreamProcessor)1 FixedPath (de.flapdoodle.embed.process.io.directories.FixedPath)1 ArtifactStoreBuilder (de.flapdoodle.embed.process.store.ArtifactStoreBuilder)1 PostgresArtifactStoreBuilder (de.flapdoodle.embed.process.store.PostgresArtifactStoreBuilder)1 File (java.io.File)1 Command (ru.yandex.qatools.embed.postgresql.Command)1 PostgresExecutable (ru.yandex.qatools.embed.postgresql.PostgresExecutable)1 PostgresProcess (ru.yandex.qatools.embed.postgresql.PostgresProcess)1 PostgresStarter (ru.yandex.qatools.embed.postgresql.PostgresStarter)1 AbstractPostgresConfig (ru.yandex.qatools.embed.postgresql.config.AbstractPostgresConfig)1 PostgresConfig (ru.yandex.qatools.embed.postgresql.config.PostgresConfig)1 PostgresDownloadConfigBuilder (ru.yandex.qatools.embed.postgresql.config.PostgresDownloadConfigBuilder)1 RuntimeConfigBuilder (ru.yandex.qatools.embed.postgresql.config.RuntimeConfigBuilder)1 LogWatchStreamProcessor (ru.yandex.qatools.embed.postgresql.ext.LogWatchStreamProcessor)1