Skip to content

Commit 55290d0

Browse files
committed
Speed up DB2 client tests (#1655)
This commit modernizes the DB2 client test infrastructure by: - upgrading to the community image icr.io/db2_community/db2:12.1.4.0 - eliminating the JDBC driver dependency - removing z/OS *testing* support (not possible in containerized environments) Also, a lot of NPE were logged because the DB2SocketConnection#closeHandler was always invoked even if not set. With all these changes, on my box, the DB2 client build passes in 3-4 minutes instead of 7-8 minutes. Some portions of this content were created with the assistance of IBM Bob. Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
1 parent d34b1d0 commit 55290d0

File tree

16 files changed

+130
-350
lines changed

16 files changed

+130
-350
lines changed

.github/workflows/ci-4.x.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ jobs:
4646
module: 'vertx-mssql-client'
4747
- os: ubuntu-latest
4848
jdk: 8
49-
profile: 'DB2-11.5'
5049
module: 'vertx-db2-client'
5150
- os: ubuntu-latest
5251
jdk: 8

.github/workflows/ci-matrix-5.x.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ jobs:
4949
module: 'vertx-mssql-client'
5050
- os: ubuntu-latest
5151
jdk: 11
52-
profile: 'DB2-11.5'
5352
module: 'vertx-db2-client'
5453
- os: ubuntu-latest
5554
jdk: 11

vertx-db2-client/pom.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,10 @@
4545
<!-- Testing purposes -->
4646
<dependency>
4747
<groupId>org.testcontainers</groupId>
48-
<artifactId>db2</artifactId>
48+
<artifactId>testcontainers</artifactId>
4949
<version>${testcontainers.version}</version>
5050
<scope>test</scope>
5151
</dependency>
52-
<dependency>
53-
<groupId>com.ibm.db2</groupId>
54-
<artifactId>jcc</artifactId>
55-
<version>11.1.4.4</version>
56-
<scope>test</scope>
57-
</dependency>
5852
<!-- SLF4J API for test code and Testcontainers -->
5953
<dependency>
6054
<groupId>org.slf4j</groupId>

vertx-db2-client/src/main/java/io/vertx/db2client/impl/DB2SocketConnection.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
/*
2-
* Copyright (C) 2019,2020 IBM Corporation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
78
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
1510
*/
1611
package io.vertx.db2client.impl;
1712

1813
import io.netty.channel.ChannelPipeline;
19-
import io.vertx.core.AsyncResult;
2014
import io.vertx.core.Completable;
2115
import io.vertx.core.Handler;
2216
import io.vertx.core.Promise;
@@ -28,9 +22,9 @@
2822
import io.vertx.db2client.impl.command.InitialHandshakeCommand;
2923
import io.vertx.db2client.impl.drda.ConnectionMetaData;
3024
import io.vertx.sqlclient.SqlConnectOptions;
25+
import io.vertx.sqlclient.impl.SocketConnectionBase;
3126
import io.vertx.sqlclient.internal.Connection;
3227
import io.vertx.sqlclient.internal.QueryResultHandler;
33-
import io.vertx.sqlclient.impl.SocketConnectionBase;
3428
import io.vertx.sqlclient.internal.command.*;
3529
import io.vertx.sqlclient.spi.DatabaseMetadata;
3630

@@ -102,7 +96,9 @@ protected <R> void doSchedule(CommandBase<R> cmd, Completable<R> handler) {
10296
@Override
10397
public void handleClose(Throwable t) {
10498
super.handleClose(t);
105-
context().runOnContext(closeHandler);
99+
if (closeHandler != null) {
100+
context().runOnContext(closeHandler);
101+
}
106102
}
107103

108104
@Override

vertx-db2-client/src/test/java/io/vertx/tests/db2client/DB2DataTypeTest.java

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
/*
2-
* Copyright (C) 2020 IBM Corporation
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
78
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
1510
*/
1611
package io.vertx.tests.db2client;
1712

@@ -32,8 +27,6 @@
3227
import java.util.List;
3328
import java.util.UUID;
3429

35-
import static org.junit.Assume.assumeTrue;
36-
3730
@RunWith(VertxUnitRunner.class)
3831
public class DB2DataTypeTest extends DB2TestBase {
3932

@@ -214,35 +207,6 @@ public void testUUID(TestContext ctx) {
214207
}));
215208
}
216209

217-
@Test
218-
public void testRowId(TestContext ctx) {
219-
assumeTrue("Only DB2/Z supports the ROWID column type", rule.isZOS());
220-
221-
final String msg = "insert data for testRowId";
222-
connect(ctx.asyncAssertSuccess(conn -> {
223-
// Insert some data
224-
conn
225-
.preparedQuery("INSERT INTO ROWTEST (message) VALUES ('" + msg + "')")
226-
.execute()
227-
.onComplete(ctx.asyncAssertSuccess(insertResult -> {
228-
// Find it by msg
229-
conn
230-
.preparedQuery("SELECT * FROM ROWTEST WHERE message = '" + msg + "'")
231-
.execute()
232-
.onComplete(ctx.asyncAssertSuccess(rows -> {
233-
RowId rowId = verifyRowId(ctx, rows, msg);
234-
// Now find it by rowid
235-
conn
236-
.preparedQuery("SELECT * FROM ROWTEST WHERE id = ?")
237-
.execute(Tuple.of(rowId))
238-
.onComplete(ctx.asyncAssertSuccess(rows2 -> {
239-
verifyRowId(ctx, rows2, msg);
240-
}));
241-
}));
242-
}));
243-
}));
244-
}
245-
246210
/**
247211
* Test to support using enum string values in the Row and Tuple methods.
248212
*/

vertx-db2-client/src/test/java/io/vertx/tests/db2client/QueryVariationsTest.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1-
package io.vertx.tests.db2client;
2-
3-
import static org.junit.Assume.assumeFalse;
4-
5-
import java.util.Arrays;
6-
import java.util.function.Consumer;
1+
/*
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
*/
711

8-
import org.junit.Test;
9-
import org.junit.runner.RunWith;
12+
package io.vertx.tests.db2client;
1013

1114
import io.vertx.ext.unit.TestContext;
1215
import io.vertx.ext.unit.junit.VertxUnitRunner;
1316
import io.vertx.sqlclient.Row;
1417
import io.vertx.sqlclient.RowIterator;
1518
import io.vertx.sqlclient.RowSet;
1619
import io.vertx.sqlclient.Tuple;
20+
import org.junit.Test;
21+
import org.junit.runner.RunWith;
22+
23+
import java.util.Arrays;
24+
import java.util.function.Consumer;
1725

1826
/**
1927
* Tests for subqueries which are documented here:
@@ -180,8 +188,6 @@ public void testSectionReuse(TestContext ctx) {
180188
*/
181189
@Test
182190
public void testSequenceQuery(TestContext ctx) {
183-
assumeFalse("TODO: Sequences behave differently on DB2/z and need to be implemented properly", rule.isZOS());
184-
185191
connect(ctx.asyncAssertSuccess(con -> {
186192
con
187193
.query("values nextval for my_seq")
@@ -214,8 +220,6 @@ public void testSequenceQuery(TestContext ctx) {
214220
*/
215221
@Test
216222
public void testSequenceQueryPrepared(TestContext ctx) {
217-
assumeFalse("TODO: Sequences behave differently on DB2/z and need to be implemented properly", rule.isZOS());
218-
219223
connect(ctx.asyncAssertSuccess(con -> {
220224
con
221225
.preparedQuery("VALUES nextval for my_seq")

vertx-db2-client/src/test/java/io/vertx/tests/db2client/TableJoinTest.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
package io.vertx.tests.db2client;
2-
3-
import static org.junit.Assume.assumeFalse;
4-
5-
import java.util.Arrays;
1+
/*
2+
* Copyright (c) 2011-2026 Contributors to the Eclipse Foundation
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
*/
611

7-
import org.junit.Test;
8-
import org.junit.runner.RunWith;
12+
package io.vertx.tests.db2client;
913

1014
import io.vertx.ext.unit.TestContext;
1115
import io.vertx.ext.unit.junit.VertxUnitRunner;
1216
import io.vertx.sqlclient.Row;
17+
import org.junit.Test;
18+
import org.junit.runner.RunWith;
19+
20+
import java.util.Arrays;
1321

1422
/**
1523
* Tests for table joins which are documented here:
@@ -84,7 +92,6 @@ public void testRightOuterJoin(TestContext ctx) {
8492

8593
@Test
8694
public void testFullOuterJoin(TestContext ctx) {
87-
assumeFalse("DB2 on Z does not support operations within ON clause for FULL OUTER JOIN", rule.isZOS());
8895
testJoin(ctx, "FULL OUTER JOIN");
8996
}
9097

vertx-db2-client/src/test/java/io/vertx/tests/db2client/junit/DB2Resource.java

Lines changed: 36 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,18 @@
1010
*/
1111
package io.vertx.tests.db2client.junit;
1212

13+
import com.github.dockerjava.api.model.Capability;
14+
import io.netty.util.internal.PlatformDependent;
1315
import io.vertx.core.net.ClientSSLOptions;
1416
import io.vertx.core.net.JksOptions;
1517
import io.vertx.db2client.DB2ConnectOptions;
1618
import org.junit.rules.ExternalResource;
1719
import org.slf4j.Logger;
1820
import org.slf4j.LoggerFactory;
19-
import org.testcontainers.containers.Db2Container;
21+
import org.testcontainers.containers.BindMode;
22+
import org.testcontainers.containers.GenericContainer;
2023
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
2124

22-
import java.nio.file.Files;
23-
import java.nio.file.Path;
24-
import java.nio.file.Paths;
25-
import java.sql.Connection;
26-
import java.sql.DriverManager;
27-
import java.sql.SQLSyntaxErrorException;
2825
import java.time.Duration;
2926
import java.util.Objects;
3027

@@ -34,29 +31,40 @@ public class DB2Resource extends ExternalResource {
3431

3532
private static final boolean CUSTOM_DB2 = get("DB2_HOST") != null;
3633

37-
/**
38-
* In order for this container to be reused across test runs you need to add the line:
39-
* <code>testcontainers.reuse.enable=true</code> to your <code>~/.testcontainers.properties</code>
40-
* file (create it if it does not exist)
41-
*/
4234
public static final DB2Resource SHARED_INSTANCE = new DB2Resource();
4335

4436
private boolean started = false;
45-
private boolean isDb2OnZ = false;
4637
private DB2ConnectOptions options;
47-
private final Db2Container instance = new Db2Container("ibmcom/db2:11.5.0.0a")
48-
.acceptLicense()
49-
.withLogConsumer(out -> logger.debug("[DB2] {}", out.getUtf8String()))
50-
.withUsername("vertx")
51-
.withPassword("vertx")
52-
.withDatabaseName("vertx")
38+
private final GenericContainer instance = new GenericContainer<>("icr.io/db2_community/db2:12.1.4.0")
39+
.withCreateContainerCmdModifier(cmd -> cmd
40+
.withCapAdd(Capability.IPC_LOCK)
41+
.withCapAdd(Capability.IPC_OWNER))
42+
.withEnv("LICENSE", "accept")
43+
.withEnv("DB2INSTANCE", "vertx")
44+
.withEnv("DB2INST1_PASSWORD", "vertx")
45+
.withEnv("DBNAME", "vertx")
46+
.withEnv("BLU", "false")
47+
.withEnv("ENABLE_ORACLE_COMPATIBILITY", "false")
48+
.withEnv("UPDATEAVAIL", "NO")
49+
.withEnv("TO_CREATE_SAMPLEDB", "false")
50+
.withEnv("REPODB", "false")
51+
.withEnv("IS_OSXFS", String.valueOf(PlatformDependent.isOsx()))
52+
.withEnv("PERSISTENT_HOME", "true")
53+
.withEnv("HADR_ENABLED", "false")
54+
.withEnv("ETCD_ENDPOINT", "")
55+
.withEnv("ETCD_USERNAME", "")
56+
.withEnv("ETCD_PASSWORD", "")
57+
.withEnv("AUTOCONFIG", "false")
58+
.withEnv("ARCHIVE_LOGS", "false")
5359
.withExposedPorts(50000, 50001)
54-
.withFileSystemBind("src/test/resources/tls/server/", "/certs/")
55-
.withFileSystemBind("src/test/resources/tls/db2_tls_setup.sh", "/var/custom/db2_tls_setup.sh")
60+
.withClasspathResourceMapping("tls/server/", "/certs/", BindMode.READ_ONLY)
61+
.withClasspathResourceMapping("tls/01-db2_tls_setup.sh", "/var/custom/01-db2_tls_setup.sh", BindMode.READ_ONLY)
62+
.withClasspathResourceMapping("init.sql", "/tmp/init.sql", BindMode.READ_ONLY)
63+
.withClasspathResourceMapping("02-init-db.sh", "/var/custom/02-init-db.sh", BindMode.READ_ONLY)
64+
.withLogConsumer(out -> logger.debug("[DB2] {}", out.getUtf8String()))
5665
.waitingFor(new LogMessageWaitStrategy()
57-
.withRegEx(".*VERTX SSH SETUP DONE.*")
58-
.withStartupTimeout(Duration.ofMinutes(10)))
59-
.withReuse(true);
66+
.withRegEx(".*DB2 DATABASE INITIALIZATION COMPLETE.*")
67+
.withStartupTimeout(Duration.ofMinutes(10)));
6068

6169
@Override
6270
protected void before() throws Throwable {
@@ -68,9 +76,9 @@ protected void before() throws Throwable {
6876
options = new DB2ConnectOptions()
6977
.setHost(instance.getHost())
7078
.setPort(instance.getMappedPort(50000))
71-
.setDatabase(instance.getDatabaseName())
72-
.setUser(instance.getUsername())
73-
.setPassword(instance.getPassword());
79+
.setDatabase("vertx")
80+
.setUser("vertx")
81+
.setPassword("vertx");
7482
} else {
7583
logger.info("Using custom DB2 instance as requested via DB2_HOST={}", get("DB2_HOST"));
7684
Objects.requireNonNull(get("DB2_PORT"), "Must set DB2_PORT to a non-null value if DB2_HOST is set");
@@ -83,11 +91,7 @@ protected void before() throws Throwable {
8391
.setDatabase(get("DB2_NAME"))
8492
.setUser(get("DB2_USER"))
8593
.setPassword(get("DB2_PASS"));
86-
}
87-
String jdbcUrl = "jdbc:db2://" + options.getHost() + ":" + options.getPort() + "/" + options.getDatabase();
88-
logger.info("Initializing DB2 database at: {}", jdbcUrl);
89-
try (Connection con = DriverManager.getConnection(jdbcUrl, options.getUser(), options.getPassword())) {
90-
runInitSql(con);
94+
logger.info("Custom DB2 instance must be manually initialized with init.sql");
9195
}
9296
started = true;
9397
}
@@ -106,40 +110,8 @@ public DB2ConnectOptions secureOptions() {
106110
.setPassword("db2test")));
107111
}
108112

109-
public boolean isZOS() {
110-
return isDb2OnZ;
111-
}
112-
113113
private static String get(String name) {
114114
return System.getProperty(name, System.getenv(name));
115115
}
116116

117-
private void runInitSql(Connection con) throws Exception {
118-
isDb2OnZ = con.getMetaData().getDatabaseProductVersion().startsWith("DSN");
119-
String currentLine = "";
120-
Path initScript = Paths.get("src", "test", "resources", isDb2OnZ ? "init.zos.sql" : "init.sql");
121-
logger.info("Running init script at: {}", initScript);
122-
for (String sql : Files.readAllLines(initScript)) {
123-
if (sql.startsWith("--"))
124-
continue;
125-
currentLine += sql;
126-
if (sql.endsWith(";")) {
127-
logger.debug(" {}", currentLine);
128-
try {
129-
con.createStatement().execute(currentLine);
130-
} catch (SQLSyntaxErrorException e) {
131-
if (sql.startsWith("DROP ") && e.getErrorCode() == -204) {
132-
logger.debug(" ignoring syntax exception: {}", e.getMessage());
133-
} else {
134-
throw e;
135-
}
136-
}
137-
currentLine = "";
138-
}
139-
}
140-
if (!currentLine.isEmpty()) {
141-
throw new IllegalStateException("Dangling SQL on init script. Ensure all statements are terminated with ';' char. SQL: " + currentLine);
142-
}
143-
}
144-
145117
}

0 commit comments

Comments
 (0)