@@ -66,7 +66,7 @@ public class EmbeddedPostgres implements Closeable {
66
66
static final String DOCKER_DEFAULT_TAG = "13-alpine" ;
67
67
// Note you can override any of these defaults explicitly in the builder.
68
68
69
- private final PostgreSQLContainer <?> postgreDBContainer ;
69
+ private final PostgreSQLContainer <?> postgreSQLContainer ;
70
70
71
71
private final UUID instanceId = UUID .randomUUID ();
72
72
@@ -79,7 +79,7 @@ public class EmbeddedPostgres implements Closeable {
79
79
OptionalInt fixedPort ,
80
80
DockerImageName image ,
81
81
String databaseName
82
- ) throws IOException {
82
+ ) {
83
83
this (postgresConfig , localeConfig , bindMounts , network , networkAlias , fixedPort , image , DEFAULT_PG_STARTUP_WAIT , databaseName );
84
84
}
85
85
@@ -93,18 +93,18 @@ public class EmbeddedPostgres implements Closeable {
93
93
Duration pgStartupWait ,
94
94
String databaseName
95
95
) {
96
- LOG .trace ("Starting containers with image {}, pgConfig {}, localeConfig {}, bindMounts {}, pgStartupWait {}, dbName {} " , image ,
97
- postgresConfig , localeConfig , bindMounts , pgStartupWait , databaseName );
96
+ if (LOG .isTraceEnabled ()) {
97
+ LOG .trace ("Starting containers with image {}, pgConfig {}, localeConfig {}, " +
98
+ "bindMounts {}, pgStartupWait {}, dbName {} " , image ,
99
+ postgresConfig , localeConfig , bindMounts , pgStartupWait , databaseName );
100
+ }
98
101
image = image .asCompatibleSubstituteFor (POSTGRES );
99
- final FixedPostgresSQLContainer pgContainer = new FixedPostgresSQLContainer (image ); //NOPMD
100
- fixedPort .ifPresent (p -> {
101
- // This would be exposed via a builder method
102
- LOG .warn ("Exposing a fixed port {} which kind of sucks," , p );
102
+ final FixedPostgresSQLContainer <?> pgContainer = new FixedPostgresSQLContainer <>(image ); //NOPMD
103
+ fixedPort .ifPresent (p -> {
104
+ LOG .warn ("Exposing a fixed port {} which is NOT recommended." , p );
103
105
pgContainer .addFixedExposedPort (p , POSTGRESQL_PORT );
104
106
});
105
-
106
- //TODO: generics are still mucked up
107
- this .postgreDBContainer = ((PostgreSQLContainer <?>) pgContainer )
107
+ this .postgreSQLContainer = pgContainer
108
108
.withDatabaseName (databaseName )
109
109
.withUsername (POSTGRES )
110
110
.withPassword (POSTGRES )
@@ -115,11 +115,11 @@ public class EmbeddedPostgres implements Closeable {
115
115
.withEnv ("POSTGRES_HOST_AUTH_METHOD" , "trust" );
116
116
final List <String > cmd = new ArrayList <>(Collections .singletonList (POSTGRES ));
117
117
cmd .addAll (createConfigOptions (postgresConfig ));
118
- postgreDBContainer .setCommand (cmd .toArray (new String [0 ]));
119
- processBindMounts (postgreDBContainer , bindMounts );
120
- network .ifPresent (postgreDBContainer ::withNetwork );
121
- networkAlias .ifPresent (postgreDBContainer ::withNetworkAliases );
122
- postgreDBContainer .start ();
118
+ postgreSQLContainer .setCommand (cmd .toArray (new String [0 ]));
119
+ processBindMounts (postgreSQLContainer , bindMounts );
120
+ network .ifPresent (postgreSQLContainer ::withNetwork );
121
+ networkAlias .ifPresent (postgreSQLContainer ::withNetworkAliases );
122
+ postgreSQLContainer .start ();
123
123
}
124
124
125
125
private void processBindMounts (PostgreSQLContainer <?> postgreDBContainer , Map <String , BindMount > bindMounts ) {
@@ -148,19 +148,19 @@ private List<String> createInitOptions(final Map<String, String> localeConfig) {
148
148
}
149
149
150
150
public DataSource getTemplateDatabase () {
151
- return getDatabase (postgreDBContainer .getUsername (), "template1" );
151
+ return getDatabase (postgreSQLContainer .getUsername (), "template1" );
152
152
}
153
153
154
154
public DataSource getTemplateDatabase (Map <String , String > properties ) {
155
- return getDatabase (postgreDBContainer .getUsername (), "template1" , properties );
155
+ return getDatabase (postgreSQLContainer .getUsername (), "template1" , properties );
156
156
}
157
157
158
158
public DataSource getPostgresDatabase () {
159
- return getDatabase (postgreDBContainer .getUsername (), postgreDBContainer .getDatabaseName ());
159
+ return getDatabase (postgreSQLContainer .getUsername (), postgreSQLContainer .getDatabaseName ());
160
160
}
161
161
162
162
public DataSource getPostgresDatabase (Map <String , String > properties ) {
163
- return getDatabase (postgreDBContainer .getUsername (), postgreDBContainer .getDatabaseName (), properties );
163
+ return getDatabase (postgreSQLContainer .getUsername (), postgreSQLContainer .getDatabaseName (), properties );
164
164
}
165
165
166
166
public DataSource getDatabase (String userName , String dbName ) {
@@ -170,10 +170,10 @@ public DataSource getDatabase(String userName, String dbName) {
170
170
public DataSource getDatabase (String userName , String dbName , Map <String , String > properties ) {
171
171
final PGSimpleDataSource ds = new PGSimpleDataSource ();
172
172
173
- ds .setURL (postgreDBContainer .getJdbcUrl ());
173
+ ds .setURL (postgreSQLContainer .getJdbcUrl ());
174
174
ds .setDatabaseName (dbName );
175
175
ds .setUser (userName );
176
- ds .setPassword (postgreDBContainer .getPassword ());
176
+ ds .setPassword (postgreSQLContainer .getPassword ());
177
177
178
178
properties .forEach ((propertyKey , propertyValue ) -> {
179
179
try {
@@ -192,22 +192,22 @@ public DataSource getDatabase(String userName, String dbName, Map<String, String
192
192
*/
193
193
public String getJdbcUrl (String dbName ) {
194
194
try {
195
- return JdbcUrlUtils .replaceDatabase (postgreDBContainer .getJdbcUrl (), dbName );
195
+ return JdbcUrlUtils .replaceDatabase (postgreSQLContainer .getJdbcUrl (), dbName );
196
196
} catch (URISyntaxException e ) {
197
197
return null ;
198
198
}
199
199
}
200
200
201
201
public String getHost () {
202
- return postgreDBContainer .getContainerIpAddress ();
202
+ return postgreSQLContainer .getContainerIpAddress ();
203
203
}
204
204
public int getPort () {
205
- return postgreDBContainer .getMappedPort (POSTGRESQL_PORT );
205
+ return postgreSQLContainer .getMappedPort (POSTGRESQL_PORT );
206
206
}
207
207
208
208
@ Override
209
209
public void close () throws IOException {
210
- postgreDBContainer .close ();
210
+ postgreSQLContainer .close ();
211
211
}
212
212
213
213
public static EmbeddedPostgres start () throws IOException {
@@ -219,11 +219,11 @@ public static EmbeddedPostgres.Builder builder() {
219
219
}
220
220
221
221
public String getUserName () {
222
- return postgreDBContainer .getUsername ();
222
+ return postgreSQLContainer .getUsername ();
223
223
}
224
224
225
225
public String getPassword () {
226
- return postgreDBContainer .getPassword ();
226
+ return postgreSQLContainer .getPassword ();
227
227
}
228
228
229
229
public static class Builder {
0 commit comments