1919import io .vertx .core .net .JksOptions ;
2020import io .vertx .db2client .DB2ConnectOptions ;
2121import org .junit .rules .ExternalResource ;
22- import org .testcontainers .containers .Db2Container ;
22+ import org .testcontainers .containers .GenericContainer ;
23+ import org .testcontainers .containers .InternetProtocol ;
2324import org .testcontainers .containers .wait .strategy .LogMessageWaitStrategy ;
2425
2526import java .nio .file .Files ;
@@ -45,12 +46,25 @@ public class DB2Resource extends ExternalResource {
4546 private boolean started = false ;
4647 private boolean isDb2OnZ = false ;
4748 private DB2ConnectOptions options ;
48- private final Db2Container instance = new Db2Container ("ibmcom/db2:11.5.0.0a" )
49- .acceptLicense ()
49+ private final String database = "vertx" ;
50+ private final String user = "vertx" ;
51+ private final String password = "vertx" ;
52+ private final ServerContainer instance = new ServerContainer ("ibmcom/db2:11.5.0.0a" ) {
53+ @ Override
54+ protected void configure () {
55+ this .addEnv ("LICENSE" , "accept" );
56+ this .addEnv ("DBNAME" , database );
57+ this .addEnv ("DB2INSTANCE" , user );
58+ this .addEnv ("DB2INST1_PASSWORD" , password );
59+ if (!this .getEnvMap ().containsKey ("AUTOCONFIG" )) {
60+ this .addEnv ("AUTOCONFIG" , "false" );
61+ }
62+ if (!this .getEnvMap ().containsKey ("ARCHIVE_LOGS" )) {
63+ this .addEnv ("ARCHIVE_LOGS" , "false" );
64+ }
65+ }
66+ }
5067 .withLogConsumer (out -> System .out .print ("[DB2] " + out .getUtf8String ()))
51- .withUsername ("vertx" )
52- .withPassword ("vertx" )
53- .withDatabaseName ("vertx" )
5468 .withExposedPorts (50000 , 50001 )
5569 .withFileSystemBind ("src/test/resources/tls/server/" , "/certs/" )
5670 .withFileSystemBind ("src/test/resources/tls/db2_tls_setup.sh" , "/var/custom/db2_tls_setup.sh" )
@@ -69,9 +83,9 @@ protected void before() throws Throwable {
6983 options = new DB2ConnectOptions ()
7084 .setHost (instance .getHost ())
7185 .setPort (instance .getMappedPort (50000 ))
72- .setDatabase (instance . getDatabaseName () )
73- .setUser (instance . getUsername () )
74- .setPassword (instance . getPassword () );
86+ .setDatabase (database )
87+ .setUser (user )
88+ .setPassword (password );
7589 } else {
7690 System .out .println ("Using custom DB2 instance as requested via DB2_HOST=" + get ("DB2_HOST" ));
7791 Objects .requireNonNull (get ("DB2_PORT" ), "Must set DB2_PORT to a non-null value if DB2_HOST is set" );
@@ -143,4 +157,15 @@ private void runInitSql(Connection con) throws Exception {
143157 }
144158 }
145159
160+ private class ServerContainer extends GenericContainer <ServerContainer > {
161+
162+ public ServerContainer (String dockerImageName ) {
163+ super (dockerImageName );
164+ }
165+
166+ public ServerContainer withFixedExposedPort (int hostPort , int containerPort ) {
167+ super .addFixedExposedPort (hostPort , containerPort , InternetProtocol .TCP );
168+ return self ();
169+ }
170+ }
146171}
0 commit comments