21
21
import org .junit .jupiter .api .extension .AfterAllCallback ;
22
22
import org .junit .jupiter .api .extension .BeforeAllCallback ;
23
23
import org .junit .jupiter .api .extension .ExtensionContext ;
24
+ import org .slf4j .LoggerFactory ;
24
25
import org .springframework .jdbc .core .JdbcTemplate ;
25
26
import org .testcontainers .containers .Network ;
26
27
import org .testcontainers .containers .PostgreSQLContainer ;
28
+ import org .testcontainers .containers .output .Slf4jLogConsumer ;
27
29
import org .testcontainers .containers .wait .strategy .LogMessageWaitStrategy ;
30
+ import org .testcontainers .utility .DockerImageName ;
28
31
import org .testcontainers .utility .MountableFile ;
29
32
30
33
import java .net .URISyntaxException ;
@@ -118,18 +121,14 @@ private void startPrimary(Network network) {
118
121
}
119
122
120
123
private void startStandby (Network network ) {
121
- this .standby = new PostgreSQLContainer <> (PostgresqlServerExtension .IMAGE_NAME )
124
+ this .standby = new CustomPostgreSQLContainer (PostgresqlServerExtension .IMAGE_NAME )
122
125
.withNetwork (network )
123
126
.withCopyFileToContainer (getHostPath ("setup-standby.sh" , 0755 ), "/setup-standby.sh" )
124
127
.withCommand ("/setup-standby.sh" )
125
128
.withEnv ("PG_REP_USER" , "replication" )
126
129
.withEnv ("PG_REP_PASSWORD" , "replication_password" )
127
130
.withEnv ("PG_MASTER_HOST" , "postgres-primary" )
128
131
.withEnv ("PG_MASTER_PORT" , "5432" );
129
- this .standby .setWaitStrategy (new LogMessageWaitStrategy ()
130
- .withRegEx (".*database system is ready to accept .* connections.*\\ s" )
131
- .withTimes (1 )
132
- .withStartupTimeout (Duration .of (60L , ChronoUnit .SECONDS )));
133
132
this .standby .start ();
134
133
HikariConfig standbyConfig = new HikariConfig ();
135
134
standbyConfig .setJdbcUrl (this .standby .getJdbcUrl ());
@@ -138,4 +137,16 @@ private void startStandby(Network network) {
138
137
this .standbyDataSource = new HikariDataSource (standbyConfig );
139
138
}
140
139
140
+ // setWaitStrategy() doesn't seem to work, only inside constructor
141
+ static class CustomPostgreSQLContainer extends PostgreSQLContainer <CustomPostgreSQLContainer > {
142
+ public CustomPostgreSQLContainer (String dockerImageName ) {
143
+ super (DockerImageName .parse (dockerImageName ));
144
+ this .waitStrategy =
145
+ new LogMessageWaitStrategy ()
146
+ .withRegEx (".*database system is ready to accept .*connections.*\\ s" )
147
+ .withTimes (1 )
148
+ .withStartupTimeout (Duration .of (60L , ChronoUnit .SECONDS ));
149
+ }
150
+ }
151
+
141
152
}
0 commit comments