use of com.twitter.common.zookeeper.ZooKeeperClient in project commons by twitter.
the class AngryBirdZooKeeperTest method testFollowerExpiration.
@Test
public void testFollowerExpiration() throws Exception {
// Create some sequential nodes.
ZooKeeperClient zkClient1 = createZKClient();
ZooKeeperClient zkClient2 = createZKClient();
ZooKeeperClient zkClient3 = createZKClient();
// Expire the follower's session.
zkServer.expireFollower(ROOT_PATH, Optional.<String>absent());
// Make sure the leader's session is not expired.
zkClient1.get().exists(zkPaths.get(zkClient1), null);
int numfailed = 0;
// Check that only one of the followers's sessions has expired.
try {
zkClient2.get().exists(zkPaths.get(zkClient2), null);
} catch (KeeperException e) {
numfailed++;
}
try {
zkClient3.get().exists(zkPaths.get(zkClient3), null);
} catch (KeeperException e) {
numfailed++;
}
assertEquals(1, numfailed);
}
use of com.twitter.common.zookeeper.ZooKeeperClient in project commons by twitter.
the class AngryBirdZooKeeperTest method testLeaderExpiration.
@Test(expected = KeeperException.class)
public void testLeaderExpiration() throws Exception {
// Create some sequential nodes.
ZooKeeperClient zkClient1 = createZKClient();
ZooKeeperClient zkClient2 = createZKClient();
ZooKeeperClient zkClient3 = createZKClient();
// Expire the leader's session.
zkServer.expireLeader(ROOT_PATH);
// Make sure the follower sessions are not expired.
zkClient2.get().exists(zkPaths.get(zkClient2), null);
zkClient3.get().exists(zkPaths.get(zkClient3), null);
// Check that leader's session has expired.
zkClient1.get().exists(zkPaths.get(zkClient1), null);
fail("Leader session has not expired!");
}
use of com.twitter.common.zookeeper.ZooKeeperClient in project commons by twitter.
the class AngryBirdZooKeeperTest method createZKClient.
// Creates a zookeeper client and creates a znode with the given path.
private ZooKeeperClient createZKClient(@Nullable byte[] data) throws Exception {
final ZooKeeperClient zkClient = zkServer.createClient();
// Create prefix path if it doesn't exist.
ZooKeeperUtils.ensurePath(zkClient, ACL, ROOT_PATH);
// Create the ephemeral node.
String path = zkClient.get().create(ROOT_PATH, data, ACL, CreateMode.EPHEMERAL_SEQUENTIAL);
LOG.info("Created ephemeral node: " + path);
zkPaths.put(zkClient, path);
return zkClient;
}
use of com.twitter.common.zookeeper.ZooKeeperClient in project commons by twitter.
the class ZooKeeperClientModule method configure.
@Override
protected void configure() {
Key<ZooKeeperClient> clientKey = keyFactory.create(ZooKeeperClient.class);
if (config.inProcess) {
requireBinding(ShutdownRegistry.class);
// Bound privately to give the local provider access to configuration settings.
bind(ClientConfig.class).toInstance(config);
bind(clientKey).toProvider(LocalClientProvider.class).in(Singleton.class);
} else {
ZooKeeperClient client = new ZooKeeperClient(config.sessionTimeout, config.credentials, config.chrootPath, config.servers);
bind(clientKey).toInstance(client);
}
expose(clientKey);
}
Aggregations