consensus-bizur/src/test/java/com/mboysan/consensus/BizurNodeTest.java
/**
     * Tests if a command will be routed to the leader if the node is not the leader.
     */
Tests if a command will be routed to the leader if the node is not the leader.
Tests if a command will be routed to the leader if the node is not the leader .
@Test
    void testCommandRouting() throws Exception {
        int numServers = 3;
        init(numServers);
        int leaderId = assertOneLeader();
        Map<String, String> expectedKVs = new HashMap<>() {{
            put("k0", "v0");
            put("k1", "v1");
            put("k2", "v2");
        }};
        getNode((leaderId + 1) % numServers).set("k0", "v0").get();
        getNode((leaderId + 2) % numServers).set("k1", "v1").get();
        getNode((leaderId + 3) % numServers).set("k2", "v2").get();
        assertLeaderNotChanged(leaderId);
        assertBucketMapsEquals(expectedKVs);
        advanceTimeForElections();  
        assertLeaderNotChanged(leaderId);
        assertBucketMapsEquals(expectedKVs);
    }
@ Test void testCommandRouting ( ) throws Exception { int numServers = 3 ; init ( numServers ) ; int leaderId = assertOneLeader ( ) ; Map < String , String > expectedKVs = new HashMap < > ( ) { { put ( "k0" , "v0" ) ; put ( "k1" , "v1" ) ; put ( "k2" , "v2" ) ; } } ; getNode ( ( leaderId + 1 ) % numServers ) . set ( "k0" , "v0" ) . get ( ) ; getNode ( ( leaderId + 2 ) % numServers ) . set ( "k1" , "v1" ) . get ( ) ; getNode ( ( leaderId + 3 ) % numServers ) . set ( "k2" , "v2" ) . get ( ) ; assertLeaderNotChanged ( leaderId ) ; assertBucketMapsEquals ( expectedKVs ) ; advanceTimeForElections ( ) ; assertLeaderNotChanged ( leaderId ) ; assertBucketMapsEquals ( expectedKVs ) ; }
Tests if a command will be routed to the leader if the node is not the leader.
Tests if a command will be routed to the leader if the node is not the leader .
// non-leader nodes will route the command to the leader // everything should stay the same even after some time passes