diff --git a/bootstrap/src/test/java/org/apache/shardingsphere/elasticjob/bootstrap/type/OneOffJobBootstrapTest.java b/bootstrap/src/test/java/org/apache/shardingsphere/elasticjob/bootstrap/type/OneOffJobBootstrapTest.java index 443a1a865c..fd74b915a8 100644 --- a/bootstrap/src/test/java/org/apache/shardingsphere/elasticjob/bootstrap/type/OneOffJobBootstrapTest.java +++ b/bootstrap/src/test/java/org/apache/shardingsphere/elasticjob/bootstrap/type/OneOffJobBootstrapTest.java @@ -41,9 +41,7 @@ class OneOffJobBootstrapTest { - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(7181); - - private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), OneOffJobBootstrapTest.class.getSimpleName()); + private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(); private static final int SHARDING_TOTAL_COUNT = 3; @@ -52,7 +50,8 @@ class OneOffJobBootstrapTest { @BeforeAll static void init() { EMBED_TESTING_SERVER.start(); - zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION); + ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), OneOffJobBootstrapTest.class.getSimpleName()); + zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration); zkRegCenter.init(); } diff --git a/kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/SnapshotService.java b/kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/SnapshotService.java index 136e87e40f..ac96f28d75 100644 --- a/kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/SnapshotService.java +++ b/kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/SnapshotService.java @@ -53,7 +53,7 @@ public final class SnapshotService { private volatile boolean closed; public SnapshotService(final CoordinatorRegistryCenter regCenter, final int port) { - Preconditions.checkArgument(port >= 0 && port <= 0xFFFF, "Port value out of range: " + port); + Preconditions.checkArgument(port >= -1 && port <= 0xFFFF, "Port value out of range: " + port); this.regCenter = regCenter; this.port = port; } diff --git a/lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lifecycle/api/JobAPIFactoryTest.java b/lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lifecycle/api/JobAPIFactoryTest.java index bf9e40f677..a4dd1cf2bb 100644 --- a/lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lifecycle/api/JobAPIFactoryTest.java +++ b/lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lifecycle/api/JobAPIFactoryTest.java @@ -26,7 +26,7 @@ class JobAPIFactoryTest { - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(8181); + private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(); @BeforeAll static void setUp() { diff --git a/lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lifecycle/internal/operate/JobOperateAPIImplTest.java b/lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lifecycle/internal/operate/JobOperateAPIImplTest.java index d42db686fa..a295f521d9 100644 --- a/lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lifecycle/internal/operate/JobOperateAPIImplTest.java +++ b/lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lifecycle/internal/operate/JobOperateAPIImplTest.java @@ -36,8 +36,6 @@ @ExtendWith(MockitoExtension.class) class JobOperateAPIImplTest { - static final int DUMP_PORT = 9000; - private JobOperateAPI jobOperateAPI; // TODO We should not use `Mock.Strictness.LENIENT` here, but the default. This is a flaw in the unit test design. diff --git a/lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lifecycle/internal/reg/RegistryCenterFactoryTest.java b/lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lifecycle/internal/reg/RegistryCenterFactoryTest.java index 48ba2e25be..5f07ac120c 100644 --- a/lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lifecycle/internal/reg/RegistryCenterFactoryTest.java +++ b/lifecycle/src/test/java/org/apache/shardingsphere/elasticjob/lifecycle/internal/reg/RegistryCenterFactoryTest.java @@ -32,7 +32,7 @@ class RegistryCenterFactoryTest { - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(8181); + private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(); @BeforeAll static void setUp() { diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java index 440191c2e9..a3838911a0 100644 --- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java +++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java @@ -43,7 +43,7 @@ @ExtendWith(MockitoExtension.class) class ZookeeperElectionServiceTest { - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181); + private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(); private static final String HOST_AND_PORT = "localhost:8899"; diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterExecuteInLeaderTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterExecuteInLeaderTest.java index f44fb68d2d..88f5a3ae77 100644 --- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterExecuteInLeaderTest.java +++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterExecuteInLeaderTest.java @@ -33,18 +33,16 @@ class ZookeeperRegistryCenterExecuteInLeaderTest { - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181); - - private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = - new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterExecuteInLeaderTest.class.getName()); + private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(); private static ZookeeperRegistryCenter zkRegCenter; @BeforeAll static void setUp() { EMBED_TESTING_SERVER.start(); - zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION); - ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000); + ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterExecuteInLeaderTest.class.getName()); + zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration); + zookeeperConfiguration.setConnectionTimeoutMilliseconds(30000); zkRegCenter.init(); } diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterForAuthTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterForAuthTest.java index 95592c85c8..eeccf9113d 100644 --- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterForAuthTest.java +++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterForAuthTest.java @@ -33,21 +33,20 @@ class ZookeeperRegistryCenterForAuthTest { - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181); + private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(); private static final String NAME_SPACE = ZookeeperRegistryCenterForAuthTest.class.getName(); - private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), NAME_SPACE); - private static ZookeeperRegistryCenter zkRegCenter; @BeforeAll static void setUp() { EMBED_TESTING_SERVER.start(); - ZOOKEEPER_CONFIGURATION.setDigest("digest:password"); - ZOOKEEPER_CONFIGURATION.setSessionTimeoutMilliseconds(5000); - ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(5000); - zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION); + ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), NAME_SPACE); + zookeeperConfiguration.setDigest("digest:password"); + zookeeperConfiguration.setSessionTimeoutMilliseconds(5000); + zookeeperConfiguration.setConnectionTimeoutMilliseconds(5000); + zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration); zkRegCenter.init(); RegistryCenterEnvironmentPreparer.persist(zkRegCenter); } diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterMiscellaneousTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterMiscellaneousTest.java index c92d551989..9f9a74583d 100644 --- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterMiscellaneousTest.java +++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterMiscellaneousTest.java @@ -30,18 +30,18 @@ class ZookeeperRegistryCenterMiscellaneousTest { - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181); + private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(); - private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = - new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterMiscellaneousTest.class.getName()); + private static ZookeeperConfiguration zookeeperConfiguration; private static ZookeeperRegistryCenter zkRegCenter; @BeforeAll static void setUp() { EMBED_TESTING_SERVER.start(); - ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000); - zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION); + zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterMiscellaneousTest.class.getName()); + zookeeperConfiguration.setConnectionTimeoutMilliseconds(30000); + zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration); zkRegCenter.init(); zkRegCenter.addCacheData("/test"); } @@ -64,7 +64,7 @@ void assertGetRawCache() { @Test void assertGetZkConfig() { - ZookeeperRegistryCenter zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION); - assertThat(zkRegCenter.getZkConfig(), is(ZOOKEEPER_CONFIGURATION)); + ZookeeperRegistryCenter zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration); + assertThat(zkRegCenter.getZkConfig(), is(zookeeperConfiguration)); } } diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterModifyTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterModifyTest.java index d4a1c9c5fc..300ac2e154 100644 --- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterModifyTest.java +++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterModifyTest.java @@ -37,17 +37,16 @@ class ZookeeperRegistryCenterModifyTest { - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181); - - private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterModifyTest.class.getName()); + private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(); private static ZookeeperRegistryCenter zkRegCenter; @BeforeAll static void setUp() { EMBED_TESTING_SERVER.start(); - zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION); - ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000); + ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterModifyTest.class.getName()); + zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration); + zookeeperConfiguration.setConnectionTimeoutMilliseconds(30000); zkRegCenter.init(); RegistryCenterEnvironmentPreparer.persist(zkRegCenter); } diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithCacheTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithCacheTest.java index 59eb61cf83..f37f1276a7 100644 --- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithCacheTest.java +++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithCacheTest.java @@ -29,18 +29,16 @@ class ZookeeperRegistryCenterQueryWithCacheTest { - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181); - - private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = - new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterQueryWithCacheTest.class.getName()); + private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(); private static ZookeeperRegistryCenter zkRegCenter; @BeforeAll static void setUp() { EMBED_TESTING_SERVER.start(); - zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION); - ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000); + ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterQueryWithCacheTest.class.getName()); + zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration); + zookeeperConfiguration.setConnectionTimeoutMilliseconds(30000); zkRegCenter.init(); RegistryCenterEnvironmentPreparer.persist(zkRegCenter); zkRegCenter.addCacheData("/test"); diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithoutCacheTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithoutCacheTest.java index c370073a85..d253d09056 100644 --- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithoutCacheTest.java +++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithoutCacheTest.java @@ -34,18 +34,16 @@ class ZookeeperRegistryCenterQueryWithoutCacheTest { - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181); - - private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = - new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterQueryWithoutCacheTest.class.getName()); + private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(); private static ZookeeperRegistryCenter zkRegCenter; @BeforeAll static void setUp() { EMBED_TESTING_SERVER.start(); - ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000); - zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION); + ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterQueryWithoutCacheTest.class.getName()); + zookeeperConfiguration.setConnectionTimeoutMilliseconds(30000); + zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration); zkRegCenter.init(); RegistryCenterEnvironmentPreparer.persist(zkRegCenter); zkRegCenter.addCacheData("/other"); diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterTransactionTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterTransactionTest.java index b08795a04b..d73c975a59 100644 --- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterTransactionTest.java +++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterTransactionTest.java @@ -34,18 +34,16 @@ class ZookeeperRegistryCenterTransactionTest { - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181); - - private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = - new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterTransactionTest.class.getName()); + private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(); private static ZookeeperRegistryCenter zkRegCenter; @BeforeAll static void setUp() { EMBED_TESTING_SERVER.start(); - zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION); - ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000); + ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterTransactionTest.class.getName()); + zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration); + zookeeperConfiguration.setConnectionTimeoutMilliseconds(30000); zkRegCenter.init(); } diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterWatchTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterWatchTest.java index 1ead5e3f15..735afc18be 100644 --- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterWatchTest.java +++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterWatchTest.java @@ -37,17 +37,16 @@ class ZookeeperRegistryCenterWatchTest { - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(9181); - - private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterWatchTest.class.getName()); + private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(); private static ZookeeperRegistryCenter zkRegCenter; @BeforeAll static void setUp() { EMBED_TESTING_SERVER.start(); - zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION); - ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000); + ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), ZookeeperRegistryCenterWatchTest.class.getName()); + zkRegCenter = new ZookeeperRegistryCenter(zookeeperConfiguration); + zookeeperConfiguration.setConnectionTimeoutMilliseconds(30000); zkRegCenter.init(); RegistryCenterEnvironmentPreparer.persist(zkRegCenter); } diff --git a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/annotation/BaseAnnotationE2ETest.java b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/annotation/BaseAnnotationE2ETest.java index 8dfa287dd3..1c1c30f75e 100644 --- a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/annotation/BaseAnnotationE2ETest.java +++ b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/annotation/BaseAnnotationE2ETest.java @@ -39,7 +39,7 @@ @Getter(AccessLevel.PROTECTED) public abstract class BaseAnnotationE2ETest { - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(7181); + private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(); private static final ZookeeperConfiguration ZOOKEEPER_CONFIG = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), "zkRegTestCenter"); diff --git a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/BaseE2ETest.java b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/BaseE2ETest.java index ba384d29a9..3c16b028d2 100644 --- a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/BaseE2ETest.java +++ b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/BaseE2ETest.java @@ -38,7 +38,7 @@ @Getter(AccessLevel.PROTECTED) public abstract class BaseE2ETest { - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(7181); + private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(); private static final ZookeeperConfiguration ZOOKEEPER_CONFIG = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), "zkRegTestCenter"); diff --git a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/snapshot/BaseSnapshotServiceE2ETest.java b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/snapshot/BaseSnapshotServiceE2ETest.java index e6d75ba387..c5f7b813f6 100644 --- a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/snapshot/BaseSnapshotServiceE2ETest.java +++ b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/snapshot/BaseSnapshotServiceE2ETest.java @@ -35,17 +35,15 @@ public abstract class BaseSnapshotServiceE2ETest { - static final int DUMP_PORT = 9000; - - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(7181); - - private static final ZookeeperConfiguration ZOOKEEPER_CONFIG = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), "zkRegTestCenter"); + static final int DUMP_PORT = -1; + private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(); + @Getter(value = AccessLevel.PROTECTED) - private static final CoordinatorRegistryCenter REG_CENTER = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIG); + private static CoordinatorRegistryCenter regCenter; @Getter(value = AccessLevel.PROTECTED) - private static SnapshotService snapshotService = new SnapshotService(REG_CENTER, DUMP_PORT); + private static SnapshotService snapshotService = new SnapshotService(regCenter, DUMP_PORT); private final ScheduleJobBootstrap bootstrap; @@ -53,19 +51,21 @@ public abstract class BaseSnapshotServiceE2ETest { private final String jobName = System.nanoTime() + "_test_job"; public BaseSnapshotServiceE2ETest(final ElasticJob elasticJob) { - bootstrap = new ScheduleJobBootstrap(REG_CENTER, elasticJob, JobConfiguration.newBuilder(jobName, 3).cron("0/1 * * * * ?").overwrite(true).build()); + bootstrap = new ScheduleJobBootstrap(regCenter, elasticJob, JobConfiguration.newBuilder(jobName, 3).cron("0/1 * * * * ?").overwrite(true).build()); } @BeforeAll static void init() { EMBED_TESTING_SERVER.start(); - ZOOKEEPER_CONFIG.setConnectionTimeoutMilliseconds(30000); - REG_CENTER.init(); + ZookeeperConfiguration zookeeperConfig = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), "zkRegTestCenter"); + regCenter = new ZookeeperRegistryCenter(zookeeperConfig); + zookeeperConfig.setConnectionTimeoutMilliseconds(30000); + regCenter.init(); } @BeforeEach void setUp() { - REG_CENTER.init(); + regCenter.init(); bootstrap.schedule(); } diff --git a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/snapshot/SnapshotServiceDisableE2ETest.java b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/snapshot/SnapshotServiceDisableE2ETest.java index a060052542..2690f93d66 100644 --- a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/snapshot/SnapshotServiceDisableE2ETest.java +++ b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/snapshot/SnapshotServiceDisableE2ETest.java @@ -36,18 +36,18 @@ class SnapshotServiceDisableE2ETest extends BaseSnapshotServiceE2ETest { @Test void assertMonitorWithDumpCommand() { - assertThrows(IOException.class, () -> SocketUtils.sendCommand(SnapshotService.DUMP_COMMAND, DUMP_PORT - 1)); + assertThrows(IOException.class, () -> SocketUtils.sendCommand(SnapshotService.DUMP_COMMAND, DUMP_PORT + 1)); } @Test void assertPortInvalid() { - assertThrows(IllegalArgumentException.class, () -> new SnapshotService(getREG_CENTER(), -1).listen()); + assertThrows(IllegalArgumentException.class, () -> new SnapshotService(getRegCenter(), -1).listen()); } @Test void assertListenException() throws IOException { ServerSocket serverSocket = new ServerSocket(9898); - SnapshotService snapshotService = new SnapshotService(getREG_CENTER(), 9898); + SnapshotService snapshotService = new SnapshotService(getRegCenter(), 9898); snapshotService.listen(); serverSocket.close(); assertNull(ReflectionUtils.getFieldValue(snapshotService, "serverSocket")); diff --git a/test/util/src/main/java/org/apache/shardingsphere/elasticjob/test/util/EmbedTestingServer.java b/test/util/src/main/java/org/apache/shardingsphere/elasticjob/test/util/EmbedTestingServer.java index ee460f25cb..d907db7153 100644 --- a/test/util/src/main/java/org/apache/shardingsphere/elasticjob/test/util/EmbedTestingServer.java +++ b/test/util/src/main/java/org/apache/shardingsphere/elasticjob/test/util/EmbedTestingServer.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.elasticjob.test.util; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.curator.framework.CuratorFramework; @@ -33,16 +35,20 @@ /** * Embed ZooKeeper testing server. */ -@RequiredArgsConstructor @Slf4j +@AllArgsConstructor public final class EmbedTestingServer { private static volatile TestingServer testingServer; private static final Object INIT_LOCK = new Object(); - + private final int port; - + + public EmbedTestingServer() { + this.port = -1; + } + /** * Start embed zookeeper server. */ @@ -64,7 +70,7 @@ public void start() { private void start0() { try { - testingServer = new TestingServer(port, true); + testingServer = new TestingServer(port); // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON @@ -132,6 +138,6 @@ private boolean isIgnoredException(final Throwable cause) { * @return connection string */ public String getConnectionString() { - return "localhost:" + port; + return testingServer.getConnectString(); } }