+
+ @Test
+ public void testOkToReplicate(){
+ MockRaftActorContext context = new MockRaftActorContext();
+ FollowerLogInformation followerLogInformation =
+ new FollowerLogInformationImpl(
+ "follower1", 10, context);
+
+ assertTrue(followerLogInformation.okToReplicate());
+ assertFalse(followerLogInformation.okToReplicate());
+
+ // wait for 150 milliseconds and it should work again
+ Uninterruptibles.sleepUninterruptibly(150, TimeUnit.MILLISECONDS);
+ assertTrue(followerLogInformation.okToReplicate());
+
+ //increment next index and try immediately and it should work again
+ followerLogInformation.incrNextIndex();
+ assertTrue(followerLogInformation.okToReplicate());
+ }
+
+ @Test
+ public void testVotingNotInitializedState() {
+ MockRaftActorContext context = new MockRaftActorContext();
+ FollowerLogInformation followerLogInformation = new FollowerLogInformationImpl("follower1", -1, context);
+
+ followerLogInformation.setFollowerState(FollowerState.VOTING_NOT_INITIALIZED);
+ assertFalse(followerLogInformation.okToReplicate());
+ assertFalse(followerLogInformation.canParticipateInConsensus());
+
+ followerLogInformation.markFollowerActive();
+ assertFalse(followerLogInformation.isFollowerActive());
+
+ followerLogInformation.setFollowerState(FollowerState.VOTING);
+ assertTrue(followerLogInformation.okToReplicate());
+ assertTrue(followerLogInformation.canParticipateInConsensus());
+
+ followerLogInformation.markFollowerActive();
+ assertTrue(followerLogInformation.isFollowerActive());
+ }
+
+ @Test
+ public void testNonVotingState() {
+ MockRaftActorContext context = new MockRaftActorContext();
+ FollowerLogInformation followerLogInformation = new FollowerLogInformationImpl("follower1", -1, context);
+
+ followerLogInformation.setFollowerState(FollowerState.NON_VOTING);
+ assertTrue(followerLogInformation.okToReplicate());
+ assertFalse(followerLogInformation.canParticipateInConsensus());
+
+ followerLogInformation.markFollowerActive();
+ assertTrue(followerLogInformation.isFollowerActive());
+ }