@Test public void testGet() throws Exception { final ZooKeeperClient zkClient = createZkClient(); shutdownNetwork(); try { zkClient.get(Amount.of(50L, Time.MILLISECONDS)); fail("Expected client connection to timeout while network down"); } catch (TimeoutException e) { assertTrue(zkClient.isClosed()); } assertNull(zkClient.getZooKeeperClientForTests()); final CountDownLatch blockingGetComplete = new CountDownLatch(1); final AtomicReference<ZooKeeper> client = new AtomicReference<ZooKeeper>(); new Thread(() -> { try { client.set(zkClient.get()); } catch (ZooKeeperConnectionException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } finally { blockingGetComplete.countDown(); } }).start(); restartNetwork(); blockingGetComplete.await(); assertNotNull(client.get()); long sessionId = zkClient.get().getSessionId(); assertSame(client.get(), zkClient.get()); shutdownNetwork(); ZooKeeper zooKeeper = zkClient.get(); try { zooKeeper.exists("/", false); fail("Expected client operation to fail while network down"); } catch (ConnectionLossException e) { } restartNetwork(); assertEquals("Expected connection to be re-established with existing session", sessionId, zkClient.get().getSessionId()); }
public synchronized ZooKeeper get() throws ZooKeeperConnectionException, InterruptedException { try { return get(WAIT_FOREVER); } catch (TimeoutException e) { InterruptedException interruptedException = new InterruptedException("Got an unexpected TimeoutException for 0 wait"); interruptedException.initCause(e); throw interruptedException; } }
ZooKeeperClient { public synchronized ZooKeeper get() throws ZooKeeperConnectionException, InterruptedException { try { return get(WAIT_FOREVER); } catch (TimeoutException e) { InterruptedException interruptedException = new InterruptedException("Got an unexpected TimeoutException for 0 wait"); interruptedException.initCause(e); throw interruptedException; } } }
ZooKeeperClient { public synchronized ZooKeeper get() throws ZooKeeperConnectionException, InterruptedException { try { return get(WAIT_FOREVER); } catch (TimeoutException e) { InterruptedException interruptedException = new InterruptedException("Got an unexpected TimeoutException for 0 wait"); interruptedException.initCause(e); throw interruptedException; } } ZooKeeperClient(Amount<Integer, Time> sessionTimeout, InetSocketAddress zooKeeperServer,
      InetSocketAddress... zooKeeperServers);  ZooKeeperClient(Amount<Integer, Time> sessionTimeout,
      Iterable<InetSocketAddress> zooKeeperServers);  ZooKeeperClient(Amount<Integer, Time> sessionTimeout, Credentials credentials,
      InetSocketAddress zooKeeperServer, InetSocketAddress... zooKeeperServers);  ZooKeeperClient(Amount<Integer, Time> sessionTimeout, Credentials credentials,
      Iterable<InetSocketAddress> zooKeeperServers);  ZooKeeperClient(Amount<Integer, Time> sessionTimeout, Optional<Credentials> credentials,
      Optional<String> chrootPath, Iterable<InetSocketAddress> zooKeeperServers); }
ZooKeeperClient { public synchronized ZooKeeper get() throws ZooKeeperConnectionException, InterruptedException { try { return get(WAIT_FOREVER); } catch (TimeoutException e) { InterruptedException interruptedException = new InterruptedException("Got an unexpected TimeoutException for 0 wait"); interruptedException.initCause(e); throw interruptedException; } } ZooKeeperClient(Amount<Integer, Time> sessionTimeout, InetSocketAddress zooKeeperServer,
      InetSocketAddress... zooKeeperServers);  ZooKeeperClient(Amount<Integer, Time> sessionTimeout,
      Iterable<InetSocketAddress> zooKeeperServers);  ZooKeeperClient(Amount<Integer, Time> sessionTimeout, Credentials credentials,
      InetSocketAddress zooKeeperServer, InetSocketAddress... zooKeeperServers);  ZooKeeperClient(Amount<Integer, Time> sessionTimeout, Credentials credentials,
      Iterable<InetSocketAddress> zooKeeperServers);  ZooKeeperClient(Amount<Integer, Time> sessionTimeout, Optional<Credentials> credentials,
      Optional<String> chrootPath, Iterable<InetSocketAddress> zooKeeperServers); synchronized ZooKeeper get(); synchronized ZooKeeper get(Amount<Long, Time> connectionTimeout); Watcher registerExpirationHandler(final Command onExpired); void register(Watcher watcher); boolean unregister(Watcher watcher); boolean shouldRetry(KeeperException e); synchronized void close(); }
ZooKeeperClient { public synchronized ZooKeeper get() throws ZooKeeperConnectionException, InterruptedException { try { return get(WAIT_FOREVER); } catch (TimeoutException e) { InterruptedException interruptedException = new InterruptedException("Got an unexpected TimeoutException for 0 wait"); interruptedException.initCause(e); throw interruptedException; } } ZooKeeperClient(Amount<Integer, Time> sessionTimeout, InetSocketAddress zooKeeperServer,
      InetSocketAddress... zooKeeperServers);  ZooKeeperClient(Amount<Integer, Time> sessionTimeout,
      Iterable<InetSocketAddress> zooKeeperServers);  ZooKeeperClient(Amount<Integer, Time> sessionTimeout, Credentials credentials,
      InetSocketAddress zooKeeperServer, InetSocketAddress... zooKeeperServers);  ZooKeeperClient(Amount<Integer, Time> sessionTimeout, Credentials credentials,
      Iterable<InetSocketAddress> zooKeeperServers);  ZooKeeperClient(Amount<Integer, Time> sessionTimeout, Optional<Credentials> credentials,
      Optional<String> chrootPath, Iterable<InetSocketAddress> zooKeeperServers); synchronized ZooKeeper get(); synchronized ZooKeeper get(Amount<Long, Time> connectionTimeout); Watcher registerExpirationHandler(final Command onExpired); void register(Watcher watcher); boolean unregister(Watcher watcher); boolean shouldRetry(KeeperException e); synchronized void close();  }