This is an automated email from the ASF dual-hosted git repository.
sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git
The following commit(s) were added to refs/heads/master by this push:
new ada191d2c Add test-util module (#2328)
ada191d2c is described below
commit ada191d2c5f2655673ea4d6574c4365de8e0325a
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Oct 28 23:34:55 2023 +0800
Add test-util module (#2328)
* Add test-util module
* Add test-util module
* Add test-util module
* Add test-util module
---
kernel/pom.xml | 11 +-
.../api/bootstrap/impl/OneOffJobBootstrapTest.java | 12 +-
.../kernel/integrate/BaseIntegrateTest.java | 8 +-
.../annotation/integrate/BaseAnnotationTest.java | 8 +-
.../internal/snapshot/BaseSnapshotServiceTest.java | 8 +-
pom.xml | 4 +
registry-center/provider/zookeeper-curator/pom.xml | 12 +-
.../zookeeper/ZookeeperElectionServiceTest.java | 12 +-
...ZookeeperRegistryCenterExecuteInLeaderTest.java | 8 +-
.../ZookeeperRegistryCenterForAuthTest.java | 12 +-
.../ZookeeperRegistryCenterMiscellaneousTest.java | 8 +-
.../ZookeeperRegistryCenterModifyTest.java | 14 ++-
.../ZookeeperRegistryCenterQueryWithCacheTest.java | 8 +-
...okeeperRegistryCenterQueryWithoutCacheTest.java | 8 +-
.../ZookeeperRegistryCenterTransactionTest.java | 8 +-
.../ZookeeperRegistryCenterWatchTest.java | 8 +-
.../reg/zookeeper/fixture/EmbedTestingServer.java | 135 ---------------------
spring/boot-starter/pom.xml | 10 +-
.../boot/job/ElasticJobSpringBootScannerTest.java | 4 +-
.../spring/boot/job/ElasticJobSpringBootTest.java | 8 +-
.../boot/job/fixture/EmbedTestingServer.java | 135 ---------------------
...ElasticJobSnapshotServiceConfigurationTest.java | 4 +-
.../boot/tracing/TracingConfigurationTest.java | 4 +-
.../provider/zookeeper-curator => test}/pom.xml | 37 ++----
.../zookeeper-curator => test/util}/pom.xml | 24 +---
.../elasticjob/test/util}/EmbedTestingServer.java | 30 ++---
26 files changed, 138 insertions(+), 402 deletions(-)
diff --git a/kernel/pom.xml b/kernel/pom.xml
index 7f354083d..6a0c2c1b6 100644
--- a/kernel/pom.xml
+++ b/kernel/pom.xml
@@ -74,6 +74,13 @@
<version>${project.parent.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere.elasticjob</groupId>
+ <artifactId>elasticjob-test-util</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
@@ -91,10 +98,6 @@
<artifactId>quartz</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-test</artifactId>
- </dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
diff --git
a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/api/bootstrap/impl/OneOffJobBootstrapTest.java
b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/api/bootstrap/impl/OneOffJobBootstrapTest.java
index f7110eef7..91e7c4d67 100644
---
a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/api/bootstrap/impl/OneOffJobBootstrapTest.java
+++
b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/api/bootstrap/impl/OneOffJobBootstrapTest.java
@@ -19,12 +19,12 @@ package
org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl;
import lombok.SneakyThrows;
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.kernel.fixture.EmbedTestingServer;
import
org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobScheduleController;
import
org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobScheduler;
import
org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import
org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@@ -42,7 +42,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class OneOffJobBootstrapTest {
- private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = new
ZookeeperConfiguration(EmbedTestingServer.getConnectionString(),
OneOffJobBootstrapTest.class.getSimpleName());
+ 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 int SHARDING_TOTAL_COUNT = 3;
@@ -50,7 +52,7 @@ class OneOffJobBootstrapTest {
@BeforeAll
static void init() {
- EmbedTestingServer.start();
+ EMBED_TESTING_SERVER.start();
}
@BeforeEach
@@ -60,7 +62,7 @@ class OneOffJobBootstrapTest {
}
@AfterEach
- void teardown() {
+ void tearDown() {
zkRegCenter.close();
}
@@ -108,7 +110,7 @@ class OneOffJobBootstrapTest {
private void blockUtilFinish(final OneOffJobBootstrap oneOffJobBootstrap,
final AtomicInteger counter) {
Scheduler scheduler = getScheduler(oneOffJobBootstrap);
while (0 == counter.get() ||
!scheduler.getCurrentlyExecutingJobs().isEmpty()) {
- Thread.sleep(100);
+ Thread.sleep(100L);
}
}
}
diff --git
a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/integrate/BaseIntegrateTest.java
b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/integrate/BaseIntegrateTest.java
index a91788f42..55b803da2 100644
---
a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/integrate/BaseIntegrateTest.java
+++
b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/integrate/BaseIntegrateTest.java
@@ -24,13 +24,13 @@ import
org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.JobBootstrap;
import
org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl.OneOffJobBootstrap;
import
org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl.ScheduleJobBootstrap;
-import org.apache.shardingsphere.elasticjob.kernel.fixture.EmbedTestingServer;
import
org.apache.shardingsphere.elasticjob.kernel.internal.election.LeaderService;
import
org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import
org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import
org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@@ -38,7 +38,9 @@ import org.junit.jupiter.api.BeforeEach;
@Getter(AccessLevel.PROTECTED)
public abstract class BaseIntegrateTest {
- private static final ZookeeperConfiguration ZOOKEEPER_CONFIG = new
ZookeeperConfiguration(EmbedTestingServer.getConnectionString(),
"zkRegTestCenter");
+ private static final EmbedTestingServer EMBED_TESTING_SERVER = new
EmbedTestingServer(7181);
+
+ private static final ZookeeperConfiguration ZOOKEEPER_CONFIG = new
ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(),
"zkRegTestCenter");
@Getter(AccessLevel.PROTECTED)
private static final CoordinatorRegistryCenter REGISTRY_CENTER = new
ZookeeperRegistryCenter(ZOOKEEPER_CONFIG);
@@ -75,7 +77,7 @@ public abstract class BaseIntegrateTest {
@BeforeAll
static void init() {
- EmbedTestingServer.start();
+ EMBED_TESTING_SERVER.start();
ZOOKEEPER_CONFIG.setConnectionTimeoutMilliseconds(30000);
REGISTRY_CENTER.init();
}
diff --git
a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/annotation/integrate/BaseAnnotationTest.java
b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/annotation/integrate/BaseAnnotationTest.java
index 1e92e5a25..3b729764c 100644
---
a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/annotation/integrate/BaseAnnotationTest.java
+++
b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/annotation/integrate/BaseAnnotationTest.java
@@ -24,7 +24,6 @@ import
org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.JobBootstrap;
import
org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl.OneOffJobBootstrap;
import
org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl.ScheduleJobBootstrap;
-import org.apache.shardingsphere.elasticjob.kernel.fixture.EmbedTestingServer;
import
org.apache.shardingsphere.elasticjob.kernel.internal.annotation.JobAnnotationBuilder;
import
org.apache.shardingsphere.elasticjob.kernel.internal.election.LeaderService;
import
org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
@@ -32,6 +31,7 @@ import
org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import
org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import
org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@@ -39,7 +39,9 @@ import org.junit.jupiter.api.BeforeEach;
@Getter(AccessLevel.PROTECTED)
public abstract class BaseAnnotationTest {
- private static final ZookeeperConfiguration ZOOKEEPER_CONFIG = new
ZookeeperConfiguration(EmbedTestingServer.getConnectionString(),
"zkRegTestCenter");
+ private static final EmbedTestingServer EMBED_TESTING_SERVER = new
EmbedTestingServer(7181);
+
+ private static final ZookeeperConfiguration ZOOKEEPER_CONFIG = new
ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(),
"zkRegTestCenter");
@Getter(AccessLevel.PROTECTED)
private static final CoordinatorRegistryCenter REGISTRY_CENTER = new
ZookeeperRegistryCenter(ZOOKEEPER_CONFIG);
@@ -75,7 +77,7 @@ public abstract class BaseAnnotationTest {
@BeforeAll
static void init() {
- EmbedTestingServer.start();
+ EMBED_TESTING_SERVER.start();
ZOOKEEPER_CONFIG.setConnectionTimeoutMilliseconds(30000);
REGISTRY_CENTER.init();
}
diff --git
a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/BaseSnapshotServiceTest.java
b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/BaseSnapshotServiceTest.java
index 98309a2cf..abf59a876 100644
---
a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/BaseSnapshotServiceTest.java
+++
b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/BaseSnapshotServiceTest.java
@@ -22,12 +22,12 @@ import lombok.Getter;
import org.apache.shardingsphere.elasticjob.api.ElasticJob;
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import
org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl.ScheduleJobBootstrap;
-import org.apache.shardingsphere.elasticjob.kernel.fixture.EmbedTestingServer;
import
org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import
org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import
org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@@ -36,7 +36,9 @@ public abstract class BaseSnapshotServiceTest {
static final int DUMP_PORT = 9000;
- private static final ZookeeperConfiguration ZOOKEEPER_CONFIG = new
ZookeeperConfiguration(EmbedTestingServer.getConnectionString(),
"zkRegTestCenter");
+ private static final EmbedTestingServer EMBED_TESTING_SERVER = new
EmbedTestingServer(7181);
+
+ private static final ZookeeperConfiguration ZOOKEEPER_CONFIG = new
ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(),
"zkRegTestCenter");
@Getter(value = AccessLevel.PROTECTED)
private static final CoordinatorRegistryCenter REG_CENTER = new
ZookeeperRegistryCenter(ZOOKEEPER_CONFIG);
@@ -55,7 +57,7 @@ public abstract class BaseSnapshotServiceTest {
@BeforeAll
static void init() {
- EmbedTestingServer.start();
+ EMBED_TESTING_SERVER.start();
ZOOKEEPER_CONFIG.setConnectionTimeoutMilliseconds(30000);
REG_CENTER.init();
}
diff --git a/pom.xml b/pom.xml
index 8bafe3435..49db7719f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -37,8 +37,12 @@
<module>kernel</module>
<module>lifecycle</module>
<module>restful</module>
+
<module>ecosystem</module>
<module>spring</module>
+
+ <module>test</module>
+
<module>distribution</module>
</modules>
diff --git a/registry-center/provider/zookeeper-curator/pom.xml
b/registry-center/provider/zookeeper-curator/pom.xml
index fb7221fee..539026923 100644
--- a/registry-center/provider/zookeeper-curator/pom.xml
+++ b/registry-center/provider/zookeeper-curator/pom.xml
@@ -33,6 +33,13 @@
<version>${project.parent.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere.elasticjob</groupId>
+ <artifactId>elasticjob-test-util</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
@@ -45,10 +52,5 @@
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
</dependency>
-
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-test</artifactId>
- </dependency>
</dependencies>
</project>
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 ec14a7a95..9256db60f 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
@@ -24,7 +24,7 @@ import
org.apache.curator.framework.recipes.leader.LeaderSelector;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.KillSession;
import org.apache.shardingsphere.elasticjob.reg.base.ElectionCandidate;
-import
org.apache.shardingsphere.elasticjob.reg.zookeeper.fixture.EmbedTestingServer;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -42,6 +42,8 @@ import static org.mockito.Mockito.verify;
@ExtendWith(MockitoExtension.class)
class ZookeeperElectionServiceTest {
+ private static final EmbedTestingServer EMBED_TESTING_SERVER = new
EmbedTestingServer(9181);
+
private static final String HOST_AND_PORT = "localhost:8899";
private static final String ELECTION_PATH = "/election";
@@ -51,18 +53,18 @@ class ZookeeperElectionServiceTest {
@BeforeAll
static void init() {
- EmbedTestingServer.start();
+ EMBED_TESTING_SERVER.start();
}
@Test
void assertContend() throws Exception {
- CuratorFramework client =
CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new
RetryOneTime(2000));
+ CuratorFramework client =
CuratorFrameworkFactory.newClient(EMBED_TESTING_SERVER.getConnectionString(),
new RetryOneTime(2000));
client.start();
client.blockUntilConnected();
ZookeeperElectionService service = new
ZookeeperElectionService(HOST_AND_PORT, client, ELECTION_PATH,
electionCandidate);
service.start();
ElectionCandidate anotherElectionCandidate =
mock(ElectionCandidate.class);
- CuratorFramework anotherClient =
CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new
RetryOneTime(2000));
+ CuratorFramework anotherClient =
CuratorFrameworkFactory.newClient(EMBED_TESTING_SERVER.getConnectionString(),
new RetryOneTime(2000));
ZookeeperElectionService anotherService = new
ZookeeperElectionService("ANOTHER_CLIENT:8899", anotherClient, ELECTION_PATH,
anotherElectionCandidate);
anotherClient.start();
anotherClient.blockUntilConnected();
@@ -80,7 +82,7 @@ class ZookeeperElectionServiceTest {
@SneakyThrows
private void blockUntilCondition(final Supplier<Boolean> condition) {
while (!condition.get()) {
- Thread.sleep(100);
+ Thread.sleep(100L);
}
}
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 ec43699cc..2bead8dae 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
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.elasticjob.reg.zookeeper;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.elasticjob.reg.base.LeaderExecutionCallback;
-import
org.apache.shardingsphere.elasticjob.reg.zookeeper.fixture.EmbedTestingServer;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -33,14 +33,16 @@ import java.util.concurrent.atomic.AtomicBoolean;
class ZookeeperRegistryCenterExecuteInLeaderTest {
+ private static final EmbedTestingServer EMBED_TESTING_SERVER = new
EmbedTestingServer(9181);
+
private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION =
- new
ZookeeperConfiguration(EmbedTestingServer.getConnectionString(),
ZookeeperRegistryCenterExecuteInLeaderTest.class.getName());
+ new
ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(),
ZookeeperRegistryCenterExecuteInLeaderTest.class.getName());
private static ZookeeperRegistryCenter zkRegCenter;
@BeforeAll
static void setUp() {
- EmbedTestingServer.start();
+ EMBED_TESTING_SERVER.start();
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
ZOOKEEPER_CONFIGURATION.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 c86f4396f..34fa53a61 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
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.elasticjob.reg.zookeeper;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryOneTime;
-import
org.apache.shardingsphere.elasticjob.reg.zookeeper.fixture.EmbedTestingServer;
import
org.apache.shardingsphere.elasticjob.reg.zookeeper.util.ZookeeperRegistryCenterTestUtil;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.apache.zookeeper.KeeperException.NoAuthException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
@@ -33,15 +33,17 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
class ZookeeperRegistryCenterForAuthTest {
+ private static final EmbedTestingServer EMBED_TESTING_SERVER = new
EmbedTestingServer(9181);
+
private static final String NAME_SPACE =
ZookeeperRegistryCenterForAuthTest.class.getName();
- private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = new
ZookeeperConfiguration(EmbedTestingServer.getConnectionString(), NAME_SPACE);
+ private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = new
ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(), NAME_SPACE);
private static ZookeeperRegistryCenter zkRegCenter;
@BeforeAll
static void setUp() {
- EmbedTestingServer.start();
+ EMBED_TESTING_SERVER.start();
ZOOKEEPER_CONFIGURATION.setDigest("digest:password");
ZOOKEEPER_CONFIGURATION.setSessionTimeoutMilliseconds(5000);
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(5000);
@@ -58,7 +60,7 @@ class ZookeeperRegistryCenterForAuthTest {
@Test
void assertInitWithDigestSuccess() throws Exception {
CuratorFramework client = CuratorFrameworkFactory.builder()
- .connectString(EmbedTestingServer.getConnectionString())
+ .connectString(EMBED_TESTING_SERVER.getConnectionString())
.retryPolicy(new RetryOneTime(2000))
.authorization("digest", "digest:password".getBytes()).build();
client.start();
@@ -69,7 +71,7 @@ class ZookeeperRegistryCenterForAuthTest {
@Test
void assertInitWithDigestFailure() {
assertThrows(NoAuthException.class, () -> {
- CuratorFramework client =
CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new
RetryOneTime(2000));
+ CuratorFramework client =
CuratorFrameworkFactory.newClient(EMBED_TESTING_SERVER.getConnectionString(),
new RetryOneTime(2000));
client.start();
client.blockUntilConnected();
client.getData().forPath("/" +
ZookeeperRegistryCenterForAuthTest.class.getName() + "/test/deep/nested");
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 d5fc1fe65..c92d55198 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
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.elasticjob.reg.zookeeper;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.CuratorCache;
-import
org.apache.shardingsphere.elasticjob.reg.zookeeper.fixture.EmbedTestingServer;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -30,14 +30,16 @@ import static org.hamcrest.MatcherAssert.assertThat;
class ZookeeperRegistryCenterMiscellaneousTest {
+ private static final EmbedTestingServer EMBED_TESTING_SERVER = new
EmbedTestingServer(9181);
+
private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION =
- new
ZookeeperConfiguration(EmbedTestingServer.getConnectionString(),
ZookeeperRegistryCenterMiscellaneousTest.class.getName());
+ new
ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(),
ZookeeperRegistryCenterMiscellaneousTest.class.getName());
private static ZookeeperRegistryCenter zkRegCenter;
@BeforeAll
static void setUp() {
- EmbedTestingServer.start();
+ EMBED_TESTING_SERVER.start();
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
zkRegCenter.init();
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 573639051..10eda57b7 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
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.elasticjob.reg.zookeeper;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryOneTime;
-import
org.apache.shardingsphere.elasticjob.reg.zookeeper.fixture.EmbedTestingServer;
import
org.apache.shardingsphere.elasticjob.reg.zookeeper.util.ZookeeperRegistryCenterTestUtil;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -37,13 +37,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class ZookeeperRegistryCenterModifyTest {
- private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = new
ZookeeperConfiguration(EmbedTestingServer.getConnectionString(),
ZookeeperRegistryCenterModifyTest.class.getName());
+ 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 ZookeeperRegistryCenter zkRegCenter;
@BeforeAll
static void setUp() {
- EmbedTestingServer.start();
+ EMBED_TESTING_SERVER.start();
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
zkRegCenter.init();
@@ -77,7 +79,7 @@ class ZookeeperRegistryCenterModifyTest {
assertThat(zkRegCenter.get("/persist"), is("persist_value"));
assertThat(zkRegCenter.get("/ephemeral"), is("ephemeral_value"));
zkRegCenter.close();
- CuratorFramework client =
CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new
RetryOneTime(2000));
+ CuratorFramework client =
CuratorFrameworkFactory.newClient(EMBED_TESTING_SERVER.getConnectionString(),
new RetryOneTime(2000));
client.start();
client.blockUntilConnected();
assertThat(client.getData().forPath("/" +
ZookeeperRegistryCenterModifyTest.class.getName() + "/persist"),
is("persist_value".getBytes()));
@@ -89,7 +91,7 @@ class ZookeeperRegistryCenterModifyTest {
void assertPersistSequential() throws Exception {
assertThat(zkRegCenter.persistSequential("/sequential/test_sequential",
"test_value"), startsWith("/sequential/test_sequential"));
assertThat(zkRegCenter.persistSequential("/sequential/test_sequential",
"test_value"), startsWith("/sequential/test_sequential"));
- CuratorFramework client =
CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new
RetryOneTime(2000));
+ CuratorFramework client =
CuratorFrameworkFactory.newClient(EMBED_TESTING_SERVER.getConnectionString(),
new RetryOneTime(2000));
client.start();
client.blockUntilConnected();
List<String> actual = client.getChildren().forPath("/" +
ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
@@ -106,7 +108,7 @@ class ZookeeperRegistryCenterModifyTest {
void assertPersistEphemeralSequential() throws Exception {
zkRegCenter.persistEphemeralSequential("/sequential/test_ephemeral_sequential");
zkRegCenter.persistEphemeralSequential("/sequential/test_ephemeral_sequential");
- CuratorFramework client =
CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new
RetryOneTime(2000));
+ CuratorFramework client =
CuratorFrameworkFactory.newClient(EMBED_TESTING_SERVER.getConnectionString(),
new RetryOneTime(2000));
client.start();
client.blockUntilConnected();
List<String> actual = client.getChildren().forPath("/" +
ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
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 7a54c8085..5a2730690 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
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.elasticjob.reg.zookeeper;
-import
org.apache.shardingsphere.elasticjob.reg.zookeeper.fixture.EmbedTestingServer;
import
org.apache.shardingsphere.elasticjob.reg.zookeeper.util.ZookeeperRegistryCenterTestUtil;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -29,14 +29,16 @@ import static org.junit.jupiter.api.Assertions.assertNull;
class ZookeeperRegistryCenterQueryWithCacheTest {
+ private static final EmbedTestingServer EMBED_TESTING_SERVER = new
EmbedTestingServer(9181);
+
private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION =
- new
ZookeeperConfiguration(EmbedTestingServer.getConnectionString(),
ZookeeperRegistryCenterQueryWithCacheTest.class.getName());
+ new
ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(),
ZookeeperRegistryCenterQueryWithCacheTest.class.getName());
private static ZookeeperRegistryCenter zkRegCenter;
@BeforeAll
static void setUp() {
- EmbedTestingServer.start();
+ EMBED_TESTING_SERVER.start();
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
zkRegCenter.init();
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 c15e81dd2..99fa81960 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
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.elasticjob.reg.zookeeper;
-import
org.apache.shardingsphere.elasticjob.reg.zookeeper.fixture.EmbedTestingServer;
import
org.apache.shardingsphere.elasticjob.reg.zookeeper.util.ZookeeperRegistryCenterTestUtil;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -34,14 +34,16 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class ZookeeperRegistryCenterQueryWithoutCacheTest {
+ private static final EmbedTestingServer EMBED_TESTING_SERVER = new
EmbedTestingServer(9181);
+
private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION =
- new
ZookeeperConfiguration(EmbedTestingServer.getConnectionString(),
ZookeeperRegistryCenterQueryWithoutCacheTest.class.getName());
+ new
ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(),
ZookeeperRegistryCenterQueryWithoutCacheTest.class.getName());
private static ZookeeperRegistryCenter zkRegCenter;
@BeforeAll
static void setUp() {
- EmbedTestingServer.start();
+ EMBED_TESTING_SERVER.start();
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
zkRegCenter.init();
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 6ff7882c1..d52072810 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
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.elasticjob.reg.zookeeper;
import
org.apache.shardingsphere.elasticjob.reg.base.transaction.TransactionOperation;
-import
org.apache.shardingsphere.elasticjob.reg.zookeeper.fixture.EmbedTestingServer;
import
org.apache.shardingsphere.elasticjob.reg.zookeeper.util.ZookeeperRegistryCenterTestUtil;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.apache.zookeeper.KeeperException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@@ -34,14 +34,16 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
class ZookeeperRegistryCenterTransactionTest {
+ private static final EmbedTestingServer EMBED_TESTING_SERVER = new
EmbedTestingServer(9181);
+
private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION =
- new
ZookeeperConfiguration(EmbedTestingServer.getConnectionString(),
ZookeeperRegistryCenterTransactionTest.class.getName());
+ new
ZookeeperConfiguration(EMBED_TESTING_SERVER.getConnectionString(),
ZookeeperRegistryCenterTransactionTest.class.getName());
private static ZookeeperRegistryCenter zkRegCenter;
@BeforeAll
static void setUp() {
- EmbedTestingServer.start();
+ EMBED_TESTING_SERVER.start();
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
ZOOKEEPER_CONFIGURATION.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 872035822..8318bc4f9 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
@@ -19,8 +19,8 @@ package org.apache.shardingsphere.elasticjob.reg.zookeeper;
import org.apache.curator.utils.ThreadUtils;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent;
-import
org.apache.shardingsphere.elasticjob.reg.zookeeper.fixture.EmbedTestingServer;
import
org.apache.shardingsphere.elasticjob.reg.zookeeper.util.ZookeeperRegistryCenterTestUtil;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -37,13 +37,15 @@ import static org.hamcrest.MatcherAssert.assertThat;
class ZookeeperRegistryCenterWatchTest {
- private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = new
ZookeeperConfiguration(EmbedTestingServer.getConnectionString(),
ZookeeperRegistryCenterWatchTest.class.getName());
+ 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 ZookeeperRegistryCenter zkRegCenter;
@BeforeAll
static void setUp() {
- EmbedTestingServer.start();
+ EMBED_TESTING_SERVER.start();
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
zkRegCenter.init();
diff --git
a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/fixture/EmbedTestingServer.java
b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/fixture/EmbedTestingServer.java
deleted file mode 100644
index 70ae28a00..000000000
---
a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/fixture/EmbedTestingServer.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.elasticjob.reg.zookeeper.fixture;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-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.TestingServer;
-import org.apache.zookeeper.KeeperException;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.concurrent.TimeUnit;
-
-@Slf4j
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class EmbedTestingServer {
-
- private static final int PORT = 9181;
-
- private static volatile TestingServer testingServer;
-
- private static final Object INIT_LOCK = new Object();
-
- /**
- * Start embed zookeeper server.
- */
- public static void start() {
- if (null != testingServer) {
- log.info("Embed zookeeper server already exists 1, on {}",
testingServer.getConnectString());
- return;
- }
- log.info("Starting embed zookeeper server...");
- synchronized (INIT_LOCK) {
- if (null != testingServer) {
- log.info("Embed zookeeper server already exists 2, on {}",
testingServer.getConnectString());
- return;
- }
- start0();
- waitTestingServerReady();
- }
- }
-
- private static void start0() {
- try {
- testingServer = new TestingServer(PORT, true);
- // CHECKSTYLE:OFF
- } catch (final Exception ex) {
- // CHECKSTYLE:ON
- if (!isIgnoredException(ex)) {
- throw new RuntimeException(ex);
- } else {
- log.warn("Start embed zookeeper server got exception: {}",
ex.getMessage());
- }
- } finally {
- Runtime.getRuntime().addShutdownHook(new Thread(() -> {
- try {
- testingServer.close();
- } catch (final IOException ignored) {
- }
- log.info("Close embed zookeeper server done");
- }));
- }
- }
-
- private static void waitTestingServerReady() {
- int maxRetries = 60;
- try (CuratorFramework client = buildCuratorClient()) {
- client.start();
- int round = 0;
- while (round < maxRetries) {
- try {
- if (client.getZookeeperClient().isConnected()) {
- log.info("client is connected");
- break;
- }
- if (client.blockUntilConnected(500,
TimeUnit.MILLISECONDS)) {
- CuratorFrameworkState state = client.getState();
- Collection<String> childrenKeys =
client.getChildren().forPath("/");
- log.info("TestingServer connected, state={},
childrenKeys={}", state, childrenKeys);
- break;
- }
- // CHECKSTYLE:OFF
- } catch (final Exception ignored) {
- // CHECKSTYLE:ON
- }
- ++round;
- }
- }
- }
-
- private static CuratorFramework buildCuratorClient() {
- CuratorFrameworkFactory.Builder builder =
CuratorFrameworkFactory.builder();
- int retryIntervalMilliseconds = 500;
- int maxRetries = 3;
- builder.connectString(getConnectionString())
- .retryPolicy(new
ExponentialBackoffRetry(retryIntervalMilliseconds, maxRetries,
retryIntervalMilliseconds * maxRetries))
- .namespace("test");
- builder.sessionTimeoutMs(60 * 1000);
- builder.connectionTimeoutMs(500);
- return builder.build();
- }
-
- private static boolean isIgnoredException(final Throwable cause) {
- return cause instanceof KeeperException.ConnectionLossException ||
cause instanceof KeeperException.NoNodeException || cause instanceof
KeeperException.NodeExistsException;
- }
-
- /**
- * Get the connection string.
- *
- * @return connection string
- */
- public static String getConnectionString() {
- return "localhost:" + PORT;
- }
-}
diff --git a/spring/boot-starter/pom.xml b/spring/boot-starter/pom.xml
index 805c895f8..d747fdf58 100644
--- a/spring/boot-starter/pom.xml
+++ b/spring/boot-starter/pom.xml
@@ -32,6 +32,12 @@
<artifactId>elasticjob-spring-core</artifactId>
<version>${project.parent.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere.elasticjob</groupId>
+ <artifactId>elasticjob-test-util</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -53,10 +59,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-test</artifactId>
- </dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
diff --git
a/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobSpringBootScannerTest.java
b/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobSpringBootScannerTest.java
index 2e4a8630f..c95e43091 100644
---
a/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobSpringBootScannerTest.java
+++
b/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobSpringBootScannerTest.java
@@ -18,9 +18,9 @@
package org.apache.shardingsphere.elasticjob.spring.boot.job;
import
org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl.ScheduleJobBootstrap;
-import
org.apache.shardingsphere.elasticjob.spring.boot.job.fixture.EmbedTestingServer;
import
org.apache.shardingsphere.elasticjob.spring.boot.job.fixture.job.impl.AnnotationCustomJob;
import org.apache.shardingsphere.elasticjob.spring.core.scanner.ElasticJobScan;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -46,7 +46,7 @@ class ElasticJobSpringBootScannerTest {
@BeforeAll
static void init() {
- EmbedTestingServer.start();
+ new EmbedTestingServer(18181).start();
AnnotationCustomJob.reset();
}
diff --git
a/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobSpringBootTest.java
b/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobSpringBootTest.java
index 6774eb45c..2cd365349 100644
---
a/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobSpringBootTest.java
+++
b/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobSpringBootTest.java
@@ -24,10 +24,10 @@ import
org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl.OneOffJobB
import
org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl.ScheduleJobBootstrap;
import
org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobScheduler;
import
org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
-import
org.apache.shardingsphere.elasticjob.spring.boot.job.fixture.EmbedTestingServer;
import
org.apache.shardingsphere.elasticjob.spring.boot.job.fixture.job.impl.CustomTestJob;
import
org.apache.shardingsphere.elasticjob.spring.boot.reg.ZookeeperProperties;
import
org.apache.shardingsphere.elasticjob.spring.boot.tracing.TracingProperties;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.BeforeAll;
@@ -60,19 +60,21 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@ActiveProfiles("elasticjob")
class ElasticJobSpringBootTest {
+ private static final EmbedTestingServer EMBED_TESTING_SERVER = new
EmbedTestingServer(18181);
+
@Autowired
private ApplicationContext applicationContext;
@BeforeAll
static void init() {
- EmbedTestingServer.start();
+ EMBED_TESTING_SERVER.start();
}
@Test
void assertZookeeperProperties() {
assertNotNull(applicationContext);
ZookeeperProperties actual =
applicationContext.getBean(ZookeeperProperties.class);
- assertThat(actual.getServerLists(),
is(EmbedTestingServer.getConnectionString()));
+ assertThat(actual.getServerLists(),
is(EMBED_TESTING_SERVER.getConnectionString()));
assertThat(actual.getNamespace(),
is("elasticjob-spring-boot-starter"));
}
diff --git
a/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/fixture/EmbedTestingServer.java
b/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/fixture/EmbedTestingServer.java
deleted file mode 100644
index dacd73e0c..000000000
---
a/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/fixture/EmbedTestingServer.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.elasticjob.spring.boot.job.fixture;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-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.TestingServer;
-import org.apache.zookeeper.KeeperException;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.concurrent.TimeUnit;
-
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-@Slf4j
-public final class EmbedTestingServer {
-
- private static final int PORT = 18181;
-
- private static volatile TestingServer testingServer;
-
- private static final Object INIT_LOCK = new Object();
-
- /**
- * Start embed zookeeper server.
- */
- public static void start() {
- if (null != testingServer) {
- log.info("Embed zookeeper server already exists 1, on {}",
testingServer.getConnectString());
- return;
- }
- log.info("Starting embed zookeeper server...");
- synchronized (INIT_LOCK) {
- if (null != testingServer) {
- log.info("Embed zookeeper server already exists 2, on {}",
testingServer.getConnectString());
- return;
- }
- start0();
- waitTestingServerReady();
- }
- }
-
- private static void start0() {
- try {
- testingServer = new TestingServer(PORT, true);
- // CHECKSTYLE:OFF
- } catch (final Exception ex) {
- // CHECKSTYLE:ON
- if (!isIgnoredException(ex)) {
- throw new RuntimeException(ex);
- } else {
- log.warn("Start embed zookeeper server got exception: {}",
ex.getMessage());
- }
- } finally {
- Runtime.getRuntime().addShutdownHook(new Thread(() -> {
- try {
- testingServer.close();
- } catch (final IOException ignored) {
- }
- log.info("Close embed zookeeper server done");
- }));
- }
- }
-
- private static void waitTestingServerReady() {
- int maxRetries = 60;
- try (CuratorFramework client = buildCuratorClient()) {
- client.start();
- int round = 0;
- while (round < maxRetries) {
- try {
- if (client.getZookeeperClient().isConnected()) {
- log.info("client is connected");
- break;
- }
- if (client.blockUntilConnected(500,
TimeUnit.MILLISECONDS)) {
- CuratorFrameworkState state = client.getState();
- Collection<String> childrenKeys =
client.getChildren().forPath("/");
- log.info("TestingServer connected, state={},
childrenKeys={}", state, childrenKeys);
- break;
- }
- // CHECKSTYLE:OFF
- } catch (final Exception ignored) {
- // CHECKSTYLE:ON
- }
- ++round;
- }
- }
- }
-
- private static CuratorFramework buildCuratorClient() {
- CuratorFrameworkFactory.Builder builder =
CuratorFrameworkFactory.builder();
- int retryIntervalMilliseconds = 500;
- int maxRetries = 3;
- builder.connectString(getConnectionString())
- .retryPolicy(new
ExponentialBackoffRetry(retryIntervalMilliseconds, maxRetries,
retryIntervalMilliseconds * maxRetries))
- .namespace("test");
- builder.sessionTimeoutMs(60 * 1000);
- builder.connectionTimeoutMs(500);
- return builder.build();
- }
-
- private static boolean isIgnoredException(final Throwable cause) {
- return cause instanceof KeeperException.ConnectionLossException ||
cause instanceof KeeperException.NoNodeException || cause instanceof
KeeperException.NodeExistsException;
- }
-
- /**
- * Get the connection string.
- *
- * @return connection string
- */
- public static String getConnectionString() {
- return "localhost:" + PORT;
- }
-}
diff --git
a/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/reg/snapshot/ElasticJobSnapshotServiceConfigurationTest.java
b/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/reg/snapshot/ElasticJobSnapshotServiceConfigurationTest.java
index ac3bfea06..42736a9dd 100644
---
a/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/reg/snapshot/ElasticJobSnapshotServiceConfigurationTest.java
+++
b/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/reg/snapshot/ElasticJobSnapshotServiceConfigurationTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.elasticjob.spring.boot.reg.snapshot;
import
org.apache.shardingsphere.elasticjob.kernel.internal.snapshot.SnapshotService;
-import
org.apache.shardingsphere.elasticjob.spring.boot.job.fixture.EmbedTestingServer;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -39,7 +39,7 @@ class ElasticJobSnapshotServiceConfigurationTest {
@BeforeAll
static void init() {
- EmbedTestingServer.start();
+ new EmbedTestingServer(18181).start();
}
@Test
diff --git
a/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/TracingConfigurationTest.java
b/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/TracingConfigurationTest.java
index 89f029a5b..c88e187d7 100644
---
a/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/TracingConfigurationTest.java
+++
b/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/TracingConfigurationTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.elasticjob.spring.boot.tracing;
-import
org.apache.shardingsphere.elasticjob.spring.boot.job.fixture.EmbedTestingServer;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -45,7 +45,7 @@ class TracingConfigurationTest {
@BeforeAll
static void init() {
- EmbedTestingServer.start();
+ new EmbedTestingServer(18181).start();
}
@Test
diff --git a/registry-center/provider/zookeeper-curator/pom.xml b/test/pom.xml
similarity index 55%
copy from registry-center/provider/zookeeper-curator/pom.xml
copy to test/pom.xml
index fb7221fee..d2a8a291e 100644
--- a/registry-center/provider/zookeeper-curator/pom.xml
+++ b/test/pom.xml
@@ -6,9 +6,9 @@
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,35 +20,14 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere.elasticjob</groupId>
- <artifactId>elasticjob-regitry-center-provider</artifactId>
+ <artifactId>elasticjob</artifactId>
<version>3.1.0-SNAPSHOT</version>
</parent>
- <artifactId>elasticjob-registry-center-zookeeper-curator</artifactId>
+ <artifactId>elasticjob-test</artifactId>
+ <packaging>pom</packaging>
<name>${project.artifactId}</name>
- <dependencies>
- <dependency>
- <groupId>org.apache.shardingsphere.elasticjob</groupId>
- <artifactId>elasticjob-registry-center-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-framework</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-client</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-recipes</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-test</artifactId>
- </dependency>
- </dependencies>
+ <modules>
+ <module>util</module>
+ </modules>
</project>
diff --git a/registry-center/provider/zookeeper-curator/pom.xml
b/test/util/pom.xml
similarity index 70%
copy from registry-center/provider/zookeeper-curator/pom.xml
copy to test/util/pom.xml
index fb7221fee..96e14fc0f 100644
--- a/registry-center/provider/zookeeper-curator/pom.xml
+++ b/test/util/pom.xml
@@ -6,9 +6,9 @@
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,35 +20,21 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere.elasticjob</groupId>
- <artifactId>elasticjob-regitry-center-provider</artifactId>
+ <artifactId>elasticjob-test</artifactId>
<version>3.1.0-SNAPSHOT</version>
</parent>
- <artifactId>elasticjob-registry-center-zookeeper-curator</artifactId>
+ <artifactId>elasticjob-test-util</artifactId>
<name>${project.artifactId}</name>
<dependencies>
- <dependency>
- <groupId>org.apache.shardingsphere.elasticjob</groupId>
- <artifactId>elasticjob-registry-center-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
-
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-client</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-recipes</artifactId>
- </dependency>
-
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
+ <scope>compile</scope>
</dependency>
</dependencies>
</project>
diff --git
a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/fixture/EmbedTestingServer.java
b/test/util/src/main/java/org/apache/shardingsphere/elasticjob/test/util/EmbedTestingServer.java
similarity index 88%
rename from
kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/fixture/EmbedTestingServer.java
rename to
test/util/src/main/java/org/apache/shardingsphere/elasticjob/test/util/EmbedTestingServer.java
index 6c704fb40..ee460f25c 100644
---
a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/fixture/EmbedTestingServer.java
+++
b/test/util/src/main/java/org/apache/shardingsphere/elasticjob/test/util/EmbedTestingServer.java
@@ -15,10 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.kernel.fixture;
+package org.apache.shardingsphere.elasticjob.test.util;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -31,20 +30,23 @@ import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
+/**
+ * Embed ZooKeeper testing server.
+ */
+@RequiredArgsConstructor
@Slf4j
public final class EmbedTestingServer {
- private static final int PORT = 7181;
-
private static volatile TestingServer testingServer;
private static final Object INIT_LOCK = new Object();
+ private final int port;
+
/**
* Start embed zookeeper server.
*/
- public static void start() {
+ public void start() {
if (null != testingServer) {
log.info("Embed zookeeper server already exists 1, on {}",
testingServer.getConnectString());
return;
@@ -60,9 +62,9 @@ public final class EmbedTestingServer {
}
}
- private static void start0() {
+ private void start0() {
try {
- testingServer = new TestingServer(PORT, true);
+ testingServer = new TestingServer(port, true);
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
@@ -82,7 +84,7 @@ public final class EmbedTestingServer {
}
}
- private static void waitTestingServerReady() {
+ private void waitTestingServerReady() {
int maxRetries = 60;
try (CuratorFramework client = buildCuratorClient()) {
client.start();
@@ -108,7 +110,7 @@ public final class EmbedTestingServer {
}
}
- private static CuratorFramework buildCuratorClient() {
+ private CuratorFramework buildCuratorClient() {
CuratorFrameworkFactory.Builder builder =
CuratorFrameworkFactory.builder();
int retryIntervalMilliseconds = 500;
int maxRetries = 3;
@@ -120,7 +122,7 @@ public final class EmbedTestingServer {
return builder.build();
}
- private static boolean isIgnoredException(final Throwable cause) {
+ private boolean isIgnoredException(final Throwable cause) {
return cause instanceof KeeperException.ConnectionLossException ||
cause instanceof KeeperException.NoNodeException || cause instanceof
KeeperException.NodeExistsException;
}
@@ -129,7 +131,7 @@ public final class EmbedTestingServer {
*
* @return connection string
*/
- public static String getConnectionString() {
- return "localhost:" + PORT;
+ public String getConnectionString() {
+ return "localhost:" + port;
}
}