use of org.apache.zookeeper.server.quorum.ZabUtils.MockLeader in project zookeeper by apache.
the class Zab1_0Test method testLastAcceptedEpoch.
/**
* In this test, the leader sets the last accepted epoch to 5. The call
* to getEpochToPropose should set epoch to 6 and wait until another
* follower executes it. If in getEpochToPropose we don't check if
* lastAcceptedEpoch == epoch, then the call from the subsequent
* follower with lastAcceptedEpoch = 6 doesn't change the value
* of epoch, and the test fails. It passes with the fix to predicate.
*
* https://issues.apache.org/jira/browse/ZOOKEEPER-1343
*
* @throws Exception
*/
@Test
public void testLastAcceptedEpoch() throws Exception {
File tmpDir = File.createTempFile("test", "dir", testData);
tmpDir.delete();
tmpDir.mkdir();
Leader leader = null;
LeadThread leadThread = null;
try {
QuorumPeer peer = createQuorumPeer(tmpDir);
leader = createMockLeader(tmpDir, peer);
peer.leader = leader;
peer.setAcceptedEpoch(5);
leadThread = new LeadThread(leader);
leadThread.start();
while (((MockLeader) leader).getCurrentEpochToPropose() != 6) {
Thread.sleep(20);
}
try {
long epoch = leader.getEpochToPropose(1, 6);
assertEquals(7, epoch, "New proposed epoch is wrong");
} catch (Exception e) {
fail("Timed out in getEpochToPropose");
}
} finally {
if (leader != null) {
leader.shutdown("end of test");
}
if (leadThread != null) {
leadThread.interrupt();
leadThread.join();
}
TestUtils.deleteFileRecursively(tmpDir);
}
}
Aggregations