This is an automated email from the ASF dual-hosted git repository.

jianglongtao 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 7b5a5406a Use EmbedTestingServer on spring-namespace module (#2330)
7b5a5406a is described below

commit 7b5a5406ae501e620fb316017c63bf77b46ae095
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Oct 29 00:28:18 2023 +0800

    Use EmbedTestingServer on spring-namespace module (#2330)
---
 lifecycle/pom.xml                                  |   4 -
 spring/namespace/pom.xml                           |  11 +-
 .../job/AbstractJobSpringIntegrateTest.java        |  17 ++-
 .../job/AbstractOneOffJobSpringIntegrateTest.java  |  17 ++-
 .../job/JobSpringNamespaceWithRefTest.java         |  17 ++-
 .../job/JobSpringNamespaceWithTypeTest.java        |  15 ++-
 .../job/OneOffJobSpringNamespaceWithRefTest.java   |  17 ++-
 .../job/OneOffJobSpringNamespaceWithTypeTest.java  |  15 ++-
 .../scanner/AbstractJobSpringIntegrateTest.java    |  17 ++-
 .../SnapshotSpringNamespaceDisableTest.java        |  15 ++-
 .../SnapshotSpringNamespaceEnableTest.java         |  15 ++-
 ...actZookeeperJUnitJupiterSpringContextTests.java |  33 -----
 .../test/EmbedZookeeperTestExecutionListener.java  | 142 ---------------------
 13 files changed, 129 insertions(+), 206 deletions(-)

diff --git a/lifecycle/pom.xml b/lifecycle/pom.xml
index e3166172b..6432c4edf 100644
--- a/lifecycle/pom.xml
+++ b/lifecycle/pom.xml
@@ -50,9 +50,5 @@
             <groupId>commons-codec</groupId>
             <artifactId>commons-codec</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.apache.curator</groupId>
-            <artifactId>curator-test</artifactId>
-        </dependency>
     </dependencies>
 </project>
diff --git a/spring/namespace/pom.xml b/spring/namespace/pom.xml
index 53a038bb7..48ba28d34 100644
--- a/spring/namespace/pom.xml
+++ b/spring/namespace/pom.xml
@@ -52,6 +52,13 @@
             <scope>provided</scope>
         </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</groupId>
             <artifactId>spring-context</artifactId>
@@ -65,10 +72,6 @@
             <groupId>org.aspectj</groupId>
             <artifactId>aspectjweaver</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.apache.curator</groupId>
-            <artifactId>curator-test</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-test</artifactId>
diff --git 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/AbstractJobSpringIntegrateTest.java
 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/AbstractJobSpringIntegrateTest.java
index 0fe0e9f51..aa501154d 100644
--- 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/AbstractJobSpringIntegrateTest.java
+++ 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/AbstractJobSpringIntegrateTest.java
@@ -19,15 +19,18 @@ package 
org.apache.shardingsphere.elasticjob.spring.namespace.job;
 
 import lombok.RequiredArgsConstructor;
 import 
org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
+import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
 import 
org.apache.shardingsphere.elasticjob.spring.namespace.fixture.job.DataflowElasticJob;
 import 
org.apache.shardingsphere.elasticjob.spring.namespace.fixture.job.FooSimpleElasticJob;
-import 
org.apache.shardingsphere.elasticjob.spring.namespace.test.AbstractZookeeperJUnitJupiterSpringContextTests;
-import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
 import org.awaitility.Awaitility;
 import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 import java.util.concurrent.TimeUnit;
 
@@ -35,8 +38,11 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+@ExtendWith(SpringExtension.class)
 @RequiredArgsConstructor
-public abstract class AbstractJobSpringIntegrateTest extends 
AbstractZookeeperJUnitJupiterSpringContextTests {
+public abstract class AbstractJobSpringIntegrateTest {
+    
+    private static final EmbedTestingServer EMBED_TESTING_SERVER = new 
EmbedTestingServer(3181);
     
     private final String simpleJobName;
     
@@ -45,6 +51,11 @@ public abstract class AbstractJobSpringIntegrateTest extends 
AbstractZookeeperJU
     @Autowired
     private CoordinatorRegistryCenter regCenter;
     
+    @BeforeAll
+    static void init() {
+        EMBED_TESTING_SERVER.start();
+    }
+    
     @BeforeEach
     @AfterEach
     void reset() {
diff --git 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/AbstractOneOffJobSpringIntegrateTest.java
 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/AbstractOneOffJobSpringIntegrateTest.java
index d690c6b49..3682c0b2a 100644
--- 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/AbstractOneOffJobSpringIntegrateTest.java
+++ 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/AbstractOneOffJobSpringIntegrateTest.java
@@ -20,16 +20,19 @@ package 
org.apache.shardingsphere.elasticjob.spring.namespace.job;
 import lombok.RequiredArgsConstructor;
 import 
org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl.OneOffJobBootstrap;
 import 
org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
+import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
 import 
org.apache.shardingsphere.elasticjob.spring.namespace.fixture.job.DataflowElasticJob;
 import 
org.apache.shardingsphere.elasticjob.spring.namespace.fixture.job.FooSimpleElasticJob;
-import 
org.apache.shardingsphere.elasticjob.spring.namespace.test.AbstractZookeeperJUnitJupiterSpringContextTests;
-import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
 import org.awaitility.Awaitility;
 import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 import java.util.concurrent.TimeUnit;
 
@@ -37,8 +40,11 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+@ExtendWith(SpringExtension.class)
 @RequiredArgsConstructor
-public abstract class AbstractOneOffJobSpringIntegrateTest extends 
AbstractZookeeperJUnitJupiterSpringContextTests {
+public abstract class AbstractOneOffJobSpringIntegrateTest {
+    
+    private static final EmbedTestingServer EMBED_TESTING_SERVER = new 
EmbedTestingServer(3181);
     
     private final String simpleJobName;
     
@@ -50,6 +56,11 @@ public abstract class AbstractOneOffJobSpringIntegrateTest 
extends AbstractZooke
     @Autowired
     private CoordinatorRegistryCenter regCenter;
     
+    @BeforeAll
+    static void init() {
+        EMBED_TESTING_SERVER.start();
+    }
+    
     @BeforeEach
     @AfterEach
     void reset() {
diff --git 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/JobSpringNamespaceWithRefTest.java
 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/JobSpringNamespaceWithRefTest.java
index 3443e123f..e4cf732ee 100644
--- 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/JobSpringNamespaceWithRefTest.java
+++ 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/JobSpringNamespaceWithRefTest.java
@@ -18,15 +18,18 @@
 package org.apache.shardingsphere.elasticjob.spring.namespace.job;
 
 import 
org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
-import 
org.apache.shardingsphere.elasticjob.spring.namespace.fixture.job.ref.RefFooSimpleElasticJob;
-import 
org.apache.shardingsphere.elasticjob.spring.namespace.test.AbstractZookeeperJUnitJupiterSpringContextTests;
 import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import 
org.apache.shardingsphere.elasticjob.spring.namespace.fixture.job.ref.RefFooSimpleElasticJob;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
 import org.awaitility.Awaitility;
 import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 import java.util.concurrent.TimeUnit;
 
@@ -34,14 +37,22 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+@ExtendWith(SpringExtension.class)
 @ContextConfiguration(locations = "classpath:META-INF/job/withJobRef.xml")
-class JobSpringNamespaceWithRefTest extends 
AbstractZookeeperJUnitJupiterSpringContextTests {
+class JobSpringNamespaceWithRefTest {
+    
+    private static final EmbedTestingServer EMBED_TESTING_SERVER = new 
EmbedTestingServer(3181);
     
     private final String simpleJobName = "simpleElasticJob_job_ref";
     
     @Autowired
     private CoordinatorRegistryCenter regCenter;
     
+    @BeforeAll
+    static void init() {
+        EMBED_TESTING_SERVER.start();
+    }
+    
     @BeforeEach
     @AfterEach
     void reset() {
diff --git 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/JobSpringNamespaceWithTypeTest.java
 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/JobSpringNamespaceWithTypeTest.java
index e33cd687c..7dbc90238 100644
--- 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/JobSpringNamespaceWithTypeTest.java
+++ 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/JobSpringNamespaceWithTypeTest.java
@@ -18,15 +18,18 @@
 package org.apache.shardingsphere.elasticjob.spring.namespace.job;
 
 import 
org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
-import 
org.apache.shardingsphere.elasticjob.spring.namespace.test.AbstractZookeeperJUnitJupiterSpringContextTests;
 import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
 import org.awaitility.Awaitility;
 import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.quartz.Scheduler;
 import org.quartz.SchedulerException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 import org.springframework.test.util.ReflectionTestUtils;
 
 import java.util.concurrent.TimeUnit;
@@ -35,8 +38,11 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+@ExtendWith(SpringExtension.class)
 @ContextConfiguration(locations = "classpath:META-INF/job/withJobType.xml")
-class JobSpringNamespaceWithTypeTest extends 
AbstractZookeeperJUnitJupiterSpringContextTests {
+class JobSpringNamespaceWithTypeTest {
+    
+    private static final EmbedTestingServer EMBED_TESTING_SERVER = new 
EmbedTestingServer(3181);
     
     private final String scriptJobName = "scriptElasticJob_job_type";
     
@@ -45,6 +51,11 @@ class JobSpringNamespaceWithTypeTest extends 
AbstractZookeeperJUnitJupiterSpring
     
     private Scheduler scheduler;
     
+    @BeforeAll
+    static void init() {
+        EMBED_TESTING_SERVER.start();
+    }
+    
     @AfterEach
     void tearDown() {
         Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() -> 
assertThat(scheduler.getCurrentlyExecutingJobs().isEmpty(), is(true)));
diff --git 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/OneOffJobSpringNamespaceWithRefTest.java
 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/OneOffJobSpringNamespaceWithRefTest.java
index c2e5c17d3..9d6003fd3 100644
--- 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/OneOffJobSpringNamespaceWithRefTest.java
+++ 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/OneOffJobSpringNamespaceWithRefTest.java
@@ -19,16 +19,19 @@ package 
org.apache.shardingsphere.elasticjob.spring.namespace.job;
 
 import 
org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl.OneOffJobBootstrap;
 import 
org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
-import 
org.apache.shardingsphere.elasticjob.spring.namespace.fixture.job.ref.RefFooSimpleElasticJob;
-import 
org.apache.shardingsphere.elasticjob.spring.namespace.test.AbstractZookeeperJUnitJupiterSpringContextTests;
 import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import 
org.apache.shardingsphere.elasticjob.spring.namespace.fixture.job.ref.RefFooSimpleElasticJob;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
 import org.awaitility.Awaitility;
 import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationContext;
 import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 import java.util.concurrent.TimeUnit;
 
@@ -36,8 +39,11 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+@ExtendWith(SpringExtension.class)
 @ContextConfiguration(locations = 
"classpath:META-INF/job/oneOffWithJobRef.xml")
-class OneOffJobSpringNamespaceWithRefTest extends 
AbstractZookeeperJUnitJupiterSpringContextTests {
+class OneOffJobSpringNamespaceWithRefTest {
+    
+    private static final EmbedTestingServer EMBED_TESTING_SERVER = new 
EmbedTestingServer(3181);
     
     private final String oneOffSimpleJobName = "oneOffSimpleElasticJobRef";
     
@@ -47,6 +53,11 @@ class OneOffJobSpringNamespaceWithRefTest extends 
AbstractZookeeperJUnitJupiterS
     @Autowired
     private CoordinatorRegistryCenter regCenter;
     
+    @BeforeAll
+    static void init() {
+        EMBED_TESTING_SERVER.start();
+    }
+    
     @BeforeEach
     @AfterEach
     void reset() {
diff --git 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/OneOffJobSpringNamespaceWithTypeTest.java
 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/OneOffJobSpringNamespaceWithTypeTest.java
index 784cbada7..6bffa1ae0 100644
--- 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/OneOffJobSpringNamespaceWithTypeTest.java
+++ 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/job/OneOffJobSpringNamespaceWithTypeTest.java
@@ -19,21 +19,27 @@ package 
org.apache.shardingsphere.elasticjob.spring.namespace.job;
 
 import 
org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl.OneOffJobBootstrap;
 import 
org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
-import 
org.apache.shardingsphere.elasticjob.spring.namespace.test.AbstractZookeeperJUnitJupiterSpringContextTests;
 import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
 import org.awaitility.Awaitility;
 import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationContext;
 import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 import java.util.concurrent.TimeUnit;
 
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+@ExtendWith(SpringExtension.class)
 @ContextConfiguration(locations = 
"classpath:META-INF/job/oneOffWithJobType.xml")
-class OneOffJobSpringNamespaceWithTypeTest extends 
AbstractZookeeperJUnitJupiterSpringContextTests {
+class OneOffJobSpringNamespaceWithTypeTest {
+    
+    private static final EmbedTestingServer EMBED_TESTING_SERVER = new 
EmbedTestingServer(3181);
     
     private final String scriptJobName = "oneOffScriptElasticJob_job_type";
     
@@ -43,6 +49,11 @@ class OneOffJobSpringNamespaceWithTypeTest extends 
AbstractZookeeperJUnitJupiter
     @Autowired
     private CoordinatorRegistryCenter regCenter;
     
+    @BeforeAll
+    static void init() {
+        EMBED_TESTING_SERVER.start();
+    }
+    
     @AfterEach
     void tearDown() {
         JobRegistry.getInstance().shutdown(scriptJobName);
diff --git 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/scanner/AbstractJobSpringIntegrateTest.java
 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/scanner/AbstractJobSpringIntegrateTest.java
index a28f60b4c..8a84cb0fd 100644
--- 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/scanner/AbstractJobSpringIntegrateTest.java
+++ 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/scanner/AbstractJobSpringIntegrateTest.java
@@ -19,14 +19,17 @@ package 
org.apache.shardingsphere.elasticjob.spring.namespace.scanner;
 
 import lombok.RequiredArgsConstructor;
 import 
org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
-import 
org.apache.shardingsphere.elasticjob.spring.namespace.fixture.job.annotation.AnnotationSimpleJob;
-import 
org.apache.shardingsphere.elasticjob.spring.namespace.test.AbstractZookeeperJUnitJupiterSpringContextTests;
 import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import 
org.apache.shardingsphere.elasticjob.spring.namespace.fixture.job.annotation.AnnotationSimpleJob;
+import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
 import org.awaitility.Awaitility;
 import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 import java.util.concurrent.TimeUnit;
 
@@ -34,14 +37,22 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+@ExtendWith(SpringExtension.class)
 @RequiredArgsConstructor
-public abstract class AbstractJobSpringIntegrateTest extends 
AbstractZookeeperJUnitJupiterSpringContextTests {
+public abstract class AbstractJobSpringIntegrateTest {
+    
+    private static final EmbedTestingServer EMBED_TESTING_SERVER = new 
EmbedTestingServer(3181);
     
     private final String simpleJobName;
     
     @Autowired
     private CoordinatorRegistryCenter regCenter;
     
+    @BeforeAll
+    static void init() {
+        EMBED_TESTING_SERVER.start();
+    }
+    
     @BeforeEach
     @AfterEach
     void reset() {
diff --git 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/snapshot/SnapshotSpringNamespaceDisableTest.java
 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/snapshot/SnapshotSpringNamespaceDisableTest.java
index 126a79234..96ad3b721 100644
--- 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/snapshot/SnapshotSpringNamespaceDisableTest.java
+++ 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/snapshot/SnapshotSpringNamespaceDisableTest.java
@@ -18,16 +18,27 @@
 package org.apache.shardingsphere.elasticjob.spring.namespace.snapshot;
 
 import 
org.apache.shardingsphere.elasticjob.kernel.internal.snapshot.SnapshotService;
-import 
org.apache.shardingsphere.elasticjob.spring.namespace.test.AbstractZookeeperJUnitJupiterSpringContextTests;
+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;
 import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 import java.io.IOException;
 
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
+@ExtendWith(SpringExtension.class)
 @ContextConfiguration(locations = 
"classpath:META-INF/snapshot/snapshotDisabled.xml")
-class SnapshotSpringNamespaceDisableTest extends 
AbstractZookeeperJUnitJupiterSpringContextTests {
+class SnapshotSpringNamespaceDisableTest {
+    
+    private static final EmbedTestingServer EMBED_TESTING_SERVER = new 
EmbedTestingServer(3181);
+    
+    @BeforeAll
+    static void init() {
+        EMBED_TESTING_SERVER.start();
+    }
     
     @Test
     void assertSnapshotDisable() {
diff --git 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/snapshot/SnapshotSpringNamespaceEnableTest.java
 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/snapshot/SnapshotSpringNamespaceEnableTest.java
index a52e33483..d7d9a33d7 100644
--- 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/snapshot/SnapshotSpringNamespaceEnableTest.java
+++ 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/snapshot/SnapshotSpringNamespaceEnableTest.java
@@ -17,16 +17,27 @@
 
 package org.apache.shardingsphere.elasticjob.spring.namespace.snapshot;
 
-import 
org.apache.shardingsphere.elasticjob.spring.namespace.test.AbstractZookeeperJUnitJupiterSpringContextTests;
+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;
 import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 import java.io.IOException;
 
 import static org.junit.jupiter.api.Assertions.assertNull;
 
+@ExtendWith(SpringExtension.class)
 @ContextConfiguration(locations = 
"classpath:META-INF/snapshot/snapshotEnabled.xml")
-class SnapshotSpringNamespaceEnableTest extends 
AbstractZookeeperJUnitJupiterSpringContextTests {
+class SnapshotSpringNamespaceEnableTest {
+    
+    private static final EmbedTestingServer EMBED_TESTING_SERVER = new 
EmbedTestingServer(3181);
+    
+    @BeforeAll
+    static void init() {
+        EMBED_TESTING_SERVER.start();
+    }
     
     @Test
     void assertSnapshotEnable() throws IOException {
diff --git 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/test/AbstractZookeeperJUnitJupiterSpringContextTests.java
 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/test/AbstractZookeeperJUnitJupiterSpringContextTests.java
deleted file mode 100644
index bde8ca124..000000000
--- 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/test/AbstractZookeeperJUnitJupiterSpringContextTests.java
+++ /dev/null
@@ -1,33 +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.namespace.test;
-
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.springframework.test.context.TestExecutionListeners;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
-
-/**
- * Background reference AbstractJUnit4SpringContextTests
- * and <a 
href="https://github.com/spring-projects/spring-framework/issues/29149";>spring-projects/spring-framework#29149</a>.
- *
- * @see 
org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests
- */
-@ExtendWith(SpringExtension.class)
-@TestExecutionListeners(listeners = EmbedZookeeperTestExecutionListener.class, 
inheritListeners = false, mergeMode = 
TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
-public abstract class AbstractZookeeperJUnitJupiterSpringContextTests {
-}
diff --git 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/test/EmbedZookeeperTestExecutionListener.java
 
b/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/test/EmbedZookeeperTestExecutionListener.java
deleted file mode 100644
index f79ac9100..000000000
--- 
a/spring/namespace/src/test/java/org/apache/shardingsphere/elasticjob/spring/namespace/test/EmbedZookeeperTestExecutionListener.java
+++ /dev/null
@@ -1,142 +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.namespace.test;
-
-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 org.springframework.test.context.TestContext;
-import org.springframework.test.context.support.AbstractTestExecutionListener;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.concurrent.TimeUnit;
-
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-@Slf4j
-public final class EmbedZookeeperTestExecutionListener extends 
AbstractTestExecutionListener {
-    
-    private static final int PORT = 3181;
-    
-    private static volatile TestingServer testingServer;
-    
-    private static final Object INIT_LOCK = new Object();
-    
-    @Override
-    public void beforeTestClass(final TestContext testContext) {
-        startEmbedTestingServer();
-    }
-    
-    /**
-     * Start embed zookeeper server.
-     */
-    private static void startEmbedTestingServer() {
-        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;
-    }
-}

Reply via email to