ru.yandex.qatools.embed.postgresql.config.PostgresConfig Java Examples

The following examples show how to use ru.yandex.qatools.embed.postgresql.config.PostgresConfig. 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 File: PostgresDatabase.java    From MegaSparkDiff with 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 File: DatabaseRule.java    From postgres-async-driver with 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());
        }
    }
}