X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FFollowerLogInformationImplTest.java;h=843b9bebbd3956a3bda56c251a03e697bbc72867;hb=ac5bcae15c3c9831f2879ae44c66b39130e3f2fe;hp=bdfd69ec119acab3a19703de8578702c10984c05;hpb=608760751ce7fcf4e84e86a8b33d43bc1d9984d6;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/FollowerLogInformationImplTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/FollowerLogInformationImplTest.java index bdfd69ec11..843b9bebbd 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/FollowerLogInformationImplTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/FollowerLogInformationImplTest.java @@ -29,14 +29,14 @@ public class FollowerLogInformationImplTest { context.setConfigParams(configParams); FollowerLogInformation followerLogInformation = - new FollowerLogInformationImpl("follower1", 9, context); + new FollowerLogInformationImpl(new PeerInfo("follower1", null, VotingState.VOTING), 9, context); assertFalse("Follower should be termed inactive before stopwatch starts", - followerLogInformation.isFollowerActive()); + followerLogInformation.isFollowerActive()); followerLogInformation.markFollowerActive(); if (sleepWithElaspsedTimeReturned(200) > 200) { - return; + return; } assertTrue("Follower should be active", followerLogInformation.isFollowerActive()); @@ -44,17 +44,17 @@ public class FollowerLogInformationImplTest { return; } assertFalse("Follower should be inactive after time lapsed", - followerLogInformation.isFollowerActive()); + followerLogInformation.isFollowerActive()); followerLogInformation.markFollowerActive(); assertTrue("Follower should be active from inactive", - followerLogInformation.isFollowerActive()); + followerLogInformation.isFollowerActive()); } // we cannot rely comfortably that the sleep will indeed sleep for the desired time // hence getting the actual elapsed time and do a match. // if the sleep has spilled over, then return the test gracefully - private long sleepWithElaspsedTimeReturned(long millis) { + private static long sleepWithElaspsedTimeReturned(long millis) { Stopwatch stopwatch = Stopwatch.createStarted(); Uninterruptibles.sleepUninterruptibly(millis, TimeUnit.MILLISECONDS); stopwatch.stop(); @@ -64,10 +64,9 @@ public class FollowerLogInformationImplTest { @Test public void testOkToReplicate(){ MockRaftActorContext context = new MockRaftActorContext(); - context.setCommitIndex(9); + context.setCommitIndex(0); FollowerLogInformation followerLogInformation = - new FollowerLogInformationImpl( - "follower1", 10, context); + new FollowerLogInformationImpl(new PeerInfo("follower1", null, VotingState.VOTING), 10, context); assertTrue(followerLogInformation.okToReplicate()); assertFalse(followerLogInformation.okToReplicate()); @@ -80,4 +79,36 @@ public class FollowerLogInformationImplTest { 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()); + } }