use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project pinpoint by naver.
the class DefaultZookeeperClient method exists.
@Override
public boolean exists(String path) throws PinpointZookeeperException, InterruptedException {
checkState();
ZooKeeper zookeeper = this.zookeeper;
try {
Stat stat = zookeeper.exists(path, false);
if (stat == null) {
return false;
}
} catch (KeeperException exception) {
if (exception.code() != Code.NODEEXISTS) {
handleException(exception);
}
}
return true;
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project pinpoint by naver.
the class ZookeeperClient method exists.
public boolean exists(String path) throws PinpointZookeeperException, InterruptedException {
checkState();
ZooKeeper zookeeper = this.zookeeper;
try {
Stat stat = zookeeper.exists(path, false);
if (stat == null) {
return false;
}
} catch (KeeperException exception) {
if (exception.code() != Code.NODEEXISTS) {
handleException(exception);
}
}
return true;
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project Dempsy by Dempsy.
the class TestZookeeperClusterImpl method testBadZooKeeperConnection.
@Test
public void testBadZooKeeperConnection() throws Throwable {
int port = ZookeeperTestServer.findNextPort();
ZookeeperTestServer server = new ZookeeperTestServer();
Throwable receivedException = null;
ZookeeperSession session = null;
try {
server.start();
session = new ZookeeperSession("127.0.0.1:" + port, 5000) {
@Override
protected ZooKeeper makeZooKeeperClient(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;
});
}
};
}
};
try {
session.getSubdirs(new ClusterId("test", "test").asPath(), null);
} catch (Exception e) {
receivedException = e.getCause();
}
} finally {
server.shutdown();
if (session != null)
session.stop();
}
assertNotNull(appropriateException);
assertTrue(receivedException == appropriateException);
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project Dempsy by Dempsy.
the class ZookeeperTestServer method forceSessionExpiration.
public static void forceSessionExpiration(ZooKeeper origZk) throws Throwable {
TestUtils.Condition<ZooKeeper> condition = new TestUtils.Condition<ZooKeeper>() {
@Override
public boolean conditionMet(ZooKeeper o) throws Throwable {
try {
return (o.getState() == ZooKeeper.States.CONNECTED) && o.exists("/", true) != null;
} catch (KeeperException ke) {
return false;
}
}
};
assertTrue(TestUtils.poll(5000, origZk, condition));
boolean done = false;
while (!done) {
long sessionid = origZk.getSessionId();
byte[] pw = origZk.getSessionPasswd();
KWatcher kwatcher = new KWatcher();
ZooKeeper killer = new ZooKeeper("127.0.0.1:" + port, 5000, kwatcher, sessionid, pw);
kwatcher.connection.set(killer);
// wait until we get a close
boolean calledBack = TestUtils.poll(5000, kwatcher, new Condition<KWatcher>() {
@Override
public boolean conditionMet(KWatcher o) throws Throwable {
return o.closed.get();
}
});
if (!calledBack)
killer.close();
final AtomicBoolean isExpired = new AtomicBoolean(false);
ZooKeeper check = new ZooKeeper("127.0.0.1:" + port, 5000, new Watcher() {
@Override
public void process(WatchedEvent event) {
if (event.getState() == Watcher.Event.KeeperState.Expired)
isExpired.set(true);
}
}, sessionid, pw);
done = TestUtils.poll(5000, isExpired, new Condition<AtomicBoolean>() {
public boolean conditionMet(AtomicBoolean o) {
return o.get();
}
});
check.close();
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException in project pulsar by yahoo.
the class ZookeeperCacheLoaderTest method testZookeeperCacheLoader.
/**
* Create znode for available broker in ZooKeeper and updates it again to verify ZooKeeper cache update
*
* @throws InterruptedException
* @throws KeeperException
* @throws IOException
*/
@Test
public void testZookeeperCacheLoader() throws InterruptedException, KeeperException, Exception {
DiscoveryZooKeeperClientFactoryImpl.zk = mockZookKeeper;
ZookeeperCacheLoader zkLoader = new ZookeeperCacheLoader(new DiscoveryZooKeeperClientFactoryImpl(), "");
List<String> brokers = Lists.newArrayList("broker-1:15000", "broker-2:15000", "broker-3:15000");
// 1. create znode for each broker
brokers.stream().forEach(b -> {
try {
zkLoader.getLocalZkCache().getZooKeeper().create(LOADBALANCE_BROKERS_ROOT + "/" + b, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} catch (KeeperException | InterruptedException e) {
fail("failed while creating broker znodes");
}
});
// wait for 100 msec: to get cache updated
Thread.sleep(100);
// 2. get available brokers from ZookeeperCacheLoader
List<LoadReport> list = zkLoader.getAvailableBrokers();
// 3. verify retrieved broker list
Assert.assertTrue(brokers.containsAll(list));
// 4.a add new broker
zkLoader.getLocalZkCache().getZooKeeper().create(LOADBALANCE_BROKERS_ROOT + "/" + "broker-4:15000", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
brokers.add("broker-4:15000");
// wait for 100 msec: to get cache updated
Thread.sleep(100);
// 4.b. get available brokers from ZookeeperCacheLoader
list = zkLoader.getAvailableBrokers();
// 4.c. verify retrieved broker list
Assert.assertTrue(brokers.containsAll(list));
}
Aggregations