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 505f6d1da873687653f08acb6cb8cace1579c85e..63bf14922a1b1c10acab2f0f37543c004f52d99d 100644 (file)
@@ -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);
     }
@@ -763,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);
@@ -830,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));
 
@@ -840,7 +840,6 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest {
         // Send an append entry
         AppendEntries appendEntries = mock(AppendEntries.class);
         doReturn(context.getTermInformation().getCurrentTerm()).when(appendEntries).getTerm();
-        doReturn(null).when(appendEntries).getEntries();
 
         follower.handleMessage(leaderActor, appendEntries);
 
@@ -872,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);
@@ -986,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;
@@ -997,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,