public void testD2WithQuorumLeaderPeerDown() throws Exception
{
setup();
assertQuorumProcessAllRequests(D2_CONFIG_DATA);
// Shutdown zk _quorum leader peer
ZKPeer peer = _quorum.getQuorumLeader();
if (peer != null)
{
int peerId = peer.getId();
peer.shutdownPeer();
// Verify requests are processed while leader goes down
long start = System.currentTimeMillis();
while (_quorum.getQuorumLeader() != null && _quorum.getQuorumLeader().equals(peer) && System.currentTimeMillis() < (start + TIMEOUT))
{
assertQuorumProcessAllRequests(D2_CONFIG_DATA);
}
start = System.currentTimeMillis();
while (_quorum.getQuorumLeader() == null && System.currentTimeMillis() < (start + TIMEOUT))
{
assertQuorumProcessAllRequests(D2_CONFIG_DATA); // wait while zookeeper is establishing a new leader
}
if (_quorum.getQuorumLeader() == null)
{
_quorum.restartAll();
}
else
{
assertTrue(! _quorum.getQuorumLeader().equals(peer), "No new _quorum leader was established. New leader id=" + _quorum.getQuorumLeader().getId());
// Restart leader peer
_quorum.restart(peerId);
}
start = System.currentTimeMillis();
peer = _quorum.get(peerId);
// Verify requests are processed while peer is restarting
while (System.currentTimeMillis() < (start + TIMEOUT) && ( peer.getZKServer() == null || ! _quorum.areAllPeersUp() || ! peer.getZKServer().isRunning()))
{
assertQuorumProcessAllRequests(D2_CONFIG_DATA);
}
// After restart
assertQuorumProcessAllRequests(D2_CONFIG_DATA);