Skip to content

Commit 0da8d38

Browse files
committed
Use random port in registry IT
1 parent 61915a2 commit 0da8d38

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/test/java/org/apache/dolphinscheduler/plugin/registry/jdbc/MysqlJdbcRegistryTestCase.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.dolphinscheduler.plugin.registry.jdbc;
1919

20+
import org.apache.commons.lang3.RandomUtils;
21+
2022
import java.sql.Connection;
2123
import java.sql.DriverManager;
2224
import java.sql.Statement;
@@ -52,12 +54,15 @@ public static void setUpTestingServer() {
5254
.withExposedPorts(3306)
5355
.waitingFor(Wait.forHealthcheck());
5456

55-
mysqlContainer.setPortBindings(Lists.newArrayList("3306:3306"));
57+
int exposedPort = RandomUtils.nextInt(10000, 65535);
58+
mysqlContainer.setPortBindings(Lists.newArrayList(exposedPort + ":3306"));
5659
Startables.deepStart(Stream.of(mysqlContainer)).join();
5760

61+
String jdbcUrl = "jdbc:mysql://localhost:" + exposedPort + "/dolphinscheduler?useSSL=false&serverTimezone=UTC";
62+
System.setProperty("spring.datasource.url", jdbcUrl);
63+
5864
try (
59-
Connection connection = DriverManager.getConnection(
60-
"jdbc:mysql://localhost:3306/dolphinscheduler?useSSL=false&serverTimezone=UTC", "root", "root");
65+
Connection connection = DriverManager.getConnection(jdbcUrl, "root", "root");
6166
Statement statement = connection.createStatement();) {
6267
statement.execute(
6368
"CREATE TABLE `t_ds_jdbc_registry_data`\n" +

dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-jdbc/src/test/java/org/apache/dolphinscheduler/plugin/registry/jdbc/PostgresqlJdbcRegistryTestCase.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.dolphinscheduler.plugin.registry.jdbc;
1919

20+
import org.apache.commons.lang3.RandomUtils;
21+
2022
import java.sql.Connection;
2123
import java.sql.DriverManager;
2224
import java.sql.Statement;
@@ -53,12 +55,15 @@ public static void setUpTestingServer() {
5355
.withDatabaseName("dolphinscheduler")
5456
.withNetwork(Network.newNetwork())
5557
.withExposedPorts(5432);
56-
postgresqlContainer.setPortBindings(Lists.newArrayList("5432:5432"));
58+
int exposedPort = RandomUtils.nextInt(10000, 65535);
59+
60+
postgresqlContainer.setPortBindings(Lists.newArrayList(exposedPort + ":5432"));
5761
Startables.deepStart(Stream.of(postgresqlContainer)).join();
5862

63+
String jdbcUrl = "jdbc:postgresql://localhost:" + exposedPort + "/dolphinscheduler";
64+
System.setProperty("spring.datasource.url", jdbcUrl);
5965
try (
60-
Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/dolphinscheduler",
61-
"root", "root");
66+
Connection connection = DriverManager.getConnection(jdbcUrl, "root", "root");
6267
Statement statement = connection.createStatement();) {
6368
statement.execute(
6469
"create table t_ds_jdbc_registry_data\n" +

dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/test/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistryTestCase.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import org.apache.dolphinscheduler.plugin.registry.RegistryTestCase;
2121

22+
import org.apache.commons.lang3.RandomUtils;
23+
2224
import java.util.stream.Stream;
2325

2426
import lombok.SneakyThrows;
@@ -51,10 +53,10 @@ class ZookeeperRegistryTestCase extends RegistryTestCase<ZookeeperRegistry> {
5153
public static void setUpTestingServer() {
5254
zookeeperContainer = new GenericContainer<>(DockerImageName.parse("zookeeper:3.8"))
5355
.withNetwork(NETWORK);
54-
55-
zookeeperContainer.setPortBindings(Lists.newArrayList("2181:2181"));
56+
int randomPort = RandomUtils.nextInt(10000, 65535);
57+
zookeeperContainer.setPortBindings(Lists.newArrayList(randomPort + ":2181"));
5658
Startables.deepStart(Stream.of(zookeeperContainer)).join();
57-
System.setProperty("registry.zookeeper.connect-string", "localhost:2181");
59+
System.setProperty("registry.zookeeper.connect-string", "localhost:" + randomPort);
5860
}
5961

6062
@SneakyThrows

0 commit comments

Comments
 (0)