+
+ @Test
+ public void testOkToReplicate(){
+ MockRaftActorContext context = new MockRaftActorContext();
+ context.setCommitIndex(0);
+ FollowerLogInformation followerLogInformation =
+ new FollowerLogInformationImpl(new PeerInfo("follower1", null, VotingState.VOTING), 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() {
+ final PeerInfo peerInfo = new PeerInfo("follower1", null, VotingState.VOTING_NOT_INITIALIZED);
+ MockRaftActorContext context = new MockRaftActorContext();
+ context.setCommitIndex(0);
+ FollowerLogInformation followerLogInformation = new FollowerLogInformationImpl(peerInfo, -1, context);
+
+ assertFalse(followerLogInformation.okToReplicate());
+
+ followerLogInformation.markFollowerActive();
+ assertFalse(followerLogInformation.isFollowerActive());
+
+ peerInfo.setVotingState(VotingState.VOTING);
+ assertTrue(followerLogInformation.okToReplicate());
+
+ followerLogInformation.markFollowerActive();
+ assertTrue(followerLogInformation.isFollowerActive());
+ }
+
+ @Test
+ public void testNonVotingState() {
+ final PeerInfo peerInfo = new PeerInfo("follower1", null, VotingState.NON_VOTING);
+ MockRaftActorContext context = new MockRaftActorContext();
+ context.setCommitIndex(0);
+ FollowerLogInformation followerLogInformation = new FollowerLogInformationImpl(peerInfo, -1, context);
+
+ assertTrue(followerLogInformation.okToReplicate());
+
+ followerLogInformation.markFollowerActive();
+ assertTrue(followerLogInformation.isFollowerActive());
+ }