From e25a2ab834a00809a3e7b406879351f54dda1dba Mon Sep 17 00:00:00 2001 From: linghengqian Date: Sat, 27 Jul 2024 23:02:05 +0800 Subject: [PATCH] Prevent unit tests and E2E from using host ports `7181`, `8181`, `9000` and `9181` --- .../type/OneOffJobBootstrapTest.java | 7 +++--- .../lifecycle/api/JobAPIFactoryTest.java | 2 +- .../operate/JobOperateAPIImplTest.java | 2 -- .../reg/RegistryCenterFactoryTest.java | 2 +- .../ZookeeperElectionServiceTest.java | 2 +- ...eperRegistryCenterExecuteInLeaderTest.java | 10 ++++----- .../ZookeeperRegistryCenterForAuthTest.java | 13 +++++------ ...keeperRegistryCenterMiscellaneousTest.java | 14 ++++++------ .../ZookeeperRegistryCenterModifyTest.java | 9 ++++---- ...eeperRegistryCenterQueryWithCacheTest.java | 10 ++++----- ...erRegistryCenterQueryWithoutCacheTest.java | 10 ++++----- ...ookeeperRegistryCenterTransactionTest.java | 10 ++++----- .../ZookeeperRegistryCenterWatchTest.java | 9 ++++---- .../test/resources/application-elasticjob.yml | 2 +- .../test/resources/application-snapshot.yml | 2 +- .../test/resources/application-tracing.yml | 2 +- .../test/resources/conf/job/conf.properties | 2 +- .../test/resources/conf/reg/conf.properties | 4 ++-- .../e2e/annotation/BaseAnnotationE2ETest.java | 18 ++++++++------- .../annotation/OneOffEnabledJobE2ETest.java | 12 +++++----- .../annotation/ScheduleEnabledJobE2ETest.java | 12 +++++----- .../elasticjob/test/e2e/raw/BaseE2ETest.java | 18 ++++++++------- .../e2e/raw/disable/DisabledJobE2ETest.java | 6 ++--- .../disable/ScheduleDisabledJobE2ETest.java | 8 +++---- .../e2e/raw/enable/EnabledJobE2ETest.java | 10 ++++----- .../raw/enable/OneOffEnabledJobE2ETest.java | 2 +- .../raw/enable/ScheduleEnabledJobE2ETest.java | 2 +- .../snapshot/BaseSnapshotServiceE2ETest.java | 22 ++++++++++--------- .../SnapshotServiceDisableE2ETest.java | 4 ++-- .../test/util/EmbedTestingServer.java | 16 ++++++++++---- 30 files changed, 121 insertions(+), 121 deletions(-) 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/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/spring/boot-starter/src/test/resources/application-elasticjob.yml b/spring/boot-starter/src/test/resources/application-elasticjob.yml index 204bd0e0f5..0990201b66 100644 --- a/spring/boot-starter/src/test/resources/application-elasticjob.yml +++ b/spring/boot-starter/src/test/resources/application-elasticjob.yml @@ -27,7 +27,7 @@ elasticjob: type: RDB excludeJobNames: [customTestJob] regCenter: - serverLists: localhost:18181 + serverLists: 127.0.0.1:18181 namespace: elasticjob-spring-boot-starter jobs: customTestJob: diff --git a/spring/boot-starter/src/test/resources/application-snapshot.yml b/spring/boot-starter/src/test/resources/application-snapshot.yml index 95e28f1de6..f0930efc86 100644 --- a/spring/boot-starter/src/test/resources/application-snapshot.yml +++ b/spring/boot-starter/src/test/resources/application-snapshot.yml @@ -19,5 +19,5 @@ elasticjob: dump: port: 0 regCenter: - serverLists: localhost:18181 + serverLists: 127.0.0.1:18181 namespace: elasticjob-spring-boot-starter diff --git a/spring/boot-starter/src/test/resources/application-tracing.yml b/spring/boot-starter/src/test/resources/application-tracing.yml index 610a73cf9a..be446ee6d6 100644 --- a/spring/boot-starter/src/test/resources/application-tracing.yml +++ b/spring/boot-starter/src/test/resources/application-tracing.yml @@ -17,5 +17,5 @@ elasticjob: regCenter: - serverLists: localhost:18181 + serverLists: 127.0.0.1:18181 namespace: elasticjob-spring-boot-starter diff --git a/spring/namespace/src/test/resources/conf/job/conf.properties b/spring/namespace/src/test/resources/conf/job/conf.properties index 4f09309e23..ff5e933aae 100644 --- a/spring/namespace/src/test/resources/conf/job/conf.properties +++ b/spring/namespace/src/test/resources/conf/job/conf.properties @@ -15,7 +15,7 @@ # limitations under the License. # -regCenter.serverLists=localhost:3181 +regCenter.serverLists=127.0.0.1:3181 regCenter.namespace=elasticjob-spring-test regCenter.baseSleepTimeMilliseconds=1000 regCenter.maxSleepTimeMilliseconds=3000 diff --git a/spring/namespace/src/test/resources/conf/reg/conf.properties b/spring/namespace/src/test/resources/conf/reg/conf.properties index 41de41504d..14c24279e0 100644 --- a/spring/namespace/src/test/resources/conf/reg/conf.properties +++ b/spring/namespace/src/test/resources/conf/reg/conf.properties @@ -15,13 +15,13 @@ # limitations under the License. # -regCenter1.serverLists=localhost:3181 +regCenter1.serverLists=127.0.0.1:3181 regCenter1.namespace=regCenter1 regCenter1.baseSleepTimeMilliseconds=1000 regCenter1.maxSleepTimeMilliseconds=3000 regCenter1.maxRetries=3 -regCenter2.serverLists=localhost:3181 +regCenter2.serverLists=127.0.0.1:3181 regCenter2.namespace=regCenter2 regCenter2.baseSleepTimeMilliseconds=1000 regCenter2.maxSleepTimeMilliseconds=3000 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..3ac80f506a 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,12 +39,12 @@ @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"); + private static ZookeeperConfiguration zookeeperConfig; @Getter(AccessLevel.PROTECTED) - private static final CoordinatorRegistryCenter REGISTRY_CENTER = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIG); + private static CoordinatorRegistryCenter registryCenter; private final ElasticJob elasticJob; @@ -61,15 +61,15 @@ protected BaseAnnotationE2ETest(final TestType type, final ElasticJob elasticJob jobConfiguration = JobAnnotationBuilder.generateJobConfiguration(elasticJob.getClass()); jobName = jobConfiguration.getJobName(); jobBootstrap = createJobBootstrap(type, elasticJob); - leaderService = new LeaderService(REGISTRY_CENTER, jobName); + leaderService = new LeaderService(registryCenter, jobName); } private JobBootstrap createJobBootstrap(final TestType type, final ElasticJob elasticJob) { switch (type) { case SCHEDULE: - return new ScheduleJobBootstrap(REGISTRY_CENTER, elasticJob); + return new ScheduleJobBootstrap(registryCenter, elasticJob); case ONE_OFF: - return new OneOffJobBootstrap(REGISTRY_CENTER, elasticJob); + return new OneOffJobBootstrap(registryCenter, elasticJob); default: throw new RuntimeException(String.format("Cannot support `%s`", type)); } @@ -78,8 +78,10 @@ private JobBootstrap createJobBootstrap(final TestType type, final ElasticJob el @BeforeAll static void init() { EMBED_TESTING_SERVER.start(); - ZOOKEEPER_CONFIG.setConnectionTimeoutMilliseconds(30000); - REGISTRY_CENTER.init(); + zookeeperConfig = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), "zkRegTestCenter"); + registryCenter = new ZookeeperRegistryCenter(zookeeperConfig); + zookeeperConfig.setConnectionTimeoutMilliseconds(30000); + registryCenter.init(); } @BeforeEach diff --git a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/annotation/OneOffEnabledJobE2ETest.java b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/annotation/OneOffEnabledJobE2ETest.java index e23072f521..f776b0b241 100644 --- a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/annotation/OneOffEnabledJobE2ETest.java +++ b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/annotation/OneOffEnabledJobE2ETest.java @@ -46,20 +46,20 @@ class OneOffEnabledJobE2ETest extends BaseAnnotationE2ETest { void assertEnabledRegCenterInfo() { assertThat(JobRegistry.getInstance().getCurrentShardingTotalCount(getJobName()), is(1)); assertThat(JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp(), is(IpUtils.getIp())); - JobConfiguration jobConfig = YamlEngine.unmarshal(getREGISTRY_CENTER().get("/" + getJobName() + "/config"), JobConfigurationPOJO.class).toJobConfiguration(); + JobConfiguration jobConfig = YamlEngine.unmarshal(getRegistryCenter().get("/" + getJobName() + "/config"), JobConfigurationPOJO.class).toJobConfiguration(); assertThat(jobConfig.getShardingTotalCount(), is(1)); assertNull(jobConfig.getCron()); - assertThat(getREGISTRY_CENTER().get("/" + getJobName() + "/servers/" + JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp()), is(ServerStatus.ENABLED.name())); - assertThat(getREGISTRY_CENTER().get("/" + getJobName() + "/leader/election/instance"), is(JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId())); - assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + "/instances/" + JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId())); - getREGISTRY_CENTER().remove("/" + getJobName() + "/leader/election"); + assertThat(getRegistryCenter().get("/" + getJobName() + "/servers/" + JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp()), is(ServerStatus.ENABLED.name())); + assertThat(getRegistryCenter().get("/" + getJobName() + "/leader/election/instance"), is(JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId())); + assertTrue(getRegistryCenter().isExisted("/" + getJobName() + "/instances/" + JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId())); + getRegistryCenter().remove("/" + getJobName() + "/leader/election"); assertTrue(getLeaderService().isLeaderUntilBlock()); } @Test void assertJobInit() { Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() -> MatcherAssert.assertThat(((AnnotationUnShardingJob) getElasticJob()).isCompleted(), is(true))); - assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + "/sharding")); + assertTrue(getRegistryCenter().isExisted("/" + getJobName() + "/sharding")); } } diff --git a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/annotation/ScheduleEnabledJobE2ETest.java b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/annotation/ScheduleEnabledJobE2ETest.java index d8162f688f..ba23457d94 100644 --- a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/annotation/ScheduleEnabledJobE2ETest.java +++ b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/annotation/ScheduleEnabledJobE2ETest.java @@ -46,22 +46,22 @@ class ScheduleEnabledJobE2ETest extends BaseAnnotationE2ETest { void assertEnabledRegCenterInfo() { assertThat(JobRegistry.getInstance().getCurrentShardingTotalCount(getJobName()), is(3)); assertThat(JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp(), is(IpUtils.getIp())); - JobConfiguration jobConfig = YamlEngine.unmarshal(getREGISTRY_CENTER().get("/" + getJobName() + "/config"), JobConfigurationPOJO.class).toJobConfiguration(); + JobConfiguration jobConfig = YamlEngine.unmarshal(getRegistryCenter().get("/" + getJobName() + "/config"), JobConfigurationPOJO.class).toJobConfiguration(); assertThat(jobConfig.getShardingTotalCount(), is(3)); assertThat(jobConfig.getCron(), is("*/10 * * * * ?")); assertNull(jobConfig.getTimeZone()); assertThat(jobConfig.getShardingItemParameters(), is("0=a,1=b,2=c")); - assertThat(getREGISTRY_CENTER().get("/" + getJobName() + "/servers/" + JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp()), is(ServerStatus.ENABLED.name())); - assertThat(getREGISTRY_CENTER().get("/" + getJobName() + "/leader/election/instance"), is(JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId())); - assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + "/instances/" + JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId())); - getREGISTRY_CENTER().remove("/" + getJobName() + "/leader/election"); + assertThat(getRegistryCenter().get("/" + getJobName() + "/servers/" + JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp()), is(ServerStatus.ENABLED.name())); + assertThat(getRegistryCenter().get("/" + getJobName() + "/leader/election/instance"), is(JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId())); + assertTrue(getRegistryCenter().isExisted("/" + getJobName() + "/instances/" + JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId())); + getRegistryCenter().remove("/" + getJobName() + "/leader/election"); assertTrue(getLeaderService().isLeaderUntilBlock()); } @Test void assertJobInit() { Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() -> MatcherAssert.assertThat(((AnnotationSimpleJob) getElasticJob()).isCompleted(), is(true))); - assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + "/sharding")); + assertTrue(getRegistryCenter().isExisted("/" + getJobName() + "/sharding")); } } 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..e4126b15dd 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,12 +38,12 @@ @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"); + private static ZookeeperConfiguration zookeeperConfig; @Getter(AccessLevel.PROTECTED) - private static final CoordinatorRegistryCenter REGISTRY_CENTER = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIG); + private static CoordinatorRegistryCenter registryCenter; private final ElasticJob elasticJob; @@ -59,7 +59,7 @@ protected BaseE2ETest(final TestType type, final ElasticJob elasticJob) { this.elasticJob = elasticJob; jobConfiguration = getJobConfiguration(jobName); jobBootstrap = createJobBootstrap(type, elasticJob); - leaderService = new LeaderService(REGISTRY_CENTER, jobName); + leaderService = new LeaderService(registryCenter, jobName); } protected abstract JobConfiguration getJobConfiguration(String jobName); @@ -67,9 +67,9 @@ protected BaseE2ETest(final TestType type, final ElasticJob elasticJob) { private JobBootstrap createJobBootstrap(final TestType type, final ElasticJob elasticJob) { switch (type) { case SCHEDULE: - return new ScheduleJobBootstrap(REGISTRY_CENTER, elasticJob, jobConfiguration); + return new ScheduleJobBootstrap(registryCenter, elasticJob, jobConfiguration); case ONE_OFF: - return new OneOffJobBootstrap(REGISTRY_CENTER, elasticJob, jobConfiguration); + return new OneOffJobBootstrap(registryCenter, elasticJob, jobConfiguration); default: throw new RuntimeException(String.format("Cannot support `%s`", type)); } @@ -78,8 +78,10 @@ private JobBootstrap createJobBootstrap(final TestType type, final ElasticJob el @BeforeAll static void init() { EMBED_TESTING_SERVER.start(); - ZOOKEEPER_CONFIG.setConnectionTimeoutMilliseconds(30000); - REGISTRY_CENTER.init(); + zookeeperConfig = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), "zkRegTestCenter"); + registryCenter = new ZookeeperRegistryCenter(zookeeperConfig); + zookeeperConfig.setConnectionTimeoutMilliseconds(30000); + registryCenter.init(); } @BeforeEach diff --git a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/disable/DisabledJobE2ETest.java b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/disable/DisabledJobE2ETest.java index f387b076d3..01ce148406 100644 --- a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/disable/DisabledJobE2ETest.java +++ b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/disable/DisabledJobE2ETest.java @@ -46,7 +46,7 @@ protected final void assertDisabledRegCenterInfo() { assertThat(JobRegistry.getInstance().getCurrentShardingTotalCount(getJobName()), is(3)); assertThat(JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp(), is(IpUtils.getIp())); }); - JobConfiguration jobConfig = YamlEngine.unmarshal(getREGISTRY_CENTER().get("/" + getJobName() + "/config"), JobConfigurationPOJO.class).toJobConfiguration(); + JobConfiguration jobConfig = YamlEngine.unmarshal(getRegistryCenter().get("/" + getJobName() + "/config"), JobConfigurationPOJO.class).toJobConfiguration(); assertThat(jobConfig.getShardingTotalCount(), is(3)); if (getJobBootstrap() instanceof ScheduleJobBootstrap) { assertThat(jobConfig.getCron(), is("0/1 * * * * ?")); @@ -54,7 +54,7 @@ protected final void assertDisabledRegCenterInfo() { assertNull(jobConfig.getCron()); } assertThat(jobConfig.getShardingItemParameters(), is("0=A,1=B,2=C")); - assertThat(getREGISTRY_CENTER().get("/" + getJobName() + "/servers/" + JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp()), is(ServerStatus.DISABLED.name())); - Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() -> assertThat(getREGISTRY_CENTER().get("/" + getJobName() + "/leader/election/instance"), is(IsNull.nullValue()))); + assertThat(getRegistryCenter().get("/" + getJobName() + "/servers/" + JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp()), is(ServerStatus.DISABLED.name())); + Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() -> assertThat(getRegistryCenter().get("/" + getJobName() + "/leader/election/instance"), is(IsNull.nullValue()))); } } diff --git a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/disable/ScheduleDisabledJobE2ETest.java b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/disable/ScheduleDisabledJobE2ETest.java index f397a43e4a..542923a629 100644 --- a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/disable/ScheduleDisabledJobE2ETest.java +++ b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/disable/ScheduleDisabledJobE2ETest.java @@ -51,12 +51,12 @@ void assertJobRunning() { } private void setJobEnable() { - getREGISTRY_CENTER().persist("/" + getJobName() + "/servers/" + JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp(), ServerStatus.ENABLED.name()); + getRegistryCenter().persist("/" + getJobName() + "/servers/" + JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp(), ServerStatus.ENABLED.name()); } private void assertEnabledRegCenterInfo() { - assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + "/instances/" + JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId())); - getREGISTRY_CENTER().remove("/" + getJobName() + "/leader/election"); - assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + "/sharding")); + assertTrue(getRegistryCenter().isExisted("/" + getJobName() + "/instances/" + JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId())); + getRegistryCenter().remove("/" + getJobName() + "/leader/election"); + assertTrue(getRegistryCenter().isExisted("/" + getJobName() + "/sharding")); } } diff --git a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/enable/EnabledJobE2ETest.java b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/enable/EnabledJobE2ETest.java index 8c3cd2b605..4ed1973f13 100644 --- a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/enable/EnabledJobE2ETest.java +++ b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/enable/EnabledJobE2ETest.java @@ -43,7 +43,7 @@ protected EnabledJobE2ETest(final TestType type, final ElasticJob elasticJob) { void assertEnabledRegCenterInfo() { assertThat(JobRegistry.getInstance().getCurrentShardingTotalCount(getJobName()), is(3)); assertThat(JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp(), is(IpUtils.getIp())); - JobConfiguration jobConfig = YamlEngine.unmarshal(getREGISTRY_CENTER().get("/" + getJobName() + "/config"), JobConfigurationPOJO.class).toJobConfiguration(); + JobConfiguration jobConfig = YamlEngine.unmarshal(getRegistryCenter().get("/" + getJobName() + "/config"), JobConfigurationPOJO.class).toJobConfiguration(); assertThat(jobConfig.getShardingTotalCount(), is(3)); if (getJobBootstrap() instanceof ScheduleJobBootstrap) { assertThat(jobConfig.getCron(), is("0/1 * * * * ?")); @@ -51,10 +51,10 @@ void assertEnabledRegCenterInfo() { assertNull(jobConfig.getCron()); } assertThat(jobConfig.getShardingItemParameters(), is("0=A,1=B,2=C")); - assertThat(getREGISTRY_CENTER().get("/" + getJobName() + "/servers/" + JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp()), is(ServerStatus.ENABLED.name())); - assertThat(getREGISTRY_CENTER().get("/" + getJobName() + "/leader/election/instance"), is(JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId())); - assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + "/instances/" + JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId())); - getREGISTRY_CENTER().remove("/" + getJobName() + "/leader/election"); + assertThat(getRegistryCenter().get("/" + getJobName() + "/servers/" + JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp()), is(ServerStatus.ENABLED.name())); + assertThat(getRegistryCenter().get("/" + getJobName() + "/leader/election/instance"), is(JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId())); + assertTrue(getRegistryCenter().isExisted("/" + getJobName() + "/instances/" + JobRegistry.getInstance().getJobInstance(getJobName()).getJobInstanceId())); + getRegistryCenter().remove("/" + getJobName() + "/leader/election"); assertTrue(getLeaderService().isLeaderUntilBlock()); } } diff --git a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/enable/OneOffEnabledJobE2ETest.java b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/enable/OneOffEnabledJobE2ETest.java index 6c117b347b..6b92e25b4a 100644 --- a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/enable/OneOffEnabledJobE2ETest.java +++ b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/enable/OneOffEnabledJobE2ETest.java @@ -43,6 +43,6 @@ protected JobConfiguration getJobConfiguration(final String jobName) { @Test void assertJobInit() { Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() -> assertThat(((E2EFixtureJobImpl) getElasticJob()).isCompleted(), is(true))); - assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + "/sharding")); + assertTrue(getRegistryCenter().isExisted("/" + getJobName() + "/sharding")); } } diff --git a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/enable/ScheduleEnabledJobE2ETest.java b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/enable/ScheduleEnabledJobE2ETest.java index d211e4fc02..449b0e8793 100644 --- a/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/enable/ScheduleEnabledJobE2ETest.java +++ b/test/e2e/src/test/java/org/apache/shardingsphere/elasticjob/test/e2e/raw/enable/ScheduleEnabledJobE2ETest.java @@ -43,6 +43,6 @@ protected JobConfiguration getJobConfiguration(final String jobName) { @Test void assertJobInit() { Awaitility.await().atMost(10L, TimeUnit.SECONDS).untilAsserted(() -> assertThat(((E2EFixtureJobImpl) getElasticJob()).isCompleted(), is(true))); - assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + "/sharding")); + assertTrue(getRegistryCenter().isExisted("/" + getJobName() + "/sharding")); } } 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..3e88a87f2c 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 @@ -19,6 +19,7 @@ import lombok.AccessLevel; import lombok.Getter; +import org.apache.curator.test.InstanceSpec; import org.apache.shardingsphere.elasticjob.api.ElasticJob; import org.apache.shardingsphere.elasticjob.api.JobConfiguration; import org.apache.shardingsphere.elasticjob.bootstrap.type.ScheduleJobBootstrap; @@ -35,17 +36,15 @@ public abstract class BaseSnapshotServiceE2ETest { - static final int DUMP_PORT = 9000; + static final int DUMP_PORT = InstanceSpec.getRandomPort(); - private static final EmbedTestingServer EMBED_TESTING_SERVER = new EmbedTestingServer(7181); - - private static final ZookeeperConfiguration ZOOKEEPER_CONFIG = new ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), "zkRegTestCenter"); + 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; private final ScheduleJobBootstrap bootstrap; @@ -53,19 +52,22 @@ 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); + snapshotService = new SnapshotService(regCenter, DUMP_PORT); + 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..30b7fbe2d7 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 @@ -41,13 +41,13 @@ void assertMonitorWithDumpCommand() { @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..461e92a946 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,12 +17,13 @@ package org.apache.shardingsphere.elasticjob.test.util; -import lombok.RequiredArgsConstructor; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.framework.imps.CuratorFrameworkState; import org.apache.curator.retry.ExponentialBackoffRetry; +import org.apache.curator.test.InstanceSpec; import org.apache.curator.test.TestingServer; import org.apache.zookeeper.KeeperException; @@ -33,7 +34,7 @@ /** * Embed ZooKeeper testing server. */ -@RequiredArgsConstructor +@AllArgsConstructor @Slf4j public final class EmbedTestingServer { @@ -43,6 +44,13 @@ public final class EmbedTestingServer { private final int port; + /** + * Create the server using a random port + */ + public EmbedTestingServer() { + this.port = InstanceSpec.getRandomPort(); + } + /** * Start embed zookeeper server. */ @@ -64,7 +72,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 +140,6 @@ private boolean isIgnoredException(final Throwable cause) { * @return connection string */ public String getConnectionString() { - return "localhost:" + port; + return testingServer.getConnectString(); } }