Skip to content

Commit

Permalink
use CountDownLatch to check zk registry if establish connection (apac…
Browse files Browse the repository at this point in the history
  • Loading branch information
tswstarplanet authored and beiwei30 committed Aug 1, 2019
1 parent 65a0140 commit 5b38331
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public class ZookeeperRegistry extends FailbackRegistry {

private final static Logger logger = LoggerFactory.getLogger(ZookeeperRegistry.class);

private final static int DEFAULT_ZOOKEEPER_PORT = 2181;

private final static String DEFAULT_ROOT = "dubbo";

private final String root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public class ZookeeperRegistryTest {
public void setUp() throws Exception {
int zkServerPort = NetUtils.getAvailablePort();
this.zkServer = new TestingServer(zkServerPort, true);
this.registryUrl = URL.valueOf("zookeeper://localhost:" + zkServerPort);
this.zkServer.start();

this.registryUrl = URL.valueOf("zookeeper://localhost:" + zkServerPort);
zookeeperRegistryFactory = new ZookeeperRegistryFactory();
zookeeperRegistryFactory.setZookeeperTransporter(new CuratorZookeeperTransporter());
this.zookeeperRegistry = (ZookeeperRegistry) zookeeperRegistryFactory.createRegistry(registryUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;

import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;

Expand Down Expand Up @@ -84,6 +85,10 @@ public void stateChanged(CuratorFramework client, ConnectionState state) {
}
});
client.start();
boolean connected = client.blockUntilConnected(timeout, TimeUnit.MILLISECONDS);
if (!connected) {
throw new IllegalStateException("zookeeper not connected");
}
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
}
Expand Down

0 comments on commit 5b38331

Please sign in to comment.