consensus-raft/src/test/java/com/mboysan/consensus/RaftNodeTest.java
/**
     * Tests re-election mechanism after a leader is killed/disconnected.
     */
Tests re-election mechanism after a leader is killed/disconnected.
Tests re - election mechanism after a leader is killed / disconnected .
@Test
    void testReElection() throws Exception {
        init(3);
        int oldLeaderId = assertOneLeader();
        disconnect(oldLeaderId);
        advanceTimeForElections();
        assertLeaderChanged(oldLeaderId, false /* oldLeader is not aware */);
        connect(oldLeaderId);
        advanceTimeForElections();
        assertOneLeader();
    }
@ Test void testReElection ( ) throws Exception { init ( 3 ) ; int oldLeaderId = assertOneLeader ( ) ; disconnect ( oldLeaderId ) ; advanceTimeForElections ( ) ; assertLeaderChanged ( oldLeaderId , false /* oldLeader is not aware */ ) ; connect ( oldLeaderId ) ; advanceTimeForElections ( ) ; assertOneLeader ( ) ; }
Tests re-election mechanism after a leader is killed/disconnected.
Tests re - election mechanism after a leader is killed / disconnected .
// wait a while and check if the leader has changed // rejoin old leader, old leader might try to recover its leadership due to its short update interval // but at the end there must still be one leader