Search in sources :

Example 1 with PostgresDownloadConfigBuilder

use of ru.yandex.qatools.embed.postgresql.config.PostgresDownloadConfigBuilder 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 2 with PostgresDownloadConfigBuilder

use of ru.yandex.qatools.embed.postgresql.config.PostgresDownloadConfigBuilder 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 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 ProcessOutput (de.flapdoodle.embed.process.config.io.ProcessOutput)1 IDownloadConfig (de.flapdoodle.embed.process.config.store.IDownloadConfig)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 NonCachedPostgresArtifactStoreBuilder (de.flapdoodle.embed.process.store.NonCachedPostgresArtifactStoreBuilder)1 PostgresArtifactStoreBuilder (de.flapdoodle.embed.process.store.PostgresArtifactStoreBuilder)1 Command (ru.yandex.qatools.embed.postgresql.Command)1 PostgresStarter (ru.yandex.qatools.embed.postgresql.PostgresStarter)1 LogWatchStreamProcessor (ru.yandex.qatools.embed.postgresql.ext.LogWatchStreamProcessor)1