You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by sl...@apache.org on 2013/06/25 22:21:42 UTC
git commit: https://issues.apache.org/jira/browse/HELIX-131
Updated Branches:
refs/heads/master fbcd316d6 -> bf7a6583e
https://issues.apache.org/jira/browse/HELIX-131
Add configurable timeout value when creating a ZKHelixAdmin, in case the
ZKHelixAdmin is pointed to wrong zk address
Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/bf7a6583
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/bf7a6583
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/bf7a6583
Branch: refs/heads/master
Commit: bf7a6583e2609dc2ac8901937befc5d5629ffdca
Parents: fbcd316
Author: slu2011 <lu...@gmail.com>
Authored: Tue Jun 25 13:17:49 2013 -0700
Committer: slu2011 <lu...@gmail.com>
Committed: Tue Jun 25 13:17:49 2013 -0700
----------------------------------------------------------------------
.../apache/helix/manager/zk/ZKHelixAdmin.java | 7 +++--
.../apache/helix/tools/TestClusterSetup.java | 31 +++++++++++++++++++-
2 files changed, 34 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/bf7a6583/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
index d9c2608..1a5609b 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
@@ -82,7 +82,7 @@ import org.apache.log4j.Logger;
public class ZKHelixAdmin implements HelixAdmin
{
-
+ public static final String CONNECTION_TIMEOUT = "helixAdmin.timeOutInSec";
private final ZkClient _zkClient;
private final ConfigAccessor _configAccessor;
@@ -96,9 +96,10 @@ public class ZKHelixAdmin implements HelixAdmin
public ZKHelixAdmin(String zkAddress)
{
- _zkClient = new ZkClient(zkAddress);
+ int timeOutInSec = Integer.parseInt(System.getProperty(CONNECTION_TIMEOUT, "30"));
+ _zkClient = new ZkClient(zkAddress, timeOutInSec * 1000);
_zkClient.setZkSerializer(new ZNRecordSerializer());
- _zkClient.waitUntilConnected(30, TimeUnit.SECONDS);
+ _zkClient.waitUntilConnected(timeOutInSec, TimeUnit.SECONDS);
_configAccessor = new ConfigAccessor(_zkClient);
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/bf7a6583/helix-core/src/test/java/org/apache/helix/tools/TestClusterSetup.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/tools/TestClusterSetup.java b/helix-core/src/test/java/org/apache/helix/tools/TestClusterSetup.java
index de28824..b720912 100644
--- a/helix-core/src/test/java/org/apache/helix/tools/TestClusterSetup.java
+++ b/helix-core/src/test/java/org/apache/helix/tools/TestClusterSetup.java
@@ -31,6 +31,7 @@ import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.ZkUnitTestBase;
import org.apache.helix.PropertyKey.Builder;
+import org.apache.helix.manager.zk.ZKHelixAdmin;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
@@ -96,7 +97,35 @@ public class TestClusterSetup extends ZkUnitTestBase
_clusterSetup = new ClusterSetup(ZK_ADDR);
_clusterSetup.addCluster(CLUSTER_NAME, true);
}
-
+
+ @Test
+ public void testZkAdminTimeout()
+ {
+ boolean exceptionThrown = false;
+ try
+ {
+ new ZKHelixAdmin("localhost:27999");
+ }
+ catch(Exception e)
+ {
+ exceptionThrown = true;
+ }
+ Assert.assertTrue(exceptionThrown);
+ System.setProperty(ZKHelixAdmin.CONNECTION_TIMEOUT, "3");
+ exceptionThrown = false;
+ long time = System.currentTimeMillis();
+ try
+ {
+ new ZKHelixAdmin("localhost:27999");
+ }
+ catch(Exception e)
+ {
+ exceptionThrown = true;
+ }
+ Assert.assertTrue(exceptionThrown);
+ Assert.assertTrue(System.currentTimeMillis() - time < 5000);
+ }
+
@Test()
public void testAddInstancesToCluster() throws Exception
{