2020import io .vertx .sqlclient .PoolOptions ;
2121import org .junit .rules .ExternalResource ;
2222import org .testcontainers .containers .BindMode ;
23+ import org .testcontainers .containers .GenericContainer ;
2324import org .testcontainers .containers .InternetProtocol ;
24- import org .testcontainers .containers .PostgreSQLContainer ;
25+ import org .testcontainers .containers .wait . strategy . LogMessageWaitStrategy ;
2526
26- import static org .testcontainers .containers .PostgreSQLContainer .POSTGRESQL_PORT ;
27+ import java .time .Duration ;
28+ import java .time .temporal .ChronoUnit ;
29+
30+ import static io .vertx .pgclient .PgConnectOptions .DEFAULT_PORT ;
2731
2832/**
2933 * Postgresql test database based on https://www.testcontainers.org
@@ -73,9 +77,14 @@ public ContainerPgRule user(String user) {
7377
7478 private void initServer (String version ) throws Exception {
7579 server = new ServerContainer <>("postgres:" + version )
76- .withDatabaseName ("postgres" )
77- .withUsername (user )
78- .withPassword ("postgres" )
80+ .withEnv ("POSTGRES_DB" , "postgres" )
81+ .withEnv ("POSTGRES_USER" , user )
82+ .withEnv ("POSTGRES_PASSWORD" , "postgres" )
83+ .waitingFor (new LogMessageWaitStrategy ()
84+ .withRegEx (".*database system is ready to accept connections.*\\ s" )
85+ .withTimes (2 )
86+ .withStartupTimeout (Duration .of (60 , ChronoUnit .SECONDS )))
87+ .withCommand ("postgres" , "-c" , "fsync=off" )
7988 .withClasspathResourceMapping ("create-postgres.sql" , "/docker-entrypoint-initdb.d/create-postgres.sql" , BindMode .READ_ONLY );
8089 if (ssl ) {
8190 server
@@ -89,9 +98,9 @@ private void initServer(String version) throws Exception {
8998 }
9099 }
91100 if (System .getProperties ().containsKey ("containerFixedPort" )) {
92- server .withFixedExposedPort (POSTGRESQL_PORT , POSTGRESQL_PORT );
101+ server .withFixedExposedPort (DEFAULT_PORT , DEFAULT_PORT );
93102 } else {
94- server .withExposedPorts (POSTGRESQL_PORT );
103+ server .withExposedPorts (DEFAULT_PORT );
95104 }
96105 }
97106
@@ -108,7 +117,7 @@ public synchronized PgConnectOptions startServer(String databaseVersion) throws
108117 server .start ();
109118
110119 return new PgConnectOptions ()
111- .setPort (server .getMappedPort (POSTGRESQL_PORT ))
120+ .setPort (server .getMappedPort (DEFAULT_PORT ))
112121 .setHost (server .getHost ())
113122 .setDatabase ("postgres" )
114123 .setUser (user )
@@ -183,7 +192,7 @@ protected void after() {
183192 }
184193 }
185194
186- private static class ServerContainer <SELF extends ServerContainer <SELF >> extends PostgreSQLContainer <SELF > {
195+ private static class ServerContainer <SELF extends ServerContainer <SELF >> extends GenericContainer <SELF > {
187196
188197 public ServerContainer (String dockerImageName ) {
189198 super (dockerImageName );
0 commit comments