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=b89f28f40166c113243972267e51e5b1ba595577;hpb=9491b06df9419e58db3089a4c5cd9f5407cb9aac;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 b89f28f401..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,8 +7,10 @@ */ 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; @@ -62,8 +64,9 @@ public class FollowerLogInformationImplTest { } @Test - public void testOkToReplicate(){ + public void testOkToReplicate() { MockRaftActorContext context = new MockRaftActorContext(); + context.setCommitIndex(0); FollowerLogInformation followerLogInformation = new FollowerLogInformationImpl(new PeerInfo("follower1", null, VotingState.VOTING), 10, context); @@ -83,6 +86,7 @@ public class FollowerLogInformationImplTest { 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()); @@ -101,6 +105,7 @@ public class FollowerLogInformationImplTest { 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()); @@ -108,4 +113,21 @@ public class FollowerLogInformationImplTest { 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()); + } }