Fix unit test errors due to Mockito upgrade
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / RaftActorRecoverySupportTest.java
index da02e81fa82b3cd67c39785fe5669ca6d7a054c0..71ca4cae5df490d6d6d5faa00954b167dc614fb9 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.controller.cluster.raft;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Mockito.doReturn;
@@ -213,6 +215,7 @@ public class RaftActorRecoverySupportTest {
         assertEquals("Snapshot index", lastAppliedDuringSnapshotCapture, context.getReplicatedLog().getSnapshotIndex());
         assertEquals("Election term", electionTerm, context.getTermInformation().getCurrentTerm());
         assertEquals("Election votedFor", electionVotedFor, context.getTermInformation().getVotedFor());
+        assertFalse("Dynamic server configuration", context.isDynamicServerConfigurationInUse());
 
         verify(mockCohort).applyRecoverySnapshot(snapshotBytes);
     }
@@ -240,7 +243,7 @@ public class RaftActorRecoverySupportTest {
         }
 
         inOrder.verify(mockCohort).applyCurrentLogRecoveryBatch();
-
+        inOrder.verify(mockCohort).getRestoreFromSnapshot();
         inOrder.verifyNoMoreInteractions();
     }
 
@@ -248,6 +251,7 @@ public class RaftActorRecoverySupportTest {
     public void testOnRecoveryCompletedWithNoRemainingBatch() {
         sendMessageToSupport(RecoveryCompleted.getInstance(), true);
 
+        verify(mockCohort).getRestoreFromSnapshot();
         verifyNoMoreInteractions(mockCohort);
     }
 
@@ -337,6 +341,7 @@ public class RaftActorRecoverySupportTest {
 
         sendMessageToSupport(RecoveryCompleted.getInstance(), true);
 
+        verify(mockCohort).getRestoreFromSnapshot();
         verifyNoMoreInteractions(mockCohort);
 
         verify(mockPersistentProvider).deleteMessages(10L);
@@ -370,6 +375,7 @@ public class RaftActorRecoverySupportTest {
 
         sendMessageToSupport(RecoveryCompleted.getInstance(), true);
 
+        verify(mockCohort).getRestoreFromSnapshot();
         verifyNoMoreInteractions(mockCohort, mockPersistentProvider);
     }
 
@@ -392,6 +398,7 @@ public class RaftActorRecoverySupportTest {
         sendMessageToSupport(new MockRaftActorContext.MockReplicatedLogEntry(1, 0, obj));
 
         //verify new peers
+        assertTrue("Dynamic server configuration", context.isDynamicServerConfigurationInUse());
         assertEquals("New peer Ids", Sets.newHashSet(follower1, follower2, follower3),
                 Sets.newHashSet(context.getPeerIds()));
         assertEquals("follower1 isVoting", true, context.getPeerInfo(follower1).isVoting());
@@ -412,6 +419,7 @@ public class RaftActorRecoverySupportTest {
         sendMessageToSupport(new MockRaftActorContext.MockReplicatedLogEntry(1, 1, obj));
 
         //verify new peers
+        assertTrue("Dynamic server configuration", context.isDynamicServerConfigurationInUse());
         assertEquals("New peer Ids", Sets.newHashSet(follower2, follower3), Sets.newHashSet(context.getPeerIds()));
     }
 
@@ -428,4 +436,29 @@ public class RaftActorRecoverySupportTest {
         //verify new peers
         assertEquals("New peer Ids", Sets.newHashSet(follower), Sets.newHashSet(context.getPeerIds()));
     }
+
+    @Test
+    public void testOnSnapshotOfferWithServerConfiguration() {
+        long electionTerm = 2;
+        String electionVotedFor = "member-2";
+        ServerConfigurationPayload serverPayload = new ServerConfigurationPayload(Arrays.asList(
+                                                        new ServerInfo(localId, true),
+                                                        new ServerInfo("follower1", true),
+                                                        new ServerInfo("follower2", true)));
+
+        Snapshot snapshot = Snapshot.create(new byte[]{1}, Collections.<ReplicatedLogEntry>emptyList(),
+                -1, -1, -1, -1, electionTerm, electionVotedFor, serverPayload);
+
+        SnapshotMetadata metadata = new SnapshotMetadata("test", 6, 12345);
+        SnapshotOffer snapshotOffer = new SnapshotOffer(metadata , snapshot);
+
+        sendMessageToSupport(snapshotOffer);
+
+        assertEquals("Journal log size", 0, context.getReplicatedLog().size());
+        assertEquals("Election term", electionTerm, context.getTermInformation().getCurrentTerm());
+        assertEquals("Election votedFor", electionVotedFor, context.getTermInformation().getVotedFor());
+        assertTrue("Dynamic server configuration", context.isDynamicServerConfigurationInUse());
+        assertEquals("Peer List", Sets.newHashSet("follower1", "follower2"),
+            Sets.newHashSet(context.getPeerIds()));
+    }
 }