FollowerLogInformation { public boolean isFollowerActive() { if (peerInfo.getVotingState() == VotingState.VOTING_NOT_INITIALIZED) { return false; } long elapsed = stopwatch.elapsed(TimeUnit.MILLISECONDS); return stopwatch.isRunning() && elapsed <= context.getConfigParams().getElectionTimeOutInterval().toMillis(); } @VisibleForTesting  FollowerLogInformation(final PeerInfo peerInfo, final long matchIndex, final RaftActorContext context);  FollowerLogInformation(final PeerInfo peerInfo, final RaftActorContext context); boolean decrNextIndex(final long followerLastIndex); @SuppressWarnings("checkstyle:hiddenField") boolean setNextIndex(final long nextIndex); long incrMatchIndex(); @SuppressWarnings("checkstyle:hiddenField") boolean setMatchIndex(final long matchIndex); String getId(); long getNextIndex(); long getMatchIndex(); boolean isFollowerActive(); void markFollowerActive(); @VisibleForTesting void markFollowerInActive(); long nanosSinceLastActivity(); boolean okToReplicate(final long commitIndex); short getPayloadVersion(); void setPayloadVersion(final short payloadVersion); short getRaftVersion(); void setRaftVersion(final short raftVersion); @Nullable LeaderInstallSnapshotState getInstallSnapshotState(); void setLeaderInstallSnapshotState(final @NonNull LeaderInstallSnapshotState state); void clearLeaderInstallSnapshotState(); void setSlicedLogEntryIndex(final long index); boolean isLogEntrySlicingInProgress(); void setNeedsLeaderAddress(final boolean value); @Nullable String needsLeaderAddress(final String leaderId); boolean hasStaleCommitIndex(final long commitIndex); void setSentCommitIndex(final long commitIndex); @Override String toString(); static final long NO_INDEX; }
@Test public void testIsFollowerActive() { MockRaftActorContext context = new MockRaftActorContext(); context.setCommitIndex(10); DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl(); configParams.setHeartBeatInterval(new FiniteDuration(500, TimeUnit.MILLISECONDS)); configParams.setElectionTimeoutFactor(1); context.setConfigParams(configParams); FollowerLogInformation followerLogInformation = new FollowerLogInformation(new PeerInfo("follower1", null, VotingState.VOTING), 9, context); assertFalse("Follower should be termed inactive before stopwatch starts", followerLogInformation.isFollowerActive()); followerLogInformation.markFollowerActive(); if (sleepWithElaspsedTimeReturned(200) > 200) { return; } assertTrue("Follower should be active", followerLogInformation.isFollowerActive()); if (sleepWithElaspsedTimeReturned(400) > 400) { return; } assertFalse("Follower should be inactive after time lapsed", followerLogInformation.isFollowerActive()); followerLogInformation.markFollowerActive(); assertTrue("Follower should be active from inactive", followerLogInformation.isFollowerActive()); }