@Test
public void testLeaderCreatedWithCommitIndexLessThanLastIndex() {

    logStart("testLeaderCreatedWithCommitIndexLessThanLastIndex");
    final MockRaftActorContext leaderActorContext = createActorContextWithFollower();
    MockRaftActorContext followerActorContext = createActorContext(FOLLOWER_ID, followerActor);
    Follower follower = new Follower(followerActorContext);
    followerActor.underlyingActor().setBehavior(follower);
    followerActorContext.setCurrentBehavior(follower);
    Map<String, String> peerAddresses = new HashMap<>();
    peerAddresses.put(FOLLOWER_ID, followerActor.path().toString());
    leaderActorContext.setPeerAddresses(peerAddresses);
    leaderActorContext.getReplicatedLog().removeFrom(0);
    //create 3 entries
    leaderActorContext.setReplicatedLog(
            new MockRaftActorContext.MockReplicatedLogBuilder().createEntries(0, 3, 1).build());
    leaderActorContext.setCommitIndex(1);
    followerActorContext.getReplicatedLog().removeFrom(0);
    // follower too has the exact same log entries and has the same commit index
    followerActorContext.setReplicatedLog(
            new MockRaftActorContext.MockReplicatedLogBuilder().createEntries(0, 3, 1).build());
    followerActorContext.setCommitIndex(1);
    leader = new Leader(leaderActorContext);
    leaderActorContext.setCurrentBehavior(leader);
    AppendEntries appendEntries = MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
    assertEquals(-1, appendEntries.getLeaderCommit());
    assertEquals(0, appendEntries.getEntries().size());
    assertEquals(0, appendEntries.getPrevLogIndex());
    AppendEntriesReply appendEntriesReply = MessageCollectorActor.expectFirstMatching(
            leaderActor, AppendEntriesReply.class);
    assertEquals(2, appendEntriesReply.getLogLastIndex());
    assertEquals(1, appendEntriesReply.getLogLastTerm());
    // follower returns its next index
    assertEquals(2, appendEntriesReply.getLogLastIndex());
    assertEquals(1, appendEntriesReply.getLogLastTerm());
    follower.close();
}