Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ public synchronized void process(WatchedEvent event) {
public synchronized boolean isConnected() {
return connected;
}

protected synchronized String connectionDescription() {
return String.format("connected(%s), syncConnected(%s), readOnlyConnected(%s)",
connected, syncConnected, readOnlyConnected);
}

public synchronized void waitForConnected(long timeout) throws InterruptedException, TimeoutException {
long expire = Time.currentElapsedTime() + timeout;
long left = timeout;
Expand All @@ -132,8 +138,7 @@ public synchronized void waitForConnected(long timeout) throws InterruptedExcept
left = expire - Time.currentElapsedTime();
}
if (!connected) {
throw new TimeoutException("Failed to connect to ZooKeeper server.");

throw new TimeoutException("Failed to connect to ZooKeeper server: " + connectionDescription());
}
}
public synchronized void waitForSyncConnected(long timeout) throws InterruptedException, TimeoutException {
Expand All @@ -144,18 +149,22 @@ public synchronized void waitForSyncConnected(long timeout) throws InterruptedEx
left = expire - Time.currentElapsedTime();
}
if (!syncConnected) {
throw new TimeoutException("Failed to connect to read-write ZooKeeper server.");
throw new TimeoutException(
"Failed to connect to read-write ZooKeeper server: "
+ connectionDescription());
}
}
public synchronized void waitForReadOnlyConnected(long timeout) throws InterruptedException, TimeoutException {
long expire = System.currentTimeMillis() + timeout;
long expire = Time.currentElapsedTime() + timeout;
long left = timeout;
while (!readOnlyConnected && left > 0) {
wait(left);
left = expire - System.currentTimeMillis();
left = expire - Time.currentElapsedTime();
}
if (!readOnlyConnected) {
throw new TimeoutException("Failed to connect in read-only mode to ZooKeeper server.");
throw new TimeoutException(
"Failed to connect in read-only mode to ZooKeeper server: "
+ connectionDescription());
}
}
public synchronized void waitForDisconnected(long timeout) throws InterruptedException, TimeoutException {
Expand All @@ -166,8 +175,7 @@ public synchronized void waitForDisconnected(long timeout) throws InterruptedExc
left = expire - Time.currentElapsedTime();
}
if (connected) {
throw new TimeoutException("Did not disconnect");

throw new TimeoutException("Did not disconnect: " + connectionDescription());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public void testConnectionEvents() throws Exception {

// Re-connect the client (in case we were connected to the shut down
// server and the local session was not persisted).
watcher = new CountdownWatcher();
zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, watcher, true);
long start = Time.currentElapsedTime();
while (!(zk.getState() == States.CONNECTEDREADONLY)) {
Expand Down