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();
}
Aggregations