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 {
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());
}
@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());
@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());
@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());