@Test
public void testMultipleReplicateShouldNotCauseDuplicateAppendEntriesToBeSent() {

    logStart("testHandleReplicateMessageSendAppendEntriesToFollower");
    MockRaftActorContext actorContext = createActorContextWithFollower();
    actorContext.setConfigParams(new DefaultConfigParamsImpl() {
        @Override
        public FiniteDuration getHeartBeatInterval() {
            return FiniteDuration.apply(5, TimeUnit.SECONDS);
        }
    });
    long term = 1;
    actorContext.getTermInformation().update(term, "");
    leader = new Leader(actorContext);
    // Leader will send an immediate heartbeat - ignore it.
    MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
    // The follower would normally reply - simulate that explicitly here.
    long lastIndex = actorContext.getReplicatedLog().lastIndex();
    leader.handleMessage(followerActor, new AppendEntriesReply(
            FOLLOWER_ID, term, true, lastIndex, term, (short)0));
    assertEquals("isFollowerActive", true, leader.getFollower(FOLLOWER_ID).isFollowerActive());
    followerActor.underlyingActor().clear();
    for (int i = 0; i < 5; i++) {
        sendReplicate(actorContext, lastIndex + i + 1);
    }
    List<AppendEntries> allMessages = MessageCollectorActor.getAllMatching(followerActor, AppendEntries.class);
    // We expect only 1 message to be sent because of two reasons,
    // - an append entries reply was not received
    // - the heartbeat interval has not expired
    // In this scenario if multiple messages are sent they would likely be duplicates
    assertEquals("The number of append entries collected should be 1", 1, allMessages.size());
}