List of usage examples for org.apache.zookeeper KeeperException KeeperException
public KeeperException(Code code)
From source file:com.nokia.dempsy.mpcluster.zookeeper.TestZookeeperClusterImpl.java
License:Apache License
@Test public void testBadZooKeeperConnection() throws Throwable { int port = ZookeeperTestServer.findNextPort(); ZookeeperTestServer server = new ZookeeperTestServer(); Throwable receivedException = null; ZookeeperSession<String, String> session = null; try {/*from w ww . j av a2s .c om*/ server.start(); session = new ZookeeperSession<String, String>("127.0.0.1:" + port, 5000) { @Override protected ZooKeeper makeZookeeperInstance(String connectString, int sessionTimeout) throws IOException { return new ZooKeeper(connectString, sessionTimeout, new ZkWatcher()) { @Override public List<String> getChildren(String path, Watcher watcher) throws KeeperException { throw (appropriateException = new KeeperException(Code.DATAINCONSISTENCY) { private static final long serialVersionUID = 1L; }); } }; } }; MpCluster<String, String> cluster = session.getCluster(new ClusterId("test", "test")); try { cluster.getActiveSlots(); } catch (Exception e) { receivedException = e.getCause(); } } finally { server.shutdown(); if (session != null) session.stop(); } assertNotNull(appropriateException); assertTrue(receivedException == appropriateException); }