@Test
public void testHandleAppendEntriesWithExistingLogEntry() {

    logStart("testHandleAppendEntriesWithExistingLogEntry");
    MockRaftActorContext context = createActorContext();
    context.getTermInformation().update(1, "test");
    // Prepare the receivers log
    MockRaftActorContext.SimpleReplicatedLog log = new MockRaftActorContext.SimpleReplicatedLog();
    log.append(newReplicatedLogEntry(1, 0, "zero"));
    log.append(newReplicatedLogEntry(1, 1, "one"));
    context.setReplicatedLog(log);
    // Send the last entry again.
    List<ReplicatedLogEntry> entries = Arrays.asList(newReplicatedLogEntry(1, 1, "one"));
    follower = createBehavior(context);
    follower.handleMessage(leaderActor, new AppendEntries(1, "leader", 0, 1, entries, 1, -1, (short)0));
    assertEquals("Next index", 2, log.last().getIndex() + 1);
    assertEquals("Entry 1", entries.get(0), log.get(1));
    expectAndVerifyAppendEntriesReply(1, true, context.getId(), 1, 1);
    // Send the last entry again and also a new one.
    entries = Arrays.asList(newReplicatedLogEntry(1, 1, "one"), newReplicatedLogEntry(1, 2, "two"));
    MessageCollectorActor.clearMessages(leaderActor);
    follower.handleMessage(leaderActor, new AppendEntries(1, "leader", 0, 1, entries, 2, -1, (short)0));
    assertEquals("Next index", 3, log.last().getIndex() + 1);
    assertEquals("Entry 1", entries.get(0), log.get(1));
    assertEquals("Entry 2", entries.get(1), log.get(2));
    expectAndVerifyAppendEntriesReply(1, true, context.getId(), 1, 2);
}