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=d68339ee8664f445b02a54cc46fb705bb3bf559e;hb=35624f56612e0b8ca641c2fc5fed25f1c7628e51;hp=e2204a9d08f84933d5612059049c1a61b0b28253;hpb=3bc363a69d6d48709f7fd741ef018ecd75b8f99b;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 e2204a9d08..d68339ee86 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 @@ -7,13 +7,14 @@ */ package org.opendaylight.controller.cluster.raft; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; + import com.google.common.base.Stopwatch; import com.google.common.util.concurrent.Uninterruptibles; import java.util.concurrent.TimeUnit; import org.junit.Test; -import org.opendaylight.controller.cluster.raft.FollowerLogInformation.FollowerState; import scala.concurrent.duration.FiniteDuration; public class FollowerLogInformationImplTest { @@ -30,7 +31,7 @@ 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()); @@ -55,7 +56,7 @@ public class FollowerLogInformationImplTest { // 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(); @@ -63,11 +64,11 @@ public class FollowerLogInformationImplTest { } @Test - public void testOkToReplicate(){ + public void testOkToReplicate() { MockRaftActorContext context = new MockRaftActorContext(); + 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()); @@ -83,19 +84,18 @@ public class FollowerLogInformationImplTest { @Test public void testVotingNotInitializedState() { + final PeerInfo peerInfo = new PeerInfo("follower1", null, VotingState.VOTING_NOT_INITIALIZED); MockRaftActorContext context = new MockRaftActorContext(); - FollowerLogInformation followerLogInformation = new FollowerLogInformationImpl("follower1", -1, context); + context.setCommitIndex(0); + FollowerLogInformation followerLogInformation = new FollowerLogInformationImpl(peerInfo, -1, context); - followerLogInformation.setFollowerState(FollowerState.VOTING_NOT_INITIALIZED); assertFalse(followerLogInformation.okToReplicate()); - assertFalse(followerLogInformation.canParticipateInConsensus()); followerLogInformation.markFollowerActive(); assertFalse(followerLogInformation.isFollowerActive()); - followerLogInformation.setFollowerState(FollowerState.VOTING); + peerInfo.setVotingState(VotingState.VOTING); assertTrue(followerLogInformation.okToReplicate()); - assertTrue(followerLogInformation.canParticipateInConsensus()); followerLogInformation.markFollowerActive(); assertTrue(followerLogInformation.isFollowerActive()); @@ -103,14 +103,31 @@ public class FollowerLogInformationImplTest { @Test public void testNonVotingState() { + final PeerInfo peerInfo = new PeerInfo("follower1", null, VotingState.NON_VOTING); MockRaftActorContext context = new MockRaftActorContext(); - FollowerLogInformation followerLogInformation = new FollowerLogInformationImpl("follower1", -1, context); + context.setCommitIndex(0); + FollowerLogInformation followerLogInformation = new FollowerLogInformationImpl(peerInfo, -1, context); - followerLogInformation.setFollowerState(FollowerState.NON_VOTING); assertTrue(followerLogInformation.okToReplicate()); - assertFalse(followerLogInformation.canParticipateInConsensus()); followerLogInformation.markFollowerActive(); assertTrue(followerLogInformation.isFollowerActive()); } + + @Test + public void testDecrNextIndex() { + MockRaftActorContext context = new MockRaftActorContext(); + context.setCommitIndex(1); + FollowerLogInformation followerLogInformation = + new FollowerLogInformationImpl(new PeerInfo("follower1", null, VotingState.VOTING), 1, context); + + assertTrue(followerLogInformation.decrNextIndex()); + assertEquals("getNextIndex", 0, followerLogInformation.getNextIndex()); + + assertTrue(followerLogInformation.decrNextIndex()); + assertEquals("getNextIndex", -1, followerLogInformation.getNextIndex()); + + assertFalse(followerLogInformation.decrNextIndex()); + assertEquals("getNextIndex", -1, followerLogInformation.getNextIndex()); + } }