Java Code Examples for ru.yandex.qatools.embed.postgresql.PostgresProcess

The following examples show how to use ru.yandex.qatools.embed.postgresql.PostgresProcess. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: MegaSparkDiff   Source File: PostgresDatabase.java    License: Apache License 2.0 6 votes vote down vote up
public static void startPostgres() throws IOException {
  IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
      .defaults(Command.Postgres)
      .build();

  PostgresStarter<PostgresExecutable, PostgresProcess> runtime = PostgresStarter.getInstance(runtimeConfig);

  PostgresConfig config = new PostgresConfig(
      () -> "9.6.3-1",
      new Net(),
      new Storage("src/test/resources/sample"),
      new Timeout(),
      new Credentials("username", "password"));

  PostgresExecutable exec = runtime.prepare(config);
  process = exec.start();

  properties.setProperty("user", config.credentials().username());
  properties.setProperty("password", config.credentials().password());

  url = java.lang.String.format("jdbc:postgresql://%s:%s/%s",
      config.net().host(),
      config.net().port(),
      config.storage().dbName());
}
 
Example 2
Source Project: raml-module-builder   Source File: PostgresClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * .sql files
 * @param path
 */
public void importFileEmbedded(String path) {
  // starting Postgres
  if (embeddedMode) {
    if (embeddedPostgres != null) {
      Optional<PostgresProcess> optionalPostgresProcess = embeddedPostgres.getProcess();
      if (optionalPostgresProcess.isPresent()) {
        log.info("embedded postgress import starting....");
        PostgresProcess postgresProcess = optionalPostgresProcess.get();
        postgresProcess.importFromFile(new File(path));
        log.info("embedded postgress import complete....");
      } else {
        log.warn("embedded postgress is not running...");
      }
    } else {
      log.info("embedded postgress not enabled");
    }
  }
}
 
Example 3
Source Project: postgres-async-driver   Source File: DatabaseRule.java    License: Apache License 2.0 5 votes vote down vote up
DatabaseRule(NettyConnectibleBuilder builder) {
    this.builder = builder;
    if (builder instanceof EmbeddedConnectionPoolBuilder) {
        String port = System.getProperty("asyncpg.test.postgres.port");
        if (port != null && !port.isBlank()) {
            builder.hostname("localhost");
            builder.port(Integer.valueOf(port));
        } else {
            if (process == null) {
                try {
                    PostgresStarter<PostgresExecutable, PostgresProcess> runtime = PostgresStarter.getDefaultInstance();
                    PostgresConfig config = new PostgresConfig(Version.V11_1, new AbstractPostgresConfig.Net(),
                            new AbstractPostgresConfig.Storage("async-pg"), new AbstractPostgresConfig.Timeout(),
                            new AbstractPostgresConfig.Credentials("async-pg", "async-pg"));
                    PostgresExecutable exec = runtime.prepare(config);
                    process = exec.start();

                    System.out.printf("Started postgres to %s:%d%n", process.getConfig().net().host(), process.getConfig().net().port());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            builder.hostname(process.getConfig().net().host());
            builder.port(process.getConfig().net().port());
        }
    }
}