int index = 1;
while(qu.getPeer(index).peer.leader == null)
index++;
Leader leader = qu.getPeer(index).peer.leader;
Assert.assertNotNull(leader);
/*
* Reusing the index variable to select a follower to connect to
*/
index = (index == 1) ? 2 : 1;
ZooKeeper zk = new DisconnectableZooKeeper(
"127.0.0.1:" + qu.getPeer(index).peer.getClientPort(),
ClientBase.CONNECTION_TIMEOUT, new Watcher() {
public void process(WatchedEvent event) { }
});
zk.create("/blah", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
for(int i = 0; i < 50000; i++) {
zk.setData("/blah", new byte[0], -1, new AsyncCallback.StatCallback() {
public void processResult(int rc, String path, Object ctx,
Stat stat) {
counter++;
if (rc != 0) {
errors++;
}
if(counter == 20000){
sem.release();
}
}
}, null);
if(i == 5000){
qu.shutdown(index);
LOG.info("Shutting down s1");
}
if(i == 12000){
qu.start(index);
LOG.info("Setting up server: " + index);
}
if((i % 1000) == 0){
Thread.sleep(500);
}
}
// Wait until all updates return
sem.tryAcquire(15, TimeUnit.SECONDS);
// Verify that server is following and has the same epoch as the leader
Assert.assertTrue("Not following", qu.getPeer(index).peer.follower != null);
long epochF = (qu.getPeer(index).peer.getActiveServer().getZxid() >> 32L);
long epochL = (leader.getEpoch() >> 32L);
Assert.assertTrue("Zxid: " + qu.getPeer(index).peer.getActiveServer().getZxid() +
"Current epoch: " + epochF, epochF == epochL);
}