Bug 3570: Persist snapshot on follower ApplySnapshot
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / RaftActorTest.java
index 45c2e0d0adf6094a1e9800cf78a05d20653968c5..eb70c8b028e16258c392e79a3394d040f9c7c291 100644 (file)
@@ -418,15 +418,18 @@ public class RaftActorTest extends AbstractActorTest {
                     notifierActor, LeaderStateChanged.class);
 
             assertEquals(raftRoleChanged.getMemberId(), leaderStateChange.getLeaderId());
+            assertEquals(MockRaftActor.PAYLOAD_VERSION, leaderStateChange.getLeaderPayloadVersion());
 
             notifierActor.underlyingActor().clear();
 
             MockRaftActor raftActor = raftActorRef.underlyingActor();
             final String newLeaderId = "new-leader";
+            final short newLeaderVersion = 6;
             Follower follower = new Follower(raftActor.getRaftActorContext()) {
                 @Override
                 public RaftActorBehavior handleMessage(ActorRef sender, Object message) {
                     leaderId = newLeaderId;
+                    setLeaderPayloadVersion(newLeaderVersion);
                     return this;
                 }
             };
@@ -448,6 +451,15 @@ public class RaftActorTest extends AbstractActorTest {
             leaderStateChange = MessageCollectorActor.expectFirstMatching(notifierActor, LeaderStateChanged.class);
             assertEquals(persistenceId, leaderStateChange.getMemberId());
             assertEquals(newLeaderId, leaderStateChange.getLeaderId());
+            assertEquals(newLeaderVersion, leaderStateChange.getLeaderPayloadVersion());
+
+            notifierActor.underlyingActor().clear();
+
+            raftActor.handleCommand("any");
+
+            Uninterruptibles.sleepUninterruptibly(505, TimeUnit.MILLISECONDS);
+            leaderStateChange = MessageCollectorActor.getFirstMatching(notifierActor, LeaderStateChanged.class);
+            assertNull(leaderStateChange);
         }};
     }
 
@@ -573,7 +585,7 @@ public class RaftActorTest extends AbstractActorTest {
                 assertFalse(leaderActor.getRaftActorContext().getSnapshotManager().isCapturing());
 
                 // The commit is needed to complete the snapshot creation process
-                leaderActor.getRaftActorContext().getSnapshotManager().commit(-1);
+                leaderActor.getRaftActorContext().getSnapshotManager().commit(-1, leader);
 
                 // capture snapshot reply should remove the snapshotted entries only
                 assertEquals(3, leaderActor.getReplicatedLog().size());
@@ -677,7 +689,7 @@ public class RaftActorTest extends AbstractActorTest {
                 assertFalse(followerActor.getRaftActorContext().getSnapshotManager().isCapturing());
 
                 // The commit is needed to complete the snapshot creation process
-                followerActor.getRaftActorContext().getSnapshotManager().commit(-1);
+                followerActor.getRaftActorContext().getSnapshotManager().commit(-1, follower);
 
                 // capture snapshot reply should remove the snapshotted entries only till replicatedToAllIndex
                 assertEquals(3, followerActor.getReplicatedLog().size()); //indexes 5,6,7 left in the log