Search in sources :

Example 1 with LearnerHandler

use of org.apache.zookeeper.server.quorum.LearnerHandler in project zookeeper by apache.

the class QuorumTest method testLeaderShutdown.

@Test
public void testLeaderShutdown() throws IOException, InterruptedException, KeeperException {
    ZooKeeper zk = new DisconnectableZooKeeper(qb.hostPort, ClientBase.CONNECTION_TIMEOUT, new Watcher() {

        public void process(WatchedEvent event) {
        }
    });
    zk.create("/blah", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/blah/blah", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    Leader leader = qb.s1.leader;
    if (leader == null)
        leader = qb.s2.leader;
    if (leader == null)
        leader = qb.s3.leader;
    if (leader == null)
        leader = qb.s4.leader;
    if (leader == null)
        leader = qb.s5.leader;
    Assert.assertNotNull(leader);
    for (int i = 0; i < 5000; i++) {
        zk.setData("/blah/blah", new byte[0], -1, new AsyncCallback.StatCallback() {

            public void processResult(int rc, String path, Object ctx, Stat stat) {
                counter++;
                if (rc != 0) {
                    errors++;
                }
            }
        }, null);
    }
    for (LearnerHandler f : leader.getForwardingFollowers()) {
        f.getSocket().shutdownInput();
    }
    for (int i = 0; i < 5000; i++) {
        zk.setData("/blah/blah", new byte[0], -1, new AsyncCallback.StatCallback() {

            public void processResult(int rc, String path, Object ctx, Stat stat) {
                counter++;
                if (rc != 0) {
                    errors++;
                }
            }
        }, null);
    }
    // check if all the followers are alive
    Assert.assertTrue(qb.s1.isAlive());
    Assert.assertTrue(qb.s2.isAlive());
    Assert.assertTrue(qb.s3.isAlive());
    Assert.assertTrue(qb.s4.isAlive());
    Assert.assertTrue(qb.s5.isAlive());
    zk.close();
}
Also used : WatchedEvent(org.apache.zookeeper.WatchedEvent) LearnerHandler(org.apache.zookeeper.server.quorum.LearnerHandler) ZooKeeper(org.apache.zookeeper.ZooKeeper) Stat(org.apache.zookeeper.data.Stat) Leader(org.apache.zookeeper.server.quorum.Leader) AsyncCallback(org.apache.zookeeper.AsyncCallback) Watcher(org.apache.zookeeper.Watcher) CountdownWatcher(org.apache.zookeeper.test.ClientBase.CountdownWatcher) Test(org.junit.Test)

Aggregations

AsyncCallback (org.apache.zookeeper.AsyncCallback)1 WatchedEvent (org.apache.zookeeper.WatchedEvent)1 Watcher (org.apache.zookeeper.Watcher)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1 Stat (org.apache.zookeeper.data.Stat)1 Leader (org.apache.zookeeper.server.quorum.Leader)1 LearnerHandler (org.apache.zookeeper.server.quorum.LearnerHandler)1 CountdownWatcher (org.apache.zookeeper.test.ClientBase.CountdownWatcher)1 Test (org.junit.Test)1