Fix unit test errors due to Mockito upgrade
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / behaviors / FollowerTest.java
index f189e2d2ee6d140cbc738940540fb66adde82656..63bf14922a1b1c10acab2f0f37543c004f52d99d 100644 (file)
@@ -87,7 +87,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest {
         return context;
     }
 
-    private int getElectionTimeoutCount(RaftActorBehavior follower){
+    private static int getElectionTimeoutCount(RaftActorBehavior follower){
         if(follower instanceof TestFollower){
             return ((TestFollower) follower).getElectionTimeoutCount();
         }
@@ -109,7 +109,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest {
 
         follower = new Follower(createActorContext());
 
-        RaftActorBehavior raftBehavior = follower.handleMessage(followerActor, new ElectionTimeout());
+        RaftActorBehavior raftBehavior = follower.handleMessage(followerActor, ElectionTimeout.INSTANCE);
 
         assertTrue(raftBehavior instanceof Candidate);
     }
@@ -749,6 +749,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest {
         logStart("testHandleInstallSnapshot");
 
         MockRaftActorContext context = createActorContext();
+        context.getTermInformation().update(1, "leader");
 
         follower = createBehavior(context);
 
@@ -762,7 +763,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest {
         InstallSnapshot lastInstallSnapshot = null;
 
         for(int i = 0; i < totalChunks; i++) {
-            ByteString chunkData = getNextChunk(bsSnapshot, offset, chunkSize);
+            byte[] chunkData = getNextChunk(bsSnapshot, offset, chunkSize);
             lastInstallSnapshot = new InstallSnapshot(1, "leader", lastIncludedIndex, 1,
                     chunkData, chunkIndex, totalChunks);
             follower.handleMessage(leaderActor, lastInstallSnapshot);
@@ -782,6 +783,9 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest {
                 snapshot.getLastAppliedIndex());
         assertEquals("getLastTerm", lastInstallSnapshot.getLastIncludedTerm(), snapshot.getLastTerm());
         Assert.assertArrayEquals("getState", bsSnapshot.toByteArray(), snapshot.getState());
+        assertEquals("getElectionTerm", 1, snapshot.getElectionTerm());
+        assertEquals("getElectionVotedFor", "leader", snapshot.getElectionVotedFor());
+        applySnapshot.getCallback().onSuccess();
 
         List<InstallSnapshotReply> replies = MessageCollectorActor.getAllMatching(
                 leaderActor, InstallSnapshotReply.class);
@@ -826,7 +830,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest {
         assertTrue(totalChunks > 1);
 
         // Send an install snapshot with the first chunk to start the process of installing a snapshot
-        ByteString chunkData = getNextChunk(bsSnapshot, 0, chunkSize);
+        byte[] chunkData = getNextChunk(bsSnapshot, 0, chunkSize);
         follower.handleMessage(leaderActor, new InstallSnapshot(1, "leader", lastIncludedIndex, 1,
                 chunkData, 1, totalChunks));
 
@@ -867,7 +871,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest {
         InstallSnapshot lastInstallSnapshot = null;
 
         for(int i = 0; i < totalChunks; i++) {
-            ByteString chunkData = getNextChunk(bsSnapshot, offset, chunkSize);
+            byte[] chunkData = getNextChunk(bsSnapshot, offset, chunkSize);
             lastInstallSnapshot = new InstallSnapshot(1, "leader", lastIncludedIndex, 1,
                     chunkData, chunkIndex, totalChunks);
             follower.handleMessage(leaderActor, lastInstallSnapshot);
@@ -963,6 +967,8 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest {
         MockRaftActorContext context = createActorContext();
         follower = createBehavior(context);
         follower.handleMessage(leaderActor, new RaftRPC() {
+            private static final long serialVersionUID = 1L;
+
             @Override
             public long getTerm() {
                 return 100;
@@ -979,7 +985,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest {
         assertEquals("schedule election", 0, getElectionTimeoutCount(follower));
     }
 
-    public ByteString getNextChunk (ByteString bs, int offset, int chunkSize){
+    public byte[] getNextChunk (ByteString bs, int offset, int chunkSize){
         int snapshotLength = bs.size();
         int start = offset;
         int size = chunkSize;
@@ -990,7 +996,10 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest {
                 size = snapshotLength - start;
             }
         }
-        return bs.substring(start, start + size);
+
+        byte[] nextChunk = new byte[size];
+        bs.copyTo(nextChunk, start, 0, size);
+        return nextChunk;
     }
 
     private void expectAndVerifyAppendEntriesReply(int expTerm, boolean expSuccess,
@@ -1015,7 +1024,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest {
     }
 
 
-    private ReplicatedLogEntry newReplicatedLogEntry(long term, long index, String data) {
+    private static ReplicatedLogEntry newReplicatedLogEntry(long term, long index, String data) {
         return new MockRaftActorContext.MockReplicatedLogEntry(term, index,
                 new MockRaftActorContext.MockPayload(data));
     }