This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 8eac50adb Fix ZookeeperRegistryCenterWatchTest failed occasionally
(#2109)
8eac50adb is described below
commit 8eac50adba90c029e109107a9243a5980931a367
Author: 吴伟杰 <[email protected]>
AuthorDate: Mon Aug 1 13:07:55 2022 +0800
Fix ZookeeperRegistryCenterWatchTest failed occasionally (#2109)
* Use different key in ZookeeperRegistryCenterWatchTest
* Fix ZookeeperRegistryCenterWatchTest failed occasionally
* Shutdown execute at the end of test
* Persist after watch
---
.../ZookeeperRegistryCenterWatchTest.java | 34 +++++++++++++---------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git
a/elasticjob-infra/elasticjob-registry-center/elasticjob-regitry-center-provider/elasticjob-registry-center-zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterWatchTest.java
b/elasticjob-infra/elasticjob-registry-center/elasticjob-regitry-center-provider/elasticjob-registry-center-zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterWatchTest.java
index 9f1f3429d..50b4c08e3 100644
---
a/elasticjob-infra/elasticjob-registry-center/elasticjob-regitry-center-provider/elasticjob-registry-center-zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterWatchTest.java
+++
b/elasticjob-infra/elasticjob-registry-center/elasticjob-regitry-center-provider/elasticjob-registry-center-zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterWatchTest.java
@@ -24,14 +24,15 @@ import
org.apache.shardingsphere.elasticjob.reg.zookeeper.util.ZookeeperRegistry
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import static org.junit.Assert.assertThat;
-import static org.hamcrest.CoreMatchers.startsWith;
import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.junit.Assert.assertThat;
+
public final class ZookeeperRegistryCenterWatchTest {
private static final ZookeeperConfiguration ZOOKEEPER_CONFIGURATION = new
ZookeeperConfiguration(EmbedTestingServer.getConnectionString(),
ZookeeperRegistryCenterWatchTest.class.getName());
@@ -55,36 +56,41 @@ public final class ZookeeperRegistryCenterWatchTest {
@Test(timeout = 10000L)
public void assertWatchWithoutExecutor() throws InterruptedException {
CountDownLatch waitingForCountDownValue = new CountDownLatch(1);
- zkRegCenter.addCacheData("/test");
+ String key = "/test-watch-without-executor";
+ zkRegCenter.addCacheData(key);
CountDownLatch waitingForWatchReady = new CountDownLatch(1);
- zkRegCenter.watch("/test", event -> {
+ zkRegCenter.watch(key, event -> {
waitingForWatchReady.countDown();
if (DataChangedEvent.Type.UPDATED == event.getType() &&
"countDown".equals(event.getValue())) {
waitingForCountDownValue.countDown();
}
}, null);
+ zkRegCenter.persist(key, "");
waitingForWatchReady.await();
- zkRegCenter.update("/test", "countDown");
+ zkRegCenter.update(key, "countDown");
waitingForCountDownValue.await();
}
- @Test(timeout = 30000L)
+ @Test(timeout = 10000L)
public void assertWatchWithExecutor() throws InterruptedException {
CountDownLatch waitingForCountDownValue = new CountDownLatch(1);
- zkRegCenter.addCacheData("/test");
+ String key = "/test-watch-with-executor";
+ zkRegCenter.addCacheData(key);
CountDownLatch waitingForWatchReady = new CountDownLatch(1);
- String threadNamePreffix = "ListenerNotify";
- ThreadFactory threadFactory =
ThreadUtils.newGenericThreadFactory(threadNamePreffix);
- Executor executor = Executors.newSingleThreadExecutor(threadFactory);
- zkRegCenter.watch("/test", event -> {
- assertThat(Thread.currentThread().getName(),
startsWith(threadNamePreffix));
+ String threadNamePrefix = "ListenerNotify";
+ ThreadFactory threadFactory =
ThreadUtils.newGenericThreadFactory(threadNamePrefix);
+ ExecutorService executor =
Executors.newSingleThreadExecutor(threadFactory);
+ zkRegCenter.watch(key, event -> {
+ assertThat(Thread.currentThread().getName(),
startsWith(threadNamePrefix));
waitingForWatchReady.countDown();
if (DataChangedEvent.Type.UPDATED == event.getType() &&
"countDown".equals(event.getValue())) {
waitingForCountDownValue.countDown();
}
}, executor);
+ zkRegCenter.persist(key, "");
waitingForWatchReady.await();
- zkRegCenter.update("/test", "countDown");
+ zkRegCenter.update(key, "countDown");
waitingForCountDownValue.await();
+ executor.shutdown();
}
}