ru.yandex.qatools.embed.postgresql.EmbeddedPostgres Java Examples

The following examples show how to use ru.yandex.qatools.embed.postgresql.EmbeddedPostgres. 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: YandexPostgresDatabaseProvider.java    From embedded-database-spring-test with Apache License 2.0 6 votes vote down vote up
private DatabaseInstance(DatabaseConfig config) throws IOException {
    Map<String, String> initdbProperties = new HashMap<>(config.initdbProperties);
    initdbProperties.putIfAbsent("encoding", "UTF-8");

    List<String> initdbParams = initdbProperties.entrySet().stream()
            .map(e -> String.format("--%s=%s", e.getKey(), e.getValue()))
            .collect(Collectors.toList());

    Map<String, String> serverProperties = new HashMap<>(config.configProperties);
    serverProperties.putIfAbsent("max_connections", "300");

    List<String> postgresParams = serverProperties.entrySet().stream()
            .flatMap(e -> Stream.of("-c", String.format("%s=%s", e.getKey(), e.getValue())))
            .collect(Collectors.toList());

    postgres = new EmbeddedPostgres(config.version);
    postgres.start(defaultRuntimeConfig(), DEFAULT_HOST, SocketUtil.findFreePort(),
            DEFAULT_DB_NAME, POSTGRES_USERNAME, POSTGRES_PASSWORD, initdbParams, postgresParams);

    Runtime.getRuntime().addShutdownHook(new Thread(postgres::close));

    semaphore = new Semaphore(Integer.parseInt(serverProperties.get("max_connections")));
}
 
Example #2
Source File: EmbeddedSupplier.java    From ndbc with Apache License 2.0 5 votes vote down vote up
@Override
public final DataSource<PreparedStatement, Row> get() {
  log.info("Starting embedded postgres " + version + " on port " + config.port());

  final EmbeddedPostgres postgres = new EmbeddedPostgres(version);

  final IRuntimeConfig cached = cachedRuntimeConfig(
      Paths.get(System.getProperty("user.home"), ".ndbc", "embedded_postgres"));

  final String password = config.password().orElseGet(() -> {
    throw new UnsupportedOperationException("Embedded postgres requires a password");
  });

  try {
    postgres.start(cached, config.host(), config.port(), config.database().orElse(EmbeddedPostgres.DEFAULT_DB_NAME),
        config.user(), password, DEFAULT_ADD_PARAMS);
  } catch (final IOException e) {
    throw new RuntimeException(e);
  }

  Runtime.getRuntime().addShutdownHook(new Thread(() -> postgres.stop()));

  log.info("postgres " + version + " started");

  final DataSource<PreparedStatement, Row> underlying = DataSource.fromConfig(config.embedded(Optional.empty()));
  return new ProxyDataSource<PreparedStatement, Row>(underlying) {
    @Override
    public Config config() {
      return EmbeddedSupplier.this.config;
    }
  };
}
 
Example #3
Source File: PostgresClient.java    From raml-module-builder with Apache License 2.0 4 votes vote down vote up
private static void rememberEmbeddedPostgres() {
   embeddedPostgres = new EmbeddedPostgres(Version.Main.V10);
}