assertTrue("state should be connected", elector.isConnected());
}
@Test
public void testReElection() {
final SequentialZNode startupNode = elector.getNode();
final DateTime prevElection = elector.getLastElectionTime();
final SequentialZNode newLeader = zkTemplate.createEphemeralSequential(startupNode.getPath());
zkTemplate.delete(startupNode.getFullPath());
assertFalse("leader should be deleted", zkClient.exists(startupNode.getFullPath()));
// allow enough time for event thread to respond
try {
TimeUnit.SECONDS.sleep(1);
} catch (final InterruptedException e) {
}
assertEquals("incorrect leader", newLeader, elector.getLeader());
assertTrue("incorrect sequence", startupNode.getSequence() < elector.getNode().getSequence());
assertTrue("incorrect sequence", newLeader.getSequence() < elector.getNode().getSequence());
assertTrue("incorrect last election time", elector.getLastElectionTime().isAfter(prevElection));
assertTrue("state should be connected", elector.isConnected());
}