Search in sources :

Example 1 with MockLeader

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);
    }
}
Also used : MockLeader(org.apache.zookeeper.server.quorum.ZabUtils.MockLeader) ZabUtils.createMockLeader(org.apache.zookeeper.server.quorum.ZabUtils.createMockLeader) ZabUtils.createLeader(org.apache.zookeeper.server.quorum.ZabUtils.createLeader) ZabUtils.createQuorumPeer(org.apache.zookeeper.server.quorum.ZabUtils.createQuorumPeer) File(java.io.File) EOFException(java.io.EOFException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Aggregations

EOFException (java.io.EOFException)1 File (java.io.File)1 IOException (java.io.IOException)1 MockLeader (org.apache.zookeeper.server.quorum.ZabUtils.MockLeader)1 ZabUtils.createLeader (org.apache.zookeeper.server.quorum.ZabUtils.createLeader)1 ZabUtils.createMockLeader (org.apache.zookeeper.server.quorum.ZabUtils.createMockLeader)1 ZabUtils.createQuorumPeer (org.apache.zookeeper.server.quorum.ZabUtils.createQuorumPeer)1 Test (org.junit.jupiter.api.Test)1