protected Map<String, String> startupConfigProperties() {
return uniqueStartupConfigProperties(PostgresMTBase.class);
}
protected Connection createConnection() throws SQLException {
PostgresServer server = serviceManager().getServiceByClass(PostgresService.class).getServer();
int retry = 0;
while(!server.isListening()) {
if(retry == 1) {
LOG.warn("Postgres server not listening. Waiting...");
} else if(retry == 5) {
fail("Postgres server still not listening. Giving up.");
}
try {
Thread.sleep(200);
} catch(InterruptedException ex) {
LOG.error("caught an interrupted exception; re-interrupting", ex);
Thread.currentThread().interrupt();
}
++retry;
}
int port = server.getPort();
if(port <= 0) {
throw new IllegalStateException("port not set.");
}
String url = String.format(CONNECTION_URL, server.getHost(), port);
return DriverManager.getConnection(url, USER_NAME, USER_PASSWORD);
}