@Test
public void testWorkerThreads() throws Exception {
ArrayList<QuorumPeer> peerList = new ArrayList<QuorumPeer>();
for (int sid = 0; sid < 3; sid++) {
QuorumPeer peer = new QuorumPeer(peers, tmpdir[sid], tmpdir[sid],
port[sid], 3, sid, 1000, 2, 2);
LOG.info("Starting peer " + peer.getId());
peer.start();
peerList.add(sid, peer);
}
Thread.sleep(10000);
verifyThreadCount(peerList, 4);
for (int myid = 0; myid < 3; myid++) {
for (int i = 0; i < 5; i++) {
// halt one of the listeners and verify count
QuorumPeer peer = peerList.get(myid);
LOG.info("Round " + i + ", halting peer " + peer.getId());
peer.shutdown();
peerList.remove(myid);
Thread.sleep((peer.getSyncLimit() * peer.getTickTime()) + 2000);
verifyThreadCount(peerList, 2);
// Restart halted node and verify count
peer = new QuorumPeer(peers, tmpdir[myid], tmpdir[myid],
port[myid], 3, myid, 1000, 2, 2);
LOG.info("Round " + i + ", restarting peer " + peer.getId());
peer.start();
peerList.add(myid, peer);
Thread.sleep(peer.getInitLimit() * peer.getTickTime() * 2);
verifyThreadCount(peerList, 4);
}
}
}