consensus-raft/src/test/java/com/mboysan/consensus/RaftNodeTest.java
/**
     * Tests if a command will be routed to the leader if the node is a follower.
     */
Tests if a command will be routed to the leader if the node is a follower.
Tests if a command will be routed to the leader if the node is a follower .
@Test
    void testCommandRouting() throws Exception {
        int numServers = 3;
        init(numServers);
        int leaderId = assertOneLeader();
        List<String> expectedCommands = Arrays.asList("cmd0", "cmd1", "cmd2");
        assertTrue(getNode((leaderId + 1) % numServers).append(expectedCommands.get(0)).get());
        assertTrue(getNode((leaderId + 2) % numServers).append(expectedCommands.get(1)).get());
        assertTrue(getNode((leaderId + 3) % numServers).append(expectedCommands.get(2)).get());
        assertLeaderNotChanged(leaderId);
        assertLogsEquals(expectedCommands);
        advanceTimeForElections();  
        assertLeaderNotChanged(leaderId);
        assertLogsEquals(expectedCommands);
    }
@ Test void testCommandRouting ( ) throws Exception { int numServers = 3 ; init ( numServers ) ; int leaderId = assertOneLeader ( ) ; List < String > expectedCommands = Arrays . asList ( "cmd0" , "cmd1" , "cmd2" ) ; assertTrue ( getNode ( ( leaderId + 1 ) % numServers ) . append ( expectedCommands . get ( 0 ) ) . get ( ) ) ; assertTrue ( getNode ( ( leaderId + 2 ) % numServers ) . append ( expectedCommands . get ( 1 ) ) . get ( ) ) ; assertTrue ( getNode ( ( leaderId + 3 ) % numServers ) . append ( expectedCommands . get ( 2 ) ) . get ( ) ) ; assertLeaderNotChanged ( leaderId ) ; assertLogsEquals ( expectedCommands ) ; advanceTimeForElections ( ) ; assertLeaderNotChanged ( leaderId ) ; assertLogsEquals ( expectedCommands ) ; }
Tests if a command will be routed to the leader if the node is a follower.
Tests if a command will be routed to the leader if the node is a follower .
// if any of the following node is a follower, command will be routed to leader // everything should stay the same even after some time passes