Search in sources :

Example 6 with ZooKeeperClient

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);
}
Also used : ZooKeeperClient(com.twitter.common.zookeeper.ZooKeeperClient) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test)

Example 7 with ZooKeeperClient

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!");
}
Also used : ZooKeeperClient(com.twitter.common.zookeeper.ZooKeeperClient) Test(org.junit.Test)

Example 8 with ZooKeeperClient

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;
}
Also used : ZooKeeperClient(com.twitter.common.zookeeper.ZooKeeperClient)

Example 9 with ZooKeeperClient

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);
}
Also used : ZooKeeperClient(com.twitter.common.zookeeper.ZooKeeperClient)

Aggregations

ZooKeeperClient (com.twitter.common.zookeeper.ZooKeeperClient)9 Test (org.junit.Test)5 KeeperException (org.apache.zookeeper.KeeperException)2 Command (com.twitter.common.base.Command)1 DynamicHostSet (com.twitter.common.net.pool.DynamicHostSet)1 Group (com.twitter.common.zookeeper.Group)1 ServerSet (com.twitter.common.zookeeper.ServerSet)1 BaseZooKeeperTest (com.twitter.common.zookeeper.testing.BaseZooKeeperTest)1 ServiceInstance (com.twitter.thrift.ServiceInstance)1 Override (java.lang.Override)1 InetSocketAddress (java.net.InetSocketAddress)1 Watcher (org.apache.zookeeper.Watcher)1 IMocksControl (org.easymock.IMocksControl)1