@Test
public void testHandleElectionTimeoutWhenLeaderMessageReceived() {

    logStart("testHandleElectionTimeoutWhenLeaderMessageReceived");
    MockRaftActorContext context = createActorContext();
    ((DefaultConfigParamsImpl) context.getConfigParams())
            .setHeartBeatInterval(new FiniteDuration(100, TimeUnit.MILLISECONDS));
    ((DefaultConfigParamsImpl) context.getConfigParams()).setElectionTimeoutFactor(4);
    follower = new Follower(context);
    context.setCurrentBehavior(follower);
    Uninterruptibles.sleepUninterruptibly(context.getConfigParams()
            .getElectionTimeOutInterval().toMillis() - 100, TimeUnit.MILLISECONDS);
    follower.handleMessage(leaderActor, new AppendEntries(1, "leader", -1, -1, Collections.emptyList(),
            -1, -1, (short) 1));
    Uninterruptibles.sleepUninterruptibly(130, TimeUnit.MILLISECONDS);
    RaftActorBehavior raftBehavior = follower.handleMessage(leaderActor, ElectionTimeout.INSTANCE);
    assertTrue(raftBehavior instanceof Follower);
    Uninterruptibles.sleepUninterruptibly(context.getConfigParams()
            .getElectionTimeOutInterval().toMillis() - 150, TimeUnit.MILLISECONDS);
    follower.handleMessage(leaderActor, new AppendEntries(1, "leader", -1, -1, Collections.emptyList(),
            -1, -1, (short) 1));
    Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
    raftBehavior = follower.handleMessage(leaderActor, ElectionTimeout.INSTANCE);
    assertTrue(raftBehavior instanceof Follower);
}