You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2021/03/08 12:37:45 UTC

[GitHub] [zookeeper] maoling commented on a change in pull request #1621: ZOOKEEPER-1871: Add an option to zkCli to wait for connection before…

maoling commented on a change in pull request #1621:
URL: https://github.com/apache/zookeeper/pull/1621#discussion_r589390356



##########
File path: zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeperMain.java
##########
@@ -289,6 +302,17 @@ protected void connectToZK(String newHost) throws InterruptedException, IOExcept
             System.setProperty(ZKClientConfig.SECURE_CLIENT, "true");
             System.out.println("Secure connection is enabled");
         }
+        if (cl.getOption("waitforconnection") != null) {
+            connectLatch = new CountDownLatch(1);
+        }
+        int timeout = Integer.parseInt(cl.getOption("timeout"));
+        zk = new ZooKeeperAdmin(host, timeout, new MyWatcher(),readOnly);
+        if (connectLatch != null) {

Review comment:
       Could you please add more clarifications about the difference between `waitforconnection` and `timeout` in the GitHub description?

##########
File path: zookeeper-server/src/test/java/org/apache/zookeeper/ZooKeeperTest.java
##########
@@ -685,4 +686,25 @@ public void testSyncCommand() throws Exception {
         runCommandExpect(cmd, expected);
     }
 
+    @Test
+    public void testWaitForConnection() throws Exception {
+        // get a wrong port number
+        int invalid_port = PortAssignment.unique();
+        long timeout = 3000L; // millisecond
+        String[] args1 = {"-server", "localhost:" + invalid_port, "-timeout",
+            Long.toString(timeout), "-waitforconnection", "ls", "/"};
+        long start_time = System.currentTimeMillis();
+        // try to connect to a non-existing server so as to wait until wait_timeout

Review comment:
       using CamelCase naming style(e.g.: `startTime`) in the UT




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org