@Test
public void testHandleAppendEntriesLeaderChangedAfterSyncUpComplete() {

    logStart("testHandleAppendEntriesLeaderChangedAfterSyncUpComplete");
    MockRaftActorContext context = createActorContext();
    List<ReplicatedLogEntry> entries = Arrays.asList(
            newReplicatedLogEntry(2, 101, "foo"));
    // The new commitIndex is 101
    AppendEntries appendEntries = new AppendEntries(2, "leader-1", 100, 1, entries, 101, 100, (short)0);
    follower = createBehavior(context);
    follower.handleMessage(leaderActor, appendEntries);
    FollowerInitialSyncUpStatus syncStatus = MessageCollectorActor.expectFirstMatching(followerActor,
            FollowerInitialSyncUpStatus.class);
    assertFalse(syncStatus.isInitialSyncDone());
    // Clear all the messages
    MessageCollectorActor.clearMessages(followerActor);
    context.setLastApplied(101);
    context.setCommitIndex(101);
    setLastLogEntry(context, 1, 101,
            new MockRaftActorContext.MockPayload(""));
    entries = Arrays.asList(
            newReplicatedLogEntry(2, 101, "foo"));
    // The new commitIndex is 101
    appendEntries = new AppendEntries(2, "leader-1", 101, 1, entries, 102, 101, (short)0);
    follower.handleMessage(leaderActor, appendEntries);
    syncStatus = MessageCollectorActor.expectFirstMatching(followerActor, FollowerInitialSyncUpStatus.class);
    assertTrue(syncStatus.isInitialSyncDone());
    // Clear all the messages
    MessageCollectorActor.clearMessages(followerActor);
    context.setLastApplied(100);
    setLastLogEntry(context, 1, 100,
            new MockRaftActorContext.MockPayload(""));
    entries = Arrays.asList(
            newReplicatedLogEntry(2, 101, "foo"));
    // leader-2 is becoming the leader now and it says the commitIndex is 45
    appendEntries = new AppendEntries(2, "leader-2", 45, 1, entries, 46, 100, (short)0);
    follower.handleMessage(leaderActor, appendEntries);
    syncStatus = MessageCollectorActor.expectFirstMatching(followerActor, FollowerInitialSyncUpStatus.class);
    // We get a new message saying initial status is not done
    assertFalse(syncStatus.isInitialSyncDone());
}