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

duanzhengqiang 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 1a0db64d8 Use Awaitility instead of BlockUtils in unit tests
     new 5e466de55 Merge pull request #2257 from linghengqian/new-awaitility
1a0db64d8 is described below

commit 1a0db64d8d300dc8a04d36cd716b10564bbfe7c9
Author: linghengqian <[email protected]>
AuthorDate: Tue Sep 12 07:06:09 2023 +0800

    Use Awaitility instead of BlockUtils in unit tests
---
 .../elasticjob-http-executor/pom.xml               |  5 ++++
 .../http/executor/fixture/InternalController.java  | 10 ++++++--
 elasticjob-infra/elasticjob-infra-common/pom.xml   |  5 ++++
 .../concurrent/ElasticJobExecutorServiceTest.java  | 28 ++++++++++----------
 elasticjob-lite/elasticjob-lite-core/pom.xml       |  5 ++++
 .../disable/DisabledJobIntegrateTest.java          | 25 ++++++++++--------
 .../disable/OneOffDisabledJobIntegrateTest.java    |  2 --
 .../disable/ScheduleDisabledJobIntegrateTest.java  | 13 ++++++----
 .../enable/OneOffEnabledJobIntegrateTest.java      | 12 ++++++---
 .../enable/ScheduleEnabledJobIntegrateTest.java    | 14 ++++++----
 .../annotation/integrate/OneOffEnabledJobTest.java | 20 ++++++++-------
 .../integrate/ScheduleEnabledJobTest.java          | 20 ++++++++-------
 .../elasticjob-lite-spring-boot-starter/pom.xml    |  5 ++++
 .../boot/job/ElasticJobSpringBootScannerTest.java  | 12 ++++++---
 .../spring/boot/job/ElasticJobSpringBootTest.java  | 16 +++++++-----
 .../boot/job/fixture/EmbedTestingServer.java       | 30 ++++++++++++++++------
 .../elasticjob-lite-spring-namespace/pom.xml       |  5 ++++
 .../job/AbstractJobSpringIntegrateTest.java        | 20 +++++++++------
 .../job/AbstractOneOffJobSpringIntegrateTest.java  | 18 ++++++++-----
 .../job/JobSpringNamespaceWithRefTest.java         | 14 ++++++----
 .../job/JobSpringNamespaceWithTypeTest.java        | 23 ++++++++++-------
 .../job/OneOffJobSpringNamespaceWithRefTest.java   | 14 ++++++----
 .../job/OneOffJobSpringNamespaceWithTypeTest.java  |  9 ++++---
 .../scanner/AbstractJobSpringIntegrateTest.java    | 12 ++++++---
 .../test/EmbedZookeeperTestExecutionListener.java  | 27 +++++++++++++++----
 pom.xml                                            |  7 +++++
 26 files changed, 247 insertions(+), 124 deletions(-)

diff --git 
a/elasticjob-ecosystem/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/pom.xml
 
b/elasticjob-ecosystem/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/pom.xml
index 4c3cd4e58..9b2bec4b2 100644
--- 
a/elasticjob-ecosystem/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/pom.xml
+++ 
b/elasticjob-ecosystem/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/pom.xml
@@ -58,5 +58,10 @@
             <optional>true</optional>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git 
a/elasticjob-ecosystem/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/src/test/java/org/apache/shardingsphere/elasticjob/http/executor/fixture/InternalController.java
 
b/elasticjob-ecosystem/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/src/test/java/org/apache/shardingsphere/elasticjob/http/executor/fixture/InternalController.java
index 6a289e876..63d209eef 100644
--- 
a/elasticjob-ecosystem/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/src/test/java/org/apache/shardingsphere/elasticjob/http/executor/fixture/InternalController.java
+++ 
b/elasticjob-ecosystem/elasticjob-executor/elasticjob-executor-type/elasticjob-http-executor/src/test/java/org/apache/shardingsphere/elasticjob/http/executor/fixture/InternalController.java
@@ -18,14 +18,18 @@
 package org.apache.shardingsphere.elasticjob.http.executor.fixture;
 
 import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
 import org.apache.shardingsphere.elasticjob.restful.Http;
 import org.apache.shardingsphere.elasticjob.restful.RestfulController;
 import org.apache.shardingsphere.elasticjob.restful.annotation.Mapping;
 import org.apache.shardingsphere.elasticjob.restful.annotation.Param;
 import org.apache.shardingsphere.elasticjob.restful.annotation.ParamSource;
+import org.awaitility.Awaitility;
 
 import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 
 @Slf4j
 public final class InternalController implements RestfulController {
@@ -71,7 +75,9 @@ public final class InternalController implements 
RestfulController {
      */
     @Mapping(method = Http.POST, path = "/postWithTimeout")
     public String postWithTimeout() {
-        BlockUtils.waitingShortTime();
+        Awaitility.await().atLeast(100L, TimeUnit.MILLISECONDS).atMost(1L, 
TimeUnit.SECONDS).untilAsserted(() ->
+                assertThat(Boolean.TRUE, is(Boolean.TRUE))
+        );
         return "ejob";
     }
 }
diff --git a/elasticjob-infra/elasticjob-infra-common/pom.xml 
b/elasticjob-infra/elasticjob-infra-common/pom.xml
index 6f7e0f54b..005d783eb 100644
--- a/elasticjob-infra/elasticjob-infra-common/pom.xml
+++ b/elasticjob-infra/elasticjob-infra-common/pom.xml
@@ -87,5 +87,10 @@
             <artifactId>logback-classic</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git 
a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/concurrent/ElasticJobExecutorServiceTest.java
 
b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/concurrent/ElasticJobExecutorServiceTest.java
index e92c078fa..b3a4e9431 100644
--- 
a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/concurrent/ElasticJobExecutorServiceTest.java
+++ 
b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/concurrent/ElasticJobExecutorServiceTest.java
@@ -17,9 +17,11 @@
 
 package org.apache.shardingsphere.elasticjob.infra.concurrent;
 
+import org.awaitility.Awaitility;
 import org.junit.Test;
 
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertFalse;
@@ -38,15 +40,17 @@ public final class ElasticJobExecutorServiceTest {
         assertFalse(executorServiceObject.isShutdown());
         ExecutorService executorService = 
executorServiceObject.createExecutorService();
         executorService.submit(new FooTask());
-        BlockUtils.waitingShortTime();
-        assertThat(executorServiceObject.getActiveThreadCount(), is(1));
-        assertThat(executorServiceObject.getWorkQueueSize(), is(0));
-        assertFalse(executorServiceObject.isShutdown());
+        Awaitility.await().atLeast(100L, TimeUnit.MILLISECONDS).atMost(5L, 
TimeUnit.MINUTES).untilAsserted(() -> {
+            assertThat(executorServiceObject.getActiveThreadCount(), is(1));
+            assertThat(executorServiceObject.getWorkQueueSize(), is(0));
+            assertFalse(executorServiceObject.isShutdown());
+        });
         executorService.submit(new FooTask());
-        BlockUtils.waitingShortTime();
-        assertThat(executorServiceObject.getActiveThreadCount(), is(1));
-        assertThat(executorServiceObject.getWorkQueueSize(), is(1));
-        assertFalse(executorServiceObject.isShutdown());
+        Awaitility.await().atLeast(100L, TimeUnit.MILLISECONDS).atMost(5L, 
TimeUnit.MINUTES).untilAsserted(() -> {
+            assertThat(executorServiceObject.getActiveThreadCount(), is(1));
+            assertThat(executorServiceObject.getWorkQueueSize(), is(1));
+            assertFalse(executorServiceObject.isShutdown());
+        });
         executorService.shutdownNow();
         assertThat(executorServiceObject.getWorkQueueSize(), is(0));
         assertTrue(executorServiceObject.isShutdown());
@@ -54,13 +58,11 @@ public final class ElasticJobExecutorServiceTest {
     }
     
     static class FooTask implements Runnable {
-        
+
         @Override
         public void run() {
-            BlockUtils.sleep(1000L);
-            while (!hasExecuted) {
-                Thread.yield();
-            }
+            Awaitility.await().atMost(1L, TimeUnit.MINUTES)
+                    .untilAsserted(() -> assertThat(hasExecuted, is(true)));
         }
     }
 }
diff --git a/elasticjob-lite/elasticjob-lite-core/pom.xml 
b/elasticjob-lite/elasticjob-lite-core/pom.xml
index 32ff0c09a..a4898adb5 100644
--- a/elasticjob-lite/elasticjob-lite-core/pom.xml
+++ b/elasticjob-lite/elasticjob-lite-core/pom.xml
@@ -125,5 +125,10 @@
             <artifactId>logback-classic</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git 
a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/disable/DisabledJobIntegrateTest.java
 
b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/disable/DisabledJobIntegrateTest.java
index 7124db006..bca4a25ac 100644
--- 
a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/disable/DisabledJobIntegrateTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/disable/DisabledJobIntegrateTest.java
@@ -17,16 +17,19 @@
 
 package org.apache.shardingsphere.elasticjob.lite.integrate.disable;
 
-import 
org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
 import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
+import org.apache.shardingsphere.elasticjob.infra.env.IpUtils;
+import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
+import org.apache.shardingsphere.elasticjob.infra.yaml.YamlEngine;
+import 
org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
 import org.apache.shardingsphere.elasticjob.lite.fixture.job.DetailedFooJob;
 import org.apache.shardingsphere.elasticjob.lite.integrate.BaseIntegrateTest;
-import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
 import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
 import org.apache.shardingsphere.elasticjob.lite.internal.server.ServerStatus;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
-import org.apache.shardingsphere.elasticjob.infra.env.IpUtils;
-import org.apache.shardingsphere.elasticjob.infra.yaml.YamlEngine;
+import org.awaitility.Awaitility;
+import org.hamcrest.core.IsNull;
+
+import java.util.concurrent.TimeUnit;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertNull;
@@ -39,8 +42,10 @@ public abstract class DisabledJobIntegrateTest extends 
BaseIntegrateTest {
     }
     
     protected final void assertDisabledRegCenterInfo() {
-        
assertThat(JobRegistry.getInstance().getCurrentShardingTotalCount(getJobName()),
 is(3));
-        
assertThat(JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp(),
 is(IpUtils.getIp()));
+        Awaitility.await().atLeast(100L, TimeUnit.MILLISECONDS).atMost(1L, 
TimeUnit.MINUTES).untilAsserted(() -> {
+            
assertThat(JobRegistry.getInstance().getCurrentShardingTotalCount(getJobName()),
 is(3));
+            
assertThat(JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp(),
 is(IpUtils.getIp()));
+        });
         JobConfiguration jobConfig = 
YamlEngine.unmarshal(getREGISTRY_CENTER().get("/" + getJobName() + "/config"), 
JobConfigurationPOJO.class).toJobConfiguration();
         assertThat(jobConfig.getShardingTotalCount(), is(3));
         if (getJobBootstrap() instanceof ScheduleJobBootstrap) {
@@ -50,8 +55,8 @@ public abstract class DisabledJobIntegrateTest extends 
BaseIntegrateTest {
         }
         assertThat(jobConfig.getShardingItemParameters(), is("0=A,1=B,2=C"));
         assertThat(getREGISTRY_CENTER().get("/" + getJobName() + "/servers/" + 
JobRegistry.getInstance().getJobInstance(getJobName()).getServerIp()), 
is(ServerStatus.DISABLED.name()));
-        while (null != getREGISTRY_CENTER().get("/" + getJobName() + 
"/leader/election/instance")) {
-            BlockUtils.waitingShortTime();
-        }
+        Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() ->
+                assertThat(getREGISTRY_CENTER().get("/" + getJobName() + 
"/leader/election/instance"), is(IsNull.nullValue()))
+        );
     }
 }
diff --git 
a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/disable/OneOffDisabledJobIntegrateTest.java
 
b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/disable/OneOffDisabledJobIntegrateTest.java
index 77665b1b0..c9a04f18c 100644
--- 
a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/disable/OneOffDisabledJobIntegrateTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/disable/OneOffDisabledJobIntegrateTest.java
@@ -18,7 +18,6 @@
 package org.apache.shardingsphere.elasticjob.lite.integrate.disable;
 
 import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
 import org.junit.Test;
 
 public final class OneOffDisabledJobIntegrateTest extends 
DisabledJobIntegrateTest {
@@ -35,7 +34,6 @@ public final class OneOffDisabledJobIntegrateTest extends 
DisabledJobIntegrateTe
     
     @Test
     public void assertJobRunning() {
-        BlockUtils.waitingShortTime();
         assertDisabledRegCenterInfo();
     }
 }
diff --git 
a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/disable/ScheduleDisabledJobIntegrateTest.java
 
b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/disable/ScheduleDisabledJobIntegrateTest.java
index bebc27894..53c90c65e 100644
--- 
a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/disable/ScheduleDisabledJobIntegrateTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/disable/ScheduleDisabledJobIntegrateTest.java
@@ -21,9 +21,13 @@ import 
org.apache.shardingsphere.elasticjob.api.JobConfiguration;
 import org.apache.shardingsphere.elasticjob.lite.fixture.job.DetailedFooJob;
 import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
 import org.apache.shardingsphere.elasticjob.lite.internal.server.ServerStatus;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
+import org.awaitility.Awaitility;
 import org.junit.Test;
 
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 public final class ScheduleDisabledJobIntegrateTest extends 
DisabledJobIntegrateTest {
@@ -40,12 +44,11 @@ public final class ScheduleDisabledJobIntegrateTest extends 
DisabledJobIntegrate
     
     @Test
     public void assertJobRunning() {
-        BlockUtils.waitingShortTime();
         assertDisabledRegCenterInfo();
         setJobEnable();
-        while (!((DetailedFooJob) getElasticJob()).isCompleted()) {
-            BlockUtils.waitingShortTime();
-        }
+        Awaitility.await().atMost(10L, TimeUnit.SECONDS).untilAsserted(() ->
+                assertThat(((DetailedFooJob) getElasticJob()).isCompleted(), 
is(true))
+        );
         assertEnabledRegCenterInfo();
     }
     
diff --git 
a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/enable/OneOffEnabledJobIntegrateTest.java
 
b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/enable/OneOffEnabledJobIntegrateTest.java
index 2bcfedc31..eea60ebd7 100644
--- 
a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/enable/OneOffEnabledJobIntegrateTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/enable/OneOffEnabledJobIntegrateTest.java
@@ -19,9 +19,13 @@ package 
org.apache.shardingsphere.elasticjob.lite.integrate.enable;
 
 import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
 import org.apache.shardingsphere.elasticjob.lite.fixture.job.DetailedFooJob;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
+import org.awaitility.Awaitility;
 import org.junit.Test;
 
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 public final class OneOffEnabledJobIntegrateTest extends 
EnabledJobIntegrateTest {
@@ -38,9 +42,9 @@ public final class OneOffEnabledJobIntegrateTest extends 
EnabledJobIntegrateTest
     
     @Test
     public void assertJobInit() {
-        while (!((DetailedFooJob) getElasticJob()).isCompleted()) {
-            BlockUtils.waitingShortTime();
-        }
+        Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() ->
+                assertThat(((DetailedFooJob) getElasticJob()).isCompleted(), 
is(true))
+        );
         assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + 
"/sharding"));
     }
 }
diff --git 
a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/enable/ScheduleEnabledJobIntegrateTest.java
 
b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/enable/ScheduleEnabledJobIntegrateTest.java
index 5ce9bf7c7..de4a7ec69 100644
--- 
a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/enable/ScheduleEnabledJobIntegrateTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/integrate/enable/ScheduleEnabledJobIntegrateTest.java
@@ -19,9 +19,13 @@ package 
org.apache.shardingsphere.elasticjob.lite.integrate.enable;
 
 import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
 import org.apache.shardingsphere.elasticjob.lite.fixture.job.DetailedFooJob;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
+import org.awaitility.Awaitility;
 import org.junit.Test;
 
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 public final class ScheduleEnabledJobIntegrateTest extends 
EnabledJobIntegrateTest {
@@ -35,12 +39,12 @@ public final class ScheduleEnabledJobIntegrateTest extends 
EnabledJobIntegrateTe
         return JobConfiguration.newBuilder(jobName, 3).cron("0/1 * * * * 
?").shardingItemParameters("0=A,1=B,2=C")
                 .jobListenerTypes("INTEGRATE-TEST", 
"INTEGRATE-DISTRIBUTE").overwrite(true).build();
     }
-    
+
     @Test
     public void assertJobInit() {
-        while (!((DetailedFooJob) getElasticJob()).isCompleted()) {
-            BlockUtils.waitingShortTime();
-        }
+        Awaitility.await().atMost(10L, TimeUnit.SECONDS).untilAsserted(() ->
+                assertThat(((DetailedFooJob) getElasticJob()).isCompleted(), 
is(true))
+        );
         assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + 
"/sharding"));
     }
 }
diff --git 
a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/OneOffEnabledJobTest.java
 
b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/OneOffEnabledJobTest.java
index 33bf40ef8..9be96c5cb 100644
--- 
a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/OneOffEnabledJobTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/OneOffEnabledJobTest.java
@@ -17,22 +17,24 @@
 
 package 
org.apache.shardingsphere.elasticjob.lite.internal.annotation.integrate;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
 import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
 import org.apache.shardingsphere.elasticjob.infra.env.IpUtils;
 import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
 import org.apache.shardingsphere.elasticjob.infra.yaml.YamlEngine;
 import 
org.apache.shardingsphere.elasticjob.lite.fixture.job.AnnotationUnShardingJob;
 import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
 import org.apache.shardingsphere.elasticjob.lite.internal.server.ServerStatus;
+import org.awaitility.Awaitility;
 import org.junit.Before;
 import org.junit.Test;
 
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
 public final class OneOffEnabledJobTest extends BaseAnnotationTest {
     
     public OneOffEnabledJobTest() {
@@ -55,9 +57,9 @@ public final class OneOffEnabledJobTest extends 
BaseAnnotationTest {
     
     @Test
     public void assertJobInit() {
-        while (!((AnnotationUnShardingJob) getElasticJob()).isCompleted()) {
-            BlockUtils.waitingShortTime();
-        }
+        Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() ->
+                assertThat(((AnnotationUnShardingJob) 
getElasticJob()).isCompleted(), is(true))
+        );
         assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + 
"/sharding"));
     }
     
diff --git 
a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/ScheduleEnabledJobTest.java
 
b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/ScheduleEnabledJobTest.java
index d250341e3..3acfe2604 100644
--- 
a/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/ScheduleEnabledJobTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-core/src/test/java/org/apache/shardingsphere/elasticjob/lite/internal/annotation/integrate/ScheduleEnabledJobTest.java
@@ -17,22 +17,24 @@
 
 package 
org.apache.shardingsphere.elasticjob.lite.internal.annotation.integrate;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
 import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
 import org.apache.shardingsphere.elasticjob.infra.env.IpUtils;
 import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
 import org.apache.shardingsphere.elasticjob.infra.yaml.YamlEngine;
 import 
org.apache.shardingsphere.elasticjob.lite.fixture.job.AnnotationSimpleJob;
 import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
 import org.apache.shardingsphere.elasticjob.lite.internal.server.ServerStatus;
+import org.awaitility.Awaitility;
 import org.junit.Before;
 import org.junit.Test;
 
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
 public final class ScheduleEnabledJobTest extends BaseAnnotationTest {
     
     public ScheduleEnabledJobTest() {
@@ -57,9 +59,9 @@ public final class ScheduleEnabledJobTest extends 
BaseAnnotationTest {
     
     @Test
     public void assertJobInit() {
-        while (!((AnnotationSimpleJob) getElasticJob()).isCompleted()) {
-            BlockUtils.waitingShortTime();
-        }
+        Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() ->
+                assertThat(((AnnotationSimpleJob) 
getElasticJob()).isCompleted(), is(true))
+        );
         assertTrue(getREGISTRY_CENTER().isExisted("/" + getJobName() + 
"/sharding"));
     }
     
diff --git 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/pom.xml
 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/pom.xml
index f73b90006..b67214222 100644
--- 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/pom.xml
+++ 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/pom.xml
@@ -87,5 +87,10 @@
             <artifactId>h2</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootScannerTest.java
 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootScannerTest.java
index 25b948701..6d9db0bcb 100644
--- 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootScannerTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootScannerTest.java
@@ -17,18 +17,22 @@
 
 package org.apache.shardingsphere.elasticjob.lite.spring.boot.job;
 
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
 import 
org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.boot.job.fixture.EmbedTestingServer;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.boot.job.fixture.job.impl.AnnotationCustomJob;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.core.scanner.ElasticJobScan;
+import org.awaitility.Awaitility;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.ActiveProfiles;
 import 
org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
 
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 @SpringBootTest
@@ -44,9 +48,9 @@ public class ElasticJobSpringBootScannerTest extends 
AbstractJUnit4SpringContext
     
     @Test
     public void assertDefaultBeanNameWithTypeJob() {
-        while (!AnnotationCustomJob.isCompleted()) {
-            BlockUtils.waitingShortTime();
-        }
+        Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() ->
+                assertThat(AnnotationCustomJob.isCompleted(), is(true))
+        );
         assertTrue(AnnotationCustomJob.isCompleted());
         assertNotNull(applicationContext);
         
assertNotNull(applicationContext.getBean("annotationCustomJobSchedule", 
ScheduleJobBootstrap.class));
diff --git 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootTest.java
 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootTest.java
index 6ded07040..94e60f1d9 100644
--- 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/ElasticJobSpringBootTest.java
@@ -19,7 +19,6 @@ package 
org.apache.shardingsphere.elasticjob.lite.spring.boot.job;
 
 import org.apache.shardingsphere.elasticjob.api.ElasticJob;
 import org.apache.shardingsphere.elasticjob.api.JobExtraConfiguration;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
 import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.JobBootstrap;
 import 
org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.OneOffJobBootstrap;
 import 
org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
@@ -30,6 +29,7 @@ import 
org.apache.shardingsphere.elasticjob.lite.spring.boot.reg.ZookeeperProper
 import 
org.apache.shardingsphere.elasticjob.lite.spring.boot.tracing.TracingProperties;
 import 
org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
 import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
+import org.awaitility.Awaitility;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -45,6 +45,7 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.TimeUnit;
 
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.is;
@@ -131,12 +132,13 @@ public class ElasticJobSpringBootTest extends 
AbstractJUnit4SpringContextTests {
     
     @Test
     public void assertJobScheduleCreation() {
-        assertNotNull(applicationContext);
-        Map<String, ElasticJob> elasticJobBeans = 
applicationContext.getBeansOfType(ElasticJob.class);
-        assertFalse(elasticJobBeans.isEmpty());
-        Map<String, JobBootstrap> jobBootstrapBeans = 
applicationContext.getBeansOfType(JobBootstrap.class);
-        assertFalse(jobBootstrapBeans.isEmpty());
-        BlockUtils.waitingShortTime();
+        Awaitility.await().atLeast(100L, TimeUnit.MILLISECONDS).atMost(1L, 
TimeUnit.MINUTES).untilAsserted(() -> {
+            assertNotNull(applicationContext);
+            Map<String, ElasticJob> elasticJobBeans = 
applicationContext.getBeansOfType(ElasticJob.class);
+            assertFalse(elasticJobBeans.isEmpty());
+            Map<String, JobBootstrap> jobBootstrapBeans = 
applicationContext.getBeansOfType(JobBootstrap.class);
+            assertFalse(jobBootstrapBeans.isEmpty());
+        });
     }
     
     @Test
diff --git 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/fixture/EmbedTestingServer.java
 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/fixture/EmbedTestingServer.java
index aa97974ea..40f6c48b7 100644
--- 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/fixture/EmbedTestingServer.java
+++ 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/boot/job/fixture/EmbedTestingServer.java
@@ -19,12 +19,17 @@ package 
org.apache.shardingsphere.elasticjob.lite.spring.boot.job.fixture;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import org.apache.curator.CuratorZookeeperClient;
+import org.apache.curator.retry.ExponentialBackoffRetry;
 import org.apache.curator.test.TestingServer;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
 import org.apache.shardingsphere.elasticjob.reg.exception.RegExceptionHandler;
+import org.awaitility.Awaitility;
+import org.hamcrest.Matchers;
 
-import java.io.File;
 import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertThat;
 
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class EmbedTestingServer {
@@ -46,14 +51,11 @@ public final class EmbedTestingServer {
      * Start the server.
      */
     public static void start() {
-        // sleep some time to avoid testServer intended stop.
-        long sleepTime = 1000L;
-        BlockUtils.sleep(sleepTime);
         if (null != testingServer) {
             return;
         }
         try {
-            testingServer = new TestingServer(PORT, new 
File(String.format("target/test_zk_data/%s/", System.nanoTime())));
+            testingServer = new TestingServer(PORT, true);
             // CHECKSTYLE:OFF
         } catch (final Exception ex) {
             // CHECKSTYLE:ON
@@ -61,12 +63,24 @@ public final class EmbedTestingServer {
         } finally {
             Runtime.getRuntime().addShutdownHook(new Thread(() -> {
                 try {
-                    Thread.sleep(sleepTime);
                     testingServer.close();
-                } catch (final IOException | InterruptedException ex) {
+                } catch (final IOException ex) {
                     RegExceptionHandler.handleException(ex);
                 }
             }));
         }
+        try (CuratorZookeeperClient client = new 
CuratorZookeeperClient(getConnectionString(),
+                60 * 1000, 500, null,
+                new ExponentialBackoffRetry(500, 3, 500 * 3))) {
+            client.start();
+            Awaitility.await()
+                    .atLeast(100L, TimeUnit.MILLISECONDS)
+                    .atMost(500 * 60L, TimeUnit.MILLISECONDS)
+                    .untilAsserted(() -> assertThat(client.isConnected(), 
Matchers.is(true)));
+            // CHECKSTYLE:OFF
+        } catch (Exception e) {
+            // CHECKSTYLE:ON
+            throw new RuntimeException(e);
+        }
     }
 }
diff --git 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/pom.xml
 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/pom.xml
index de79e7f6e..9d8ae8add 100644
--- 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/pom.xml
+++ 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/pom.xml
@@ -114,5 +114,10 @@
             <artifactId>commons-dbcp2</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/AbstractJobSpringIntegrateTest.java
 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/AbstractJobSpringIntegrateTest.java
index 9d70f3e5c..b9227793e 100644
--- 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/AbstractJobSpringIntegrateTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/AbstractJobSpringIntegrateTest.java
@@ -19,16 +19,20 @@ package 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.job;
 
 import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
-import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.fixture.job.DataflowElasticJob;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.fixture.job.FooSimpleElasticJob;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.test.AbstractZookeeperJUnit4SpringContextTests;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
+import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import org.awaitility.Awaitility;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 @RequiredArgsConstructor
@@ -61,17 +65,17 @@ public abstract class AbstractJobSpringIntegrateTest 
extends AbstractZookeeperJU
     }
     
     private void assertSimpleElasticJobBean() {
-        while (!FooSimpleElasticJob.isCompleted()) {
-            BlockUtils.waitingShortTime();
-        }
+        Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() ->
+                assertThat(FooSimpleElasticJob.isCompleted(), is(true))
+        );
         assertTrue(FooSimpleElasticJob.isCompleted());
         assertTrue(regCenter.isExisted("/" + simpleJobName + "/sharding"));
     }
     
     private void assertThroughputDataflowElasticJobBean() {
-        while (!DataflowElasticJob.isCompleted()) {
-            BlockUtils.waitingShortTime();
-        }
+        Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() ->
+                assertThat(DataflowElasticJob.isCompleted(), is(true))
+        );
         assertTrue(DataflowElasticJob.isCompleted());
         assertTrue(regCenter.isExisted("/" + throughputDataflowJobName + 
"/sharding"));
     }
diff --git 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/AbstractOneOffJobSpringIntegrateTest.java
 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/AbstractOneOffJobSpringIntegrateTest.java
index f68dea1ff..45142a5d3 100644
--- 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/AbstractOneOffJobSpringIntegrateTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/AbstractOneOffJobSpringIntegrateTest.java
@@ -18,18 +18,22 @@
 package org.apache.shardingsphere.elasticjob.lite.spring.namespace.job;
 
 import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
 import 
org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.OneOffJobBootstrap;
 import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.fixture.job.DataflowElasticJob;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.fixture.job.FooSimpleElasticJob;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.test.AbstractZookeeperJUnit4SpringContextTests;
 import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import org.awaitility.Awaitility;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 @RequiredArgsConstructor
@@ -64,9 +68,9 @@ public abstract class AbstractOneOffJobSpringIntegrateTest 
extends AbstractZooke
     private void assertSimpleElasticJobBean() {
         OneOffJobBootstrap bootstrap = 
applicationContext.getBean(simpleJobName, OneOffJobBootstrap.class);
         bootstrap.execute();
-        while (!FooSimpleElasticJob.isCompleted()) {
-            BlockUtils.waitingShortTime();
-        }
+        Awaitility.await().atMost(10L, TimeUnit.MINUTES).untilAsserted(() ->
+                assertThat(FooSimpleElasticJob.isCompleted(), is(true))
+        );
         assertTrue(FooSimpleElasticJob.isCompleted());
         assertTrue(regCenter.isExisted("/" + simpleJobName + "/sharding"));
     }
@@ -74,9 +78,9 @@ public abstract class AbstractOneOffJobSpringIntegrateTest 
extends AbstractZooke
     private void assertThroughputDataflowElasticJobBean() {
         OneOffJobBootstrap bootstrap = 
applicationContext.getBean(throughputDataflowJobName, OneOffJobBootstrap.class);
         bootstrap.execute();
-        while (!DataflowElasticJob.isCompleted()) {
-            BlockUtils.waitingShortTime();
-        }
+        Awaitility.await().atMost(10L, TimeUnit.MINUTES).untilAsserted(() ->
+                assertThat(DataflowElasticJob.isCompleted(), is(true))
+        );
         assertTrue(DataflowElasticJob.isCompleted());
         assertTrue(regCenter.isExisted("/" + throughputDataflowJobName + 
"/sharding"));
     }
diff --git 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/JobSpringNamespaceWithRefTest.java
 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/JobSpringNamespaceWithRefTest.java
index 834b9771b..109647dd1 100644
--- 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/JobSpringNamespaceWithRefTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/JobSpringNamespaceWithRefTest.java
@@ -18,16 +18,20 @@
 package org.apache.shardingsphere.elasticjob.lite.spring.namespace.job;
 
 import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
-import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.fixture.job.ref.RefFooSimpleElasticJob;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.test.AbstractZookeeperJUnit4SpringContextTests;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
+import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import org.awaitility.Awaitility;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
 
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 @ContextConfiguration(locations = "classpath:META-INF/job/withJobRef.xml")
@@ -55,9 +59,9 @@ public final class JobSpringNamespaceWithRefTest extends 
AbstractZookeeperJUnit4
     }
 
     private void assertSimpleElasticJobBean() {
-        while (!RefFooSimpleElasticJob.isCompleted()) {
-            BlockUtils.waitingShortTime();
-        }
+        Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() ->
+                assertThat(RefFooSimpleElasticJob.isCompleted(), is(true))
+        );
         assertTrue(RefFooSimpleElasticJob.isCompleted());
         assertTrue(regCenter.isExisted("/" + simpleJobName + "/sharding"));
     }
diff --git 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/JobSpringNamespaceWithTypeTest.java
 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/JobSpringNamespaceWithTypeTest.java
index 7b9ad4bc8..7f556446a 100644
--- 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/JobSpringNamespaceWithTypeTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/JobSpringNamespaceWithTypeTest.java
@@ -17,11 +17,10 @@
 
 package org.apache.shardingsphere.elasticjob.lite.spring.namespace.job;
 
-import static org.junit.Assert.assertTrue;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
 import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.test.AbstractZookeeperJUnit4SpringContextTests;
 import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import org.awaitility.Awaitility;
 import org.junit.After;
 import org.junit.Test;
 import org.quartz.Scheduler;
@@ -30,6 +29,12 @@ import 
org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.util.ReflectionTestUtils;
 
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
 @ContextConfiguration(locations = "classpath:META-INF/job/withJobType.xml")
 public final class JobSpringNamespaceWithTypeTest extends 
AbstractZookeeperJUnit4SpringContextTests {
     
@@ -41,18 +46,18 @@ public final class JobSpringNamespaceWithTypeTest extends 
AbstractZookeeperJUnit
     private Scheduler scheduler;
 
     @After
-    public void tearDown() throws SchedulerException {
-        while (!scheduler.getCurrentlyExecutingJobs().isEmpty()) {
-            BlockUtils.waitingShortTime();
-        }
+    public void tearDown() {
+        Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() ->
+                assertThat(scheduler.getCurrentlyExecutingJobs().isEmpty(), 
is(true))
+        );
         
JobRegistry.getInstance().getJobScheduleController(scriptJobName).shutdown();
     }
     
     @Test
     public void jobScriptWithJobTypeTest() throws SchedulerException {
-        while (!regCenter.isExisted("/" + scriptJobName + "/sharding")) {
-            BlockUtils.waitingShortTime();
-        }
+        Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() ->
+                assertThat(regCenter.isExisted("/" + scriptJobName + 
"/sharding"), is(true))
+        );
         scheduler = (Scheduler) 
ReflectionTestUtils.getField(JobRegistry.getInstance().getJobScheduleController(scriptJobName),
 "scheduler");
         assertTrue(scheduler.isStarted());
     }
diff --git 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/OneOffJobSpringNamespaceWithRefTest.java
 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/OneOffJobSpringNamespaceWithRefTest.java
index d014f74c6..47976d08f 100644
--- 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/OneOffJobSpringNamespaceWithRefTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/OneOffJobSpringNamespaceWithRefTest.java
@@ -19,16 +19,20 @@ package 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.job;
 
 import 
org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.OneOffJobBootstrap;
 import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
-import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.fixture.job.ref.RefFooSimpleElasticJob;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.test.AbstractZookeeperJUnit4SpringContextTests;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
+import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import org.awaitility.Awaitility;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
 
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 @ContextConfiguration(locations = 
"classpath:META-INF/job/oneOffWithJobRef.xml")
@@ -58,9 +62,9 @@ public final class OneOffJobSpringNamespaceWithRefTest 
extends AbstractZookeeper
     }
 
     private void assertOneOffSimpleElasticJobBean() {
-        while (!RefFooSimpleElasticJob.isCompleted()) {
-            BlockUtils.waitingShortTime();
-        }
+        Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() ->
+                assertThat(RefFooSimpleElasticJob.isCompleted(), is(true))
+        );
         assertTrue(RefFooSimpleElasticJob.isCompleted());
         assertTrue(regCenter.isExisted("/" + oneOffSimpleJobName + 
"/sharding"));
     }
diff --git 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/OneOffJobSpringNamespaceWithTypeTest.java
 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/OneOffJobSpringNamespaceWithTypeTest.java
index fdc03bf69..c6f1f46db 100644
--- 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/OneOffJobSpringNamespaceWithTypeTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/job/OneOffJobSpringNamespaceWithTypeTest.java
@@ -17,16 +17,18 @@
 
 package org.apache.shardingsphere.elasticjob.lite.spring.namespace.job;
 
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
 import 
org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.OneOffJobBootstrap;
 import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.test.AbstractZookeeperJUnit4SpringContextTests;
 import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import org.awaitility.Awaitility;
 import org.junit.After;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
 
+import java.util.concurrent.TimeUnit;
+
 import static org.junit.Assert.assertTrue;
 
 @ContextConfiguration(locations = 
"classpath:META-INF/job/oneOffWithJobType.xml")
@@ -46,7 +48,8 @@ public final class OneOffJobSpringNamespaceWithTypeTest 
extends AbstractZookeepe
     public void jobScriptWithJobTypeTest() {
         OneOffJobBootstrap bootstrap = 
applicationContext.getBean(scriptJobName, OneOffJobBootstrap.class);
         bootstrap.execute();
-        BlockUtils.sleep(1000L);
-        assertTrue(regCenter.isExisted("/" + scriptJobName + "/sharding"));
+        Awaitility.await().atLeast(100L, TimeUnit.MILLISECONDS).atMost(1L, 
TimeUnit.MINUTES).untilAsserted(() ->
+                assertTrue(regCenter.isExisted("/" + scriptJobName + 
"/sharding"))
+        );
     }
 }
diff --git 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/scanner/AbstractJobSpringIntegrateTest.java
 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/scanner/AbstractJobSpringIntegrateTest.java
index 5cc4ffdf2..76f461b52 100644
--- 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/scanner/AbstractJobSpringIntegrateTest.java
+++ 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/scanner/AbstractJobSpringIntegrateTest.java
@@ -18,16 +18,20 @@
 package org.apache.shardingsphere.elasticjob.lite.spring.namespace.scanner;
 
 import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
 import org.apache.shardingsphere.elasticjob.lite.internal.schedule.JobRegistry;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.fixture.job.annotation.AnnotationSimpleJob;
 import 
org.apache.shardingsphere.elasticjob.lite.spring.namespace.test.AbstractZookeeperJUnit4SpringContextTests;
 import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
+import org.awaitility.Awaitility;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 @RequiredArgsConstructor
@@ -55,9 +59,9 @@ public abstract class AbstractJobSpringIntegrateTest extends 
AbstractZookeeperJU
     }
     
     private void assertSimpleElasticJobBean() {
-        while (!AnnotationSimpleJob.isCompleted()) {
-            BlockUtils.waitingShortTime();
-        }
+        Awaitility.await().atMost(1L, TimeUnit.MINUTES).untilAsserted(() ->
+                assertThat(AnnotationSimpleJob.isCompleted(), is(true))
+        );
         assertTrue(AnnotationSimpleJob.isCompleted());
         assertTrue(regCenter.isExisted("/" + simpleJobName + "/sharding"));
     }
diff --git 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/test/EmbedZookeeperTestExecutionListener.java
 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/test/EmbedZookeeperTestExecutionListener.java
index 6bd6b5685..dfc432b28 100644
--- 
a/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/test/EmbedZookeeperTestExecutionListener.java
+++ 
b/elasticjob-lite/elasticjob-lite-spring/elasticjob-lite-spring-namespace/src/test/java/org/apache/shardingsphere/elasticjob/lite/spring/namespace/test/EmbedZookeeperTestExecutionListener.java
@@ -17,14 +17,19 @@
 
 package org.apache.shardingsphere.elasticjob.lite.spring.namespace.test;
 
+import org.apache.curator.CuratorZookeeperClient;
+import org.apache.curator.retry.ExponentialBackoffRetry;
 import org.apache.curator.test.TestingServer;
 import org.apache.shardingsphere.elasticjob.reg.exception.RegExceptionHandler;
-import org.apache.shardingsphere.elasticjob.infra.concurrent.BlockUtils;
+import org.awaitility.Awaitility;
+import org.hamcrest.Matchers;
 import org.springframework.test.context.TestContext;
 import org.springframework.test.context.support.AbstractTestExecutionListener;
 
-import java.io.File;
 import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertThat;
 
 public final class EmbedZookeeperTestExecutionListener extends 
AbstractTestExecutionListener {
     
@@ -34,13 +39,13 @@ public final class EmbedZookeeperTestExecutionListener 
extends AbstractTestExecu
     public void beforeTestClass(final TestContext testContext) {
         startEmbedTestingServer();
     }
-    
+
     private static void startEmbedTestingServer() {
         if (null != testingServer) {
             return;
         }
         try {
-            testingServer = new TestingServer(3181, new 
File(String.format("target/test_zk_data/%s/", System.nanoTime())));
+            testingServer = new TestingServer(3181, true);
             // CHECKSTYLE:OFF
         } catch (final Exception ex) {
             // CHECKSTYLE:ON
@@ -48,12 +53,24 @@ public final class EmbedZookeeperTestExecutionListener 
extends AbstractTestExecu
         } finally {
             Runtime.getRuntime().addShutdownHook(new Thread(() -> {
                 try {
-                    BlockUtils.sleep(2000L);
                     testingServer.close();
                 } catch (final IOException ex) {
                     RegExceptionHandler.handleException(ex);
                 }
             }));
         }
+        try (CuratorZookeeperClient client = new 
CuratorZookeeperClient(testingServer.getConnectString(),
+                60 * 1000, 500, null,
+                new ExponentialBackoffRetry(500, 3, 500 * 3))) {
+            client.start();
+            Awaitility.await()
+                    .atLeast(100L, TimeUnit.MILLISECONDS)
+                    .atMost(500 * 60L, TimeUnit.MILLISECONDS)
+                    .untilAsserted(() -> assertThat(client.isConnected(), 
Matchers.is(true)));
+            // CHECKSTYLE:OFF
+        } catch (Exception e) {
+            // CHECKSTYLE:ON
+            throw new RuntimeException(e);
+        }
     }
 }
diff --git a/pom.xml b/pom.xml
index e56be37d1..9af552d72 100644
--- a/pom.xml
+++ b/pom.xml
@@ -74,6 +74,7 @@
         <junit.version>4.12</junit.version>
         <hamcrest.version>2.2</hamcrest.version>
         <mockito.version>4.8.0</mockito.version>
+        <awaitility.version>4.2.0</awaitility.version>
         
         <apache-rat-plugin.version>0.15</apache-rat-plugin.version>
         <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
@@ -347,6 +348,12 @@
                 <version>${aspectj.version}</version>
                 <scope>test</scope>
             </dependency>
+            <dependency>
+                <groupId>org.awaitility</groupId>
+                <artifactId>awaitility</artifactId>
+                <version>${awaitility.version}</version>
+                <scope>test</scope>
+            </dependency>
         </dependencies>
     </dependencyManagement>
     

Reply via email to