Fix timing issue in PartitionedCandidateOnStartupElection*Test
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / behaviors / PartitionedCandidateOnStartupElectionScenarioTest.java
index 9d58d03237c6f7b63bb1d32dc6e3008b84f8ecb7..3f5ca17d7abc17b27bd3288d0cf6d5c9b1819b1f 100644 (file)
@@ -14,13 +14,13 @@ import com.google.common.collect.ImmutableMap;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl;
 import org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload;
-import org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockReplicatedLogEntry;
 import org.opendaylight.controller.cluster.raft.MockRaftActorContext.SimpleReplicatedLog;
 import org.opendaylight.controller.cluster.raft.RaftState;
 import org.opendaylight.controller.cluster.raft.base.messages.ElectionTimeout;
 import org.opendaylight.controller.cluster.raft.base.messages.TimeoutNow;
 import org.opendaylight.controller.cluster.raft.messages.RequestVote;
 import org.opendaylight.controller.cluster.raft.messages.RequestVoteReply;
+import org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry;
 
 /**
  * A leader election scenario test that partitions a candidate when trying to join a cluster on startup.
@@ -166,7 +166,7 @@ public class PartitionedCandidateOnStartupElectionScenarioTest extends AbstractL
         // will be 2 and the last term will be 1 so it is behind the leader's log.
 
         SimpleReplicatedLog candidateReplicatedLog = new SimpleReplicatedLog();
-        candidateReplicatedLog.append(new MockReplicatedLogEntry(2, 0, new MockPayload("")));
+        candidateReplicatedLog.append(new SimpleReplicatedLogEntry(0, 2, new MockPayload("")));
 
         member3Context.setReplicatedLog(candidateReplicatedLog);
         member3Context.setCommitIndex(candidateReplicatedLog.lastIndex());
@@ -182,9 +182,8 @@ public class PartitionedCandidateOnStartupElectionScenarioTest extends AbstractL
 
         member2Actor.dropMessagesToBehavior(RequestVote.class, numCandidateElections);
 
-        Candidate member3Behavior = new Candidate(member3Context);
-        member3Actor.behavior = member3Behavior;
-        member3Context.setCurrentBehavior(member3Behavior);
+        member3Actor.self().tell(new SetBehavior(new Candidate(member3Context), member3Context),
+                ActorRef.noSender());
 
         // Send several additional ElectionTimeouts to Candidate member 3. Each ElectionTimeout will
         // start a new term so Candidate member 3's current term will be greater than the leader's
@@ -216,8 +215,8 @@ public class PartitionedCandidateOnStartupElectionScenarioTest extends AbstractL
         // will be 3 and the last term will be 2.
 
         SimpleReplicatedLog replicatedLog = new SimpleReplicatedLog();
-        replicatedLog.append(new MockReplicatedLogEntry(2, 0, new MockPayload("")));
-        replicatedLog.append(new MockReplicatedLogEntry(3, 1, new MockPayload("")));
+        replicatedLog.append(new SimpleReplicatedLogEntry(0, 2, new MockPayload("")));
+        replicatedLog.append(new SimpleReplicatedLogEntry(1, 3, new MockPayload("")));
 
         // Create member 2's behavior as Follower.
 
@@ -234,8 +233,8 @@ public class PartitionedCandidateOnStartupElectionScenarioTest extends AbstractL
         member2Context.setLastApplied(replicatedLog.lastIndex());
         member2Context.getTermInformation().update(3, "member1");
 
-        member2Actor.behavior = new Follower(member2Context);
-        member2Context.setCurrentBehavior(member2Actor.behavior);
+        member2Actor.self().tell(new SetBehavior(new Follower(member2Context), member2Context),
+                ActorRef.noSender());
 
         // Create member 1's behavior as Leader.