You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2016/01/18 01:29:54 UTC
[3/9] curator git commit: ZK calls
InetAddress.getLocalHost().getCanonicalHostName internally. On some systems
this takes seconds. Pre-call it and use the elapsed time to set MAX_WAIT_MS
so that tests don't fail in setup
ZK calls InetAddress.getLocalHost().getCanonicalHostName internally. On some systems this takes seconds. Pre-call it and use the elapsed time to set MAX_WAIT_MS so that tests don't fail in setup
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/eee4b039
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/eee4b039
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/eee4b039
Branch: refs/heads/CURATOR-3.0
Commit: eee4b03905e2ded72c32e3d113799644d8823d39
Parents: 9951d4e
Author: randgalt <ra...@apache.org>
Authored: Thu Jan 14 22:38:28 2016 -0500
Committer: randgalt <ra...@apache.org>
Committed: Thu Jan 14 22:38:28 2016 -0500
----------------------------------------------------------------------
.../curator/test/TestingZooKeeperMain.java | 31 ++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/eee4b039/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperMain.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperMain.java b/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperMain.java
index bb70da5..7487557 100644
--- a/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperMain.java
+++ b/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperMain.java
@@ -28,6 +28,8 @@ import org.apache.zookeeper.server.quorum.QuorumPeer;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
import java.io.IOException;
import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.nio.channels.ServerSocketChannel;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;
@@ -37,7 +39,25 @@ public class TestingZooKeeperMain extends ZooKeeperServerMain implements ZooKeep
private final CountDownLatch latch = new CountDownLatch(1);
private final AtomicReference<Exception> startingException = new AtomicReference<Exception>(null);
- private static final int MAX_WAIT_MS = 1000;
+ private static final int MAX_WAIT_MS;
+
+ static
+ {
+ long startMs = System.currentTimeMillis();
+ try
+ {
+ // this can take forever and fails tests - ZK calls it internally so there's nothing we can do
+ // pre flight it and use it to calculate max wait
+ //noinspection ResultOfMethodCallIgnored
+ InetAddress.getLocalHost().getCanonicalHostName();
+ }
+ catch ( UnknownHostException e )
+ {
+ // ignore
+ }
+ long elapsed = System.currentTimeMillis() - startMs;
+ MAX_WAIT_MS = Math.max((int)elapsed * 2, 1000);
+ }
@Override
public void kill()
@@ -119,7 +139,14 @@ public class TestingZooKeeperMain extends ZooKeeperServerMain implements ZooKeep
@Override
public void close() throws IOException
{
- shutdown();
+ try
+ {
+ shutdown();
+ }
+ catch ( Throwable e )
+ {
+ e.printStackTrace(); // just ignore - this class is only for testing
+ }
try
{