Bug 6659: Fix intermittent PartitionedCandidateOnStartupElectionScenarioTest failure 53/45353/2
authorTom Pantelis <tpanteli@brocade.com>
Wed, 7 Sep 2016 20:42:51 +0000 (16:42 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Wed, 7 Sep 2016 22:34:04 +0000 (22:34 +0000)
The didn't setup the SimpleReplicatedLog, commitIndex, lastAppliedIndex correctly.

Change-Id: I76fbf98f1a227245ca3a61e399258bd3bd4e743a
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
(cherry picked from commit 369664974cc0ed545b86aa78c400bff743b7b178)

opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/PartitionedCandidateOnStartupElectionScenarioTest.java

index 082defd..65950a9 100644 (file)
@@ -165,10 +165,11 @@ 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(1, 1, new MockPayload("")));
-        candidateReplicatedLog.append(new MockReplicatedLogEntry(2, 1, new MockPayload("")));
+        candidateReplicatedLog.append(new MockReplicatedLogEntry(2, 0, new MockPayload("")));
 
         member3Context.setReplicatedLog(candidateReplicatedLog);
+        member3Context.setCommitIndex(candidateReplicatedLog.lastIndex());
+        member3Context.setLastApplied(candidateReplicatedLog.lastIndex());
         member3Context.getTermInformation().update(2, member1Context.getId());
 
         // The member 3 Candidate will start a new term and send RequestVotes. However it will be
@@ -210,6 +211,13 @@ public class PartitionedCandidateOnStartupElectionScenarioTest extends AbstractL
     private void setupInitialMember1AndMember2Behaviors() throws Exception {
         testLog.info("setupInitialMember1AndMember2Behaviors starting");
 
+        // Initialize the ReplicatedLog and election term info for member 1 and 2. The current term
+        // 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("")));
+
         // Create member 2's behavior as Follower.
 
         member2Context = newRaftActorContext("member2", member2ActorRef,
@@ -220,6 +228,11 @@ public class PartitionedCandidateOnStartupElectionScenarioTest extends AbstractL
         DefaultConfigParamsImpl member2ConfigParams = newConfigParams();
         member2Context.setConfigParams(member2ConfigParams);
 
+        member2Context.setReplicatedLog(replicatedLog);
+        member2Context.setCommitIndex(replicatedLog.lastIndex());
+        member2Context.setLastApplied(replicatedLog.lastIndex());
+        member2Context.getTermInformation().update(3, "member1");
+
         member2Actor.behavior = new Follower(member2Context);
         member2Context.setCurrentBehavior(member2Actor.behavior);
 
@@ -233,24 +246,16 @@ public class PartitionedCandidateOnStartupElectionScenarioTest extends AbstractL
         DefaultConfigParamsImpl member1ConfigParams = newConfigParams();
         member1Context.setConfigParams(member1ConfigParams);
 
+        member1Context.setReplicatedLog(replicatedLog);
+        member1Context.setCommitIndex(replicatedLog.lastIndex());
+        member1Context.setLastApplied(replicatedLog.lastIndex());
+        member1Context.getTermInformation().update(3, "member1");
+
         initializeLeaderBehavior(member1Actor, member1Context, 1);
 
         member2Actor.clear();
         member3Actor.clear();
 
-        // Initialize the ReplicatedLog and election term info for member 1 and 2. The current term
-        // will be 3 and the last term will be 2.
-
-        SimpleReplicatedLog replicatedLog = new SimpleReplicatedLog();
-        replicatedLog.append(new MockReplicatedLogEntry(2, 1, new MockPayload("")));
-        replicatedLog.append(new MockReplicatedLogEntry(3, 1, new MockPayload("")));
-
-        member1Context.setReplicatedLog(replicatedLog);
-        member1Context.getTermInformation().update(3, "");
-
-        member2Context.setReplicatedLog(replicatedLog);
-        member2Context.getTermInformation().update(3, member1Context.getId());
-
         testLog.info("setupInitialMember1AndMember2Behaviors ending");
 
     }