Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit e4163f6

Browse files
olukasjbartok
andauthored
Fix SSH related issue in CDC tests (#2966) (#2967)
* Disable SSH when using JDBC with MySQL * Fix database names * Make checkstyle happy Co-authored-by: Jozsef Bartok <[email protected]>
1 parent d461147 commit e4163f6

13 files changed

+58
-65
lines changed

extensions/cdc-debezium/src/test/java/com/hazelcast/jet/cdc/AbstractCdcIntegrationTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@
3333
import org.testcontainers.containers.GenericContainer;
3434

3535
import javax.annotation.Nonnull;
36+
import java.sql.Connection;
37+
import java.sql.DriverManager;
38+
import java.sql.SQLException;
3639
import java.util.List;
3740
import java.util.Objects;
41+
import java.util.Properties;
3842
import java.util.concurrent.TimeUnit;
3943
import java.util.stream.Collectors;
4044

@@ -148,4 +152,17 @@ protected <T> T namedTestContainer(GenericContainer<?> container) {
148152
});
149153
}
150154

155+
protected static Connection getMySqlConnection(String url, String user, String password) throws SQLException {
156+
Properties properties = new Properties();
157+
properties.put("user", user);
158+
properties.put("password", password);
159+
properties.put("useSSL", "false");
160+
161+
return DriverManager.getConnection(url, properties);
162+
}
163+
164+
protected static Connection getPostgreSqlConnection(String url, String user, String password) throws SQLException {
165+
return DriverManager.getConnection(url, user, password);
166+
}
167+
151168
}

extensions/cdc-debezium/src/test/java/com/hazelcast/jet/cdc/DebeziumCdcIntegrationTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.testcontainers.containers.PostgreSQLContainer;
3434

3535
import java.sql.Connection;
36-
import java.sql.DriverManager;
3736
import java.sql.Statement;
3837
import java.util.Arrays;
3938
import java.util.List;
@@ -94,7 +93,7 @@ public void mysql() throws Exception {
9493
assertEqualsEventually(() -> jet.getMap("results").size(), 4);
9594

9695
//when
97-
try (Connection connection = DriverManager.getConnection(container.withDatabaseName("inventory").getJdbcUrl(),
96+
try (Connection connection = getMySqlConnection(container.withDatabaseName("inventory").getJdbcUrl(),
9897
container.getUsername(), container.getPassword())) {
9998
Statement statement = connection.createStatement();
10099
statement.addBatch("UPDATE customers SET first_name='Anne Marie' WHERE id=1004");
@@ -271,7 +270,7 @@ public void postgres() throws Exception {
271270
assertEqualsEventually(() -> jet.getMap("results").size(), 4);
272271

273272
//when
274-
try (Connection connection = DriverManager.getConnection(container.getJdbcUrl(), container.getUsername(),
273+
try (Connection connection = getPostgreSqlConnection(container.getJdbcUrl(), container.getUsername(),
275274
container.getPassword())) {
276275
connection.setSchema("inventory");
277276
Statement statement = connection.createStatement();

extensions/cdc-mysql/src/test/java/com/hazelcast/jet/cdc/mysql/AbstractMySqlCdcIntegrationTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.testcontainers.containers.MySQLContainer;
2424

2525
import java.sql.Connection;
26-
import java.sql.DriverManager;
2726
import java.sql.SQLException;
2827
import java.sql.Statement;
2928

@@ -50,12 +49,20 @@ protected MySqlCdcSources.Builder sourceBuilder(String name) {
5049

5150
protected void createDb(String database) throws SQLException {
5251
String jdbcUrl = "jdbc:mysql://" + mysql.getContainerIpAddress() + ":" + mysql.getMappedPort(MYSQL_PORT) + "/";
53-
try (Connection connection = DriverManager.getConnection(jdbcUrl, "root", "mysqlpw")) {
52+
try (Connection connection = getMySqlConnection(jdbcUrl, "root", "mysqlpw")) {
5453
Statement statement = connection.createStatement();
5554
statement.addBatch("CREATE DATABASE " + database);
5655
statement.addBatch("GRANT ALL PRIVILEGES ON " + database + ".* TO 'mysqluser'@'%'");
5756
statement.executeBatch();
5857
}
5958
}
6059

60+
static Connection getConnection(MySQLContainer<?> mysql, String database) throws SQLException {
61+
return getMySqlConnection(
62+
mysql.withDatabaseName(database).getJdbcUrl(),
63+
mysql.getUsername(),
64+
mysql.getPassword()
65+
);
66+
}
67+
6168
}

extensions/cdc-mysql/src/test/java/com/hazelcast/jet/cdc/mysql/MySqlCdcIntegrationTest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
import javax.annotation.Nonnull;
4040
import java.sql.Connection;
41-
import java.sql.DriverManager;
4241
import java.sql.Statement;
4342
import java.util.Arrays;
4443
import java.util.Date;
@@ -91,8 +90,7 @@ public void customers() throws Exception {
9190
assertEqualsEventually(() -> jet.getMap("results").size(), 4);
9291

9392
//when
94-
try (Connection connection = DriverManager.getConnection(mysql.withDatabaseName("inventory").getJdbcUrl(),
95-
mysql.getUsername(), mysql.getPassword())) {
93+
try (Connection connection = getConnection(mysql, "inventory")) {
9694
Statement statement = connection.createStatement();
9795
statement.addBatch("UPDATE customers SET first_name='Anne Marie' WHERE id=1004");
9896
statement.addBatch("INSERT INTO customers VALUES (1005, 'Jason', 'Bourne', '[email protected]')");
@@ -203,8 +201,7 @@ public void restart() throws Exception {
203201
JetTestSupport.assertJobStatusEventually(job, JobStatus.RUNNING);
204202

205203
//then update a record
206-
try (Connection connection = DriverManager.getConnection(mysql.withDatabaseName("inventory").getJdbcUrl(),
207-
mysql.getUsername(), mysql.getPassword())) {
204+
try (Connection connection = getConnection(mysql, "inventory")) {
208205
Statement statement = connection.createStatement();
209206
statement.addBatch("UPDATE customers SET first_name='Anne Marie' WHERE id=1004");
210207
statement.addBatch("INSERT INTO customers VALUES (1005, 'Jason', 'Bourne', '[email protected]')");
@@ -251,8 +248,7 @@ public void cdcMapSink() throws Exception {
251248
//when
252249
job.restart();
253250
JetTestSupport.assertJobStatusEventually(job, JobStatus.RUNNING);
254-
try (Connection connection = DriverManager.getConnection(mysql.withDatabaseName("inventory").getJdbcUrl(),
255-
mysql.getUsername(), mysql.getPassword())) {
251+
try (Connection connection = getConnection(mysql, "inventory")) {
256252
Statement statement = connection.createStatement();
257253
statement.addBatch("UPDATE customers SET first_name='Anne Marie' WHERE id=1004");
258254
statement.addBatch("INSERT INTO customers VALUES (1005, 'Jason', 'Bourne', '[email protected]')");
@@ -270,8 +266,7 @@ public void cdcMapSink() throws Exception {
270266
);
271267

272268
//when
273-
try (Connection connection = DriverManager.getConnection(mysql.withDatabaseName("inventory").getJdbcUrl(),
274-
mysql.getUsername(), mysql.getPassword())) {
269+
try (Connection connection = getConnection(mysql, "inventory")) {
275270
connection.createStatement().execute("DELETE FROM customers WHERE id=1005");
276271
}
277272
//then

extensions/cdc-mysql/src/test/java/com/hazelcast/jet/cdc/mysql/MySqlCdcListenBeforeExistIntegrationTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.junit.experimental.categories.Category;
3232

3333
import java.sql.Connection;
34-
import java.sql.DriverManager;
3534
import java.sql.SQLException;
3635
import java.sql.Statement;
3736
import java.util.Arrays;
@@ -149,8 +148,7 @@ public void listenBeforeColumnExists() throws Exception {
149148
}
150149

151150
private void createTableWithData(String database, String table) throws SQLException {
152-
try (Connection connection = DriverManager.getConnection(mysql.withDatabaseName(database).getJdbcUrl(),
153-
mysql.getUsername(), mysql.getPassword())) {
151+
try (Connection connection = getConnection(mysql, database)) {
154152
Statement statement = connection.createStatement();
155153
statement.addBatch("CREATE TABLE " + table + " (\n"
156154
+ " id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,\n"
@@ -177,16 +175,14 @@ private void insertToTable(String database, String table, int id, String val1, S
177175
statement.append(", '").append(val3).append("'");
178176
}
179177
statement.append(")");
180-
try (Connection connection = DriverManager.getConnection(mysql.withDatabaseName(database).getJdbcUrl(),
181-
mysql.getUsername(), mysql.getPassword())) {
178+
try (Connection connection = getConnection(mysql, database)) {
182179
connection.createStatement().execute(statement.toString());
183180

184181
}
185182
}
186183

187184
private void addColumnToTable(String database, String table, String column) throws SQLException {
188-
try (Connection connection = DriverManager.getConnection(mysql.withDatabaseName(database).getJdbcUrl(),
189-
mysql.getUsername(), mysql.getPassword())) {
185+
try (Connection connection = getConnection(mysql, database)) {
190186
connection.createStatement()
191187
.execute("ALTER TABLE " + table + " ADD COLUMN " + column + " VARCHAR(255);");
192188
}

extensions/cdc-mysql/src/test/java/com/hazelcast/jet/cdc/mysql/MySqlCdcNetworkIntegrationTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import java.io.IOException;
4949
import java.net.ServerSocket;
5050
import java.sql.Connection;
51-
import java.sql.DriverManager;
5251
import java.sql.SQLException;
5352
import java.sql.Statement;
5453
import java.util.Arrays;
@@ -366,8 +365,7 @@ private static ToxiproxyContainer.ContainerProxy initProxy(ToxiproxyContainer to
366365
}
367366

368367
private static void insertRecords(MySQLContainer<?> mysql, int... ids) throws SQLException {
369-
try (Connection connection = DriverManager.getConnection(mysql.withDatabaseName("inventory").getJdbcUrl(),
370-
mysql.getUsername(), mysql.getPassword())) {
368+
try (Connection connection = AbstractMySqlCdcIntegrationTest.getConnection(mysql, "inventory")) {
371369
connection.setAutoCommit(false);
372370
Statement statement = connection.createStatement();
373371
for (int id : ids) {

extensions/cdc-mysql/src/test/java/com/hazelcast/jet/cdc/mysql/MySqlCdcWhiteBlackListIntegrationTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.junit.experimental.categories.Category;
3333

3434
import java.sql.Connection;
35-
import java.sql.DriverManager;
3635
import java.sql.SQLException;
3736
import java.sql.Statement;
3837
import java.util.ArrayList;
@@ -282,8 +281,7 @@ private Pipeline pipeline(StreamSource<ChangeRecord> source) {
282281
private void createDbWithData(int dbSuffix) throws SQLException {
283282
String database = DB_PREFIX + dbSuffix;
284283
createDb(database);
285-
try (Connection connection = DriverManager.getConnection(mysql.withDatabaseName(database).getJdbcUrl(),
286-
mysql.getUsername(), mysql.getPassword())) {
284+
try (Connection connection = getConnection(mysql, database)) {
287285
int dbId = dbSuffix * 1000;
288286
for (int i = 0; i < 3; i++) {
289287
String table = "table" + i;
@@ -313,8 +311,7 @@ private void createDbWithData(int dbSuffix) throws SQLException {
313311

314312
private void executeStatementsOnDb(int dbSuffix) throws SQLException {
315313
String database = DB_PREFIX + dbSuffix;
316-
try (Connection connection = DriverManager.getConnection(mysql.withDatabaseName(database).getJdbcUrl(),
317-
mysql.getUsername(), mysql.getPassword())) {
314+
try (Connection connection = getConnection(mysql, database)) {
318315
int id = dbSuffix * 1000 + 1;
319316
Statement statement = connection.createStatement();
320317
statement.addBatch("UPDATE table0 SET value_1='new_" + database + "_table0_val1_0' WHERE id=" + id);

extensions/cdc-postgres/src/test/java/com/hazelcast/jet/cdc/postgres/AbstractPostgresCdcIntegrationTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import java.io.Serializable;
2727
import java.sql.Connection;
28-
import java.sql.DriverManager;
2928
import java.sql.SQLException;
3029
import java.util.Date;
3130
import java.util.Objects;
@@ -54,12 +53,15 @@ protected PostgresCdcSources.Builder sourceBuilder(String name) {
5453
}
5554

5655
protected void createSchema(String schema) throws SQLException {
57-
try (Connection connection = DriverManager.getConnection(postgres.getJdbcUrl(), postgres.getUsername(),
58-
postgres.getPassword())) {
56+
try (Connection connection = getConnection(postgres)) {
5957
connection.createStatement().execute("CREATE SCHEMA " + schema);
6058
}
6159
}
6260

61+
static Connection getConnection(PostgreSQLContainer<?> postgres) throws SQLException {
62+
return getPostgreSqlConnection(postgres.getJdbcUrl(), postgres.getUsername(), postgres.getPassword());
63+
}
64+
6365
protected static class Customer implements Serializable {
6466

6567
@JsonProperty("id")

extensions/cdc-postgres/src/test/java/com/hazelcast/jet/cdc/postgres/MultiTableCacheIntegrationTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
import java.io.Serializable;
3535
import java.sql.Connection;
36-
import java.sql.DriverManager;
3736
import java.sql.Statement;
3837
import java.util.Arrays;
3938
import java.util.Date;
@@ -97,8 +96,7 @@ record -> (Integer) record.value().toMap().get("purchaser"),
9796
assertEqualsEventually(() -> getIMapContent(jet, CACHE), expected);
9897

9998
//when
100-
try (Connection connection = DriverManager.getConnection(postgres.getJdbcUrl(), postgres.getUsername(),
101-
postgres.getPassword())) {
99+
try (Connection connection = getConnection(postgres)) {
102100
connection.setSchema("inventory");
103101
Statement statement = connection.createStatement();
104102
for (int i = 1; i <= REPEATS; i++) {

extensions/cdc-postgres/src/test/java/com/hazelcast/jet/cdc/postgres/PostgresCdcIntegrationTest.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
import javax.annotation.Nonnull;
4141
import java.sql.Connection;
42-
import java.sql.DriverManager;
4342
import java.sql.Statement;
4443
import java.util.ArrayList;
4544
import java.util.Arrays;
@@ -92,8 +91,7 @@ public void customers() throws Exception {
9291
assertEqualsEventually(() -> jet.getMap("results").size(), 4);
9392

9493
//when
95-
try (Connection connection = DriverManager.getConnection(postgres.getJdbcUrl(), postgres.getUsername(),
96-
postgres.getPassword())) {
94+
try (Connection connection = getConnection(postgres)) {
9795
connection.setSchema("inventory");
9896
Statement statement = connection.createStatement();
9997
statement.addBatch("UPDATE customers SET first_name='Anne Marie' WHERE id=1004");
@@ -201,8 +199,7 @@ public void restart() throws Exception {
201199
JetTestSupport.assertJobStatusEventually(job, JobStatus.RUNNING);
202200

203201
//then update a record
204-
try (Connection connection = DriverManager.getConnection(postgres.getJdbcUrl(), postgres.getUsername(),
205-
postgres.getPassword())) {
202+
try (Connection connection = getConnection(postgres)) {
206203
connection.setSchema("inventory");
207204
Statement statement = connection.createStatement();
208205
statement.addBatch("UPDATE customers SET first_name='Anne Marie' WHERE id=1004");
@@ -250,8 +247,7 @@ public void cdcMapSink() throws Exception {
250247
//when
251248
job.restart();
252249
JetTestSupport.assertJobStatusEventually(job, JobStatus.RUNNING);
253-
try (Connection connection = DriverManager.getConnection(postgres.getJdbcUrl(), postgres.getUsername(),
254-
postgres.getPassword())) {
250+
try (Connection connection = getConnection(postgres)) {
255251
connection.setSchema("inventory");
256252
Statement statement = connection.createStatement();
257253
statement.addBatch("UPDATE customers SET first_name='Anne Marie' WHERE id=1004");
@@ -270,8 +266,7 @@ public void cdcMapSink() throws Exception {
270266
);
271267

272268
//when
273-
try (Connection connection = DriverManager.getConnection(postgres.getJdbcUrl(), postgres.getUsername(),
274-
postgres.getPassword())) {
269+
try (Connection connection = getConnection(postgres)) {
275270
connection.setSchema("inventory");
276271
connection
277272
.prepareStatement("DELETE FROM customers WHERE id=1005")
@@ -337,8 +332,7 @@ public void dataLoss() throws Exception {
337332
assertJobStatusEventually(job, JobStatus.RUNNING);
338333

339334
//when
340-
try (Connection connection = DriverManager.getConnection(postgres.getJdbcUrl(), postgres.getUsername(),
341-
postgres.getPassword())) {
335+
try (Connection connection = getConnection(postgres)) {
342336
connection.setSchema("inventory");
343337
Statement statement = connection.createStatement();
344338
for (int i = offset; i < offset + length; i++) {

0 commit comments

Comments
 (0)