You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/07/22 09:22:18 UTC
[shardingsphere-elasticjob] branch master updated: Fix
ZookeeperElectionServiceTest (#1245) (#1247)
This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 8a7e70f Fix ZookeeperElectionServiceTest (#1245) (#1247)
8a7e70f is described below
commit 8a7e70f43ca2600415d69f7a15898d5c0c2a2b1d
Author: Tboy <gu...@immomo.com>
AuthorDate: Wed Jul 22 17:22:03 2020 +0800
Fix ZookeeperElectionServiceTest (#1245) (#1247)
---
.../reg/zookeeper/ZookeeperElectionServiceTest.java | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/elasticjob-infra/elasticjob-registry-center/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java b/elasticjob-infra/elasticjob-registry-center/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java
index 4e1d02c..c03b631 100644
--- a/elasticjob-infra/elasticjob-registry-center/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java
+++ b/elasticjob-infra/elasticjob-registry-center/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java
@@ -17,19 +17,22 @@
package org.apache.shardingsphere.elasticjob.reg.zookeeper;
+import lombok.SneakyThrows;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.recipes.leader.LeaderSelector;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.KillSession;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.fixture.EmbedTestingServer;
import org.apache.shardingsphere.elasticjob.reg.base.ElectionCandidate;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import java.lang.reflect.Field;
+
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -49,7 +52,6 @@ public class ZookeeperElectionServiceTest {
}
@Test
- @Ignore
public void assertContend() throws Exception {
CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
client.start();
@@ -64,6 +66,16 @@ public class ZookeeperElectionServiceTest {
anotherService.start();
KillSession.kill(client.getZookeeperClient().getZooKeeper());
service.stop();
+ blockUtilHasLeadership(anotherService);
verify(anotherElectionCandidate).startLeadership();
}
+
+ @SneakyThrows
+ private void blockUtilHasLeadership(final Object obj) {
+ Field field = ZookeeperElectionService.class.getDeclaredField("leaderSelector");
+ field.setAccessible(true);
+ while (!((LeaderSelector) field.get(obj)).hasLeadership()) {
+ Thread.sleep(100);
+ }
+ }
}