Add mockito-configuration to tests 45/32045/11
authorRobert Varga <robert.varga@pantheon.sk>
Sat, 2 Jan 2016 23:38:29 +0000 (00:38 +0100)
committerRobert Varga <nite@hq.sk>
Wed, 13 Jan 2016 09:58:00 +0000 (09:58 +0000)
Ynagtools' mockito-configuration ensures that all methods touched in
mocked objects have to be mocked, preventing failures which are hard to
track down.

The reason for this is that by default unmocked methods do nothong and
return null -- injecting nulls into context which do not expect them.

Change-Id: If7b9afac01128be6f1b2a90b1e8c068cb4a39b65
Signed-off-by: Robert Varga <robert.varga@pantheon.sk>
13 files changed:
opendaylight/md-sal/sal-akka-raft/pom.xml
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/ElectionTermImplTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActor.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorDelegatingPersistentDataProviderTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorLeadershipTransferCohortTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorRecoverySupportTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorSnapshotMessageSupportTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/ReplicatedLogImplTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/SnapshotManagerTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/CandidateTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/FollowerTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java

index 64b1c79..e3ec32f 100644 (file)
       <artifactId>mockito-all</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>mockito-configuration</artifactId>
+      <scope>test</scope>
+    </dependency>
 
     <dependency>
       <groupId>org.slf4j</groupId>
index 9dd5e40..a7d2f48 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.controller.cluster.raft;
 
 import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.verify;
 import akka.japi.Procedure;
 import org.junit.Before;
@@ -15,6 +17,8 @@ import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.cluster.DataPersistenceProvider;
 import org.opendaylight.controller.cluster.raft.base.messages.UpdateElectionTerm;
 import org.slf4j.Logger;
@@ -31,9 +35,19 @@ public class ElectionTermImplTest {
     @Mock
     private DataPersistenceProvider mockPersistence;
 
+    @SuppressWarnings("unchecked")
     @Before
     public void setup() {
         MockitoAnnotations.initMocks(this);
+
+        doAnswer(new Answer<Void>() {
+            @Override
+            public Void answer(InvocationOnMock invocation) throws Exception {
+                final Object[] args = invocation.getArguments();
+                ((Procedure<Object>)args[1]).apply(args[0]);
+                return null;
+            }
+        }).when(mockPersistence).persist(any(Object.class), any(Procedure.class));
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
index c1a87e8..7411245 100644 (file)
@@ -9,6 +9,8 @@
 package org.opendaylight.controller.cluster.raft;
 
 import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.mock;
 import akka.actor.ActorRef;
 import akka.actor.Props;
@@ -49,8 +51,16 @@ public class MockRaftActor extends RaftActor implements RaftActorRecoveryCohort,
         super(builder.id, builder.peerAddresses, Optional.fromNullable(builder.config), PAYLOAD_VERSION);
         state = new ArrayList<>();
         this.actorDelegate = mock(RaftActor.class);
+        doNothing().when(this.actorDelegate).onRecoveryComplete();
+        doNothing().when(this.actorDelegate).onStateChanged();
+        doNothing().when(this.actorDelegate).applyState(any(ActorRef.class), any(String.class), any(Object.class));
+
         this.recoveryCohortDelegate = mock(RaftActorRecoveryCohort.class);
+        doNothing().when(this.recoveryCohortDelegate).applyRecoverySnapshot(any(byte[].class));
+
         this.snapshotCohortDelegate = mock(RaftActorSnapshotCohort.class);
+        doNothing().when(this.snapshotCohortDelegate).applySnapshot(any(byte[].class));
+        doNothing().when(this.snapshotCohortDelegate).createSnapshot(any(ActorRef.class));
 
         if(builder.dataPersistenceProvider == null){
             setPersistence(builder.persistent.isPresent() ? builder.persistent.get() : true);
index 378c53c..e833f43 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.controller.cluster.raft;
 
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
 import akka.japi.Procedure;
@@ -16,6 +19,8 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.cluster.DataPersistenceProvider;
 import org.opendaylight.controller.cluster.PersistentDataProvider;
 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
@@ -51,11 +56,24 @@ public class RaftActorDelegatingPersistentDataProviderTest {
 
     private RaftActorDelegatingPersistentDataProvider provider;
 
+    @SuppressWarnings("unchecked")
     @Before
-    public void setup() {
+    public void setup() throws Exception {
         MockitoAnnotations.initMocks(this);
         doReturn(PERSISTENT_PAYLOAD).when(mockPersistentLogEntry).getData();
         doReturn(NON_PERSISTENT_PAYLOAD).when(mockNonPersistentLogEntry).getData();
+
+        doAnswer(new Answer<Void>() {
+            @Override
+            public Void answer(InvocationOnMock invocation) throws Exception {
+                final Object[] args = invocation.getArguments();
+                ((Procedure<Object>)args[1]).apply(args[0]);
+                return null;
+            }
+        }).when(mockPersistentProvider).persist(any(Object.class), any(Procedure.class));
+
+        doNothing().when(mockDelegateProvider).persist(any(Object.class), any(Procedure.class));
+        doNothing().when(mockProcedure).apply(any(Object.class));
         provider = new RaftActorDelegatingPersistentDataProvider(mockDelegateProvider, mockPersistentProvider);
     }
 
index c7d9e3d..9037f68 100644 (file)
@@ -7,10 +7,13 @@
  */
 package org.opendaylight.controller.cluster.raft;
 
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
+import akka.actor.ActorRef;
 import akka.dispatch.Dispatchers;
 import com.google.common.base.Function;
 import org.junit.After;
@@ -36,6 +39,9 @@ public class RaftActorLeadershipTransferCohortTest extends AbstractActorTest {
     }
 
     private void setup() {
+        doNothing().when(onComplete).onSuccess(any(ActorRef.class), any(ActorRef.class));
+        doNothing().when(onComplete).onFailure(any(ActorRef.class), any(ActorRef.class));
+
         String persistenceId = factory.generateActorId("leader-");
         mockRaftActor = factory.<MockRaftActor>createTestActor(MockRaftActor.builder().id(persistenceId).config(
                 config).pauseLeaderFunction(pauseLeaderFunction).props().withDispatcher(Dispatchers.DefaultDispatcherId()),
index 71ca4ca..2c13031 100644 (file)
@@ -12,6 +12,7 @@ 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.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
@@ -77,13 +78,20 @@ public class RaftActorRecoverySupportTest {
     public void setup() {
         MockitoAnnotations.initMocks(this);
 
+        doNothing().when(mockCohort).startLogRecoveryBatch(any(int.class));
+        doNothing().when(mockCohort).applyCurrentLogRecoveryBatch();
+        doNothing().when(mockCohort).applyRecoverySnapshot(any(byte[].class));
+        doNothing().when(mockCohort).appendRecoveredLogEntry(any(Payload.class));
+        doReturn(null).when(mockCohort).getRestoreFromSnapshot();
+        doReturn(true).when(mockPersistence).isRecoveryApplicable();
+        doNothing().when(mockPersistence).deleteMessages(any(long.class));
+        doNothing().when(mockPersistentProvider).deleteMessages(any(long.class));
+        doNothing().when(mockPersistentProvider).deleteSnapshots(any(SnapshotSelectionCriteria.class));
+        doNothing().when(mockPersistentProvider).persist(any(Object.class), any(Procedure.class));
+
         context = new RaftActorContextImpl(null, null, localId, new ElectionTermImpl(mockPersistentProvider, "test", LOG),
                 -1, -1, Collections.<String,String>emptyMap(), configParams, mockPersistence, LOG);
-
         support = new RaftActorRecoverySupport(context, mockBehavior , mockCohort);
-
-        doReturn(true).when(mockPersistence).isRecoveryApplicable();
-
         context.setReplicatedLog(ReplicatedLogImpl.newInstance(context, mockBehavior));
     }
 
index 94000d0..d9dcd06 100644 (file)
@@ -11,9 +11,12 @@ import static org.junit.Assert.assertEquals;
 import static org.mockito.Matchers.anyLong;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Matchers.same;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
 import akka.actor.ActorRef;
+import akka.japi.Procedure;
 import akka.persistence.SaveSnapshotFailure;
 import akka.persistence.SaveSnapshotSuccess;
 import akka.persistence.SnapshotMetadata;
@@ -62,6 +65,13 @@ public class RaftActorSnapshotMessageSupportTest {
     public void setup() {
         MockitoAnnotations.initMocks(this);
 
+        doNothing().when(mockSnapshotManager).setApplySnapshotProcedure(any(Procedure.class));
+        doNothing().when(mockSnapshotManager).setCreateSnapshotCallable(any(Procedure.class));
+        doNothing().when(mockSnapshotManager).apply(any(ApplySnapshot.class));
+        doNothing().when(mockSnapshotManager).commit(any(long.class), any(RaftActorBehavior.class));
+        doNothing().when(mockSnapshotManager).persist(any(byte[].class), any(RaftActorBehavior.class), any(long.class));
+        doNothing().when(mockSnapshotManager).rollback();
+
         context = new RaftActorContextImpl(mockRaftActorRef, null, "test",
                 new ElectionTermImpl(mockPersistence, "test", LOG),
                 -1, -1, Collections.<String,String>emptyMap(), configParams, mockPersistence, LOG) {
index f4846d2..c47ca5c 100644 (file)
@@ -19,6 +19,7 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyObject;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Matchers.same;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
@@ -36,6 +37,7 @@ import akka.persistence.SaveSnapshotFailure;
 import akka.persistence.SaveSnapshotSuccess;
 import akka.persistence.SnapshotMetadata;
 import akka.persistence.SnapshotOffer;
+import akka.persistence.SnapshotSelectionCriteria;
 import akka.testkit.JavaTestKit;
 import akka.testkit.TestActorRef;
 import com.google.common.base.Optional;
@@ -102,6 +104,19 @@ public class RaftActorTest extends AbstractActorTest {
         factory = new TestActorFactory(getSystem());
     }
 
+    @SuppressWarnings("unchecked")
+    private static DataPersistenceProvider mockPersistenceProvider() {
+        final DataPersistenceProvider dataPersistenceProvider = mock(DataPersistenceProvider.class);
+        doReturn(false).when(dataPersistenceProvider).isRecoveryApplicable();
+        doReturn(0L).when(dataPersistenceProvider).getLastSequenceNumber();
+        doNothing().when(dataPersistenceProvider).saveSnapshot(any(Object.class));
+        doNothing().when(dataPersistenceProvider).persist(any(Object.class), any(Procedure.class));
+        doNothing().when(dataPersistenceProvider).deleteSnapshots(any(SnapshotSelectionCriteria.class));
+        doNothing().when(dataPersistenceProvider).deleteMessages(0L);
+
+        return dataPersistenceProvider;
+    }
+
     @After
     public void tearDown() throws Exception {
         factory.close();
@@ -295,7 +310,8 @@ public class RaftActorTest extends AbstractActorTest {
         mockRaftActor.waitForRecoveryComplete();
 
         RaftActorRecoverySupport mockSupport = mock(RaftActorRecoverySupport.class);
-        mockRaftActor.setRaftActorRecoverySupport(mockSupport );
+        doReturn(false).when(mockSupport).handleRecoveryMessage(any(Object.class), any(PersistentDataProvider.class));
+        mockRaftActor.setRaftActorRecoverySupport(mockSupport);
 
         Snapshot snapshot = Snapshot.create(new byte[]{1}, Collections.<ReplicatedLogEntry>emptyList(), 3, 1, 3, 1);
         SnapshotOffer snapshotOffer = new SnapshotOffer(new SnapshotMetadata("test", 6, 12345), snapshot);
@@ -400,7 +416,7 @@ public class RaftActorTest extends AbstractActorTest {
 
                 config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
 
-                DataPersistenceProvider dataPersistenceProvider = mock(DataPersistenceProvider.class);
+                DataPersistenceProvider dataPersistenceProvider = mockPersistenceProvider();
 
                 TestActorRef<MockRaftActor> mockActorRef = factory.createTestActor(MockRaftActor.props(persistenceId,
                         Collections.<String, String>emptyMap(), config, dataPersistenceProvider), persistenceId);
@@ -431,7 +447,7 @@ public class RaftActorTest extends AbstractActorTest {
 
                 config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
 
-                DataPersistenceProvider dataPersistenceProvider = mock(DataPersistenceProvider.class);
+                DataPersistenceProvider dataPersistenceProvider = mockPersistenceProvider();
 
                 TestActorRef<MockRaftActor> mockActorRef = factory.createTestActor(MockRaftActor.props(persistenceId,
                         Collections.<String, String>emptyMap(), config, dataPersistenceProvider), persistenceId);
@@ -599,7 +615,7 @@ public class RaftActorTest extends AbstractActorTest {
                 config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
                 config.setIsolatedLeaderCheckInterval(new FiniteDuration(1, TimeUnit.DAYS));
 
-                DataPersistenceProvider dataPersistenceProvider = mock(DataPersistenceProvider.class);
+                DataPersistenceProvider dataPersistenceProvider = mockPersistenceProvider();
 
                 Map<String, String> peerAddresses = new HashMap<>();
                 peerAddresses.put(follower1Id, followerActor1.path().toString());
@@ -696,7 +712,7 @@ public class RaftActorTest extends AbstractActorTest {
                 config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
                 config.setIsolatedLeaderCheckInterval(new FiniteDuration(1, TimeUnit.DAYS));
 
-                DataPersistenceProvider dataPersistenceProvider = mock(DataPersistenceProvider.class);
+                DataPersistenceProvider dataPersistenceProvider = mockPersistenceProvider();
 
                 Map<String, String> peerAddresses = new HashMap<>();
                 peerAddresses.put(leaderId, leaderActor1.path().toString());
@@ -803,7 +819,7 @@ public class RaftActorTest extends AbstractActorTest {
                 config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
                 config.setIsolatedLeaderCheckInterval(new FiniteDuration(1, TimeUnit.DAYS));
 
-                DataPersistenceProvider dataPersistenceProvider = mock(DataPersistenceProvider.class);
+                DataPersistenceProvider dataPersistenceProvider = mockPersistenceProvider();
 
                 Map<String, String> peerAddresses = new HashMap<>();
                 peerAddresses.put(follower1Id, followerActor1.path().toString());
@@ -1063,7 +1079,7 @@ public class RaftActorTest extends AbstractActorTest {
         String persistenceId = factory.generateActorId("follower-");
         ImmutableMap<String, String> peerAddresses =
             ImmutableMap.<String, String>builder().put("member1", "address").build();
-        DataPersistenceProvider dataPersistenceProvider = mock(DataPersistenceProvider.class);
+        DataPersistenceProvider dataPersistenceProvider = mockPersistenceProvider();
 
         TestActorRef<MockRaftActor> actorRef = factory.createTestActor(
                 MockRaftActor.props(persistenceId, peerAddresses, emptyConfig, dataPersistenceProvider), persistenceId);
@@ -1137,6 +1153,7 @@ public class RaftActorTest extends AbstractActorTest {
         verify(mockRaftActor.snapshotCohortDelegate, timeout(5000)).createSnapshot(any(ActorRef.class));
 
         mockRaftActor.snapshotCohortDelegate = mock(RaftActorSnapshotCohort.class);
+        doNothing().when(mockRaftActor.snapshotCohortDelegate).createSnapshot(any(ActorRef.class));
 
         raftActorRef.tell(GetSnapshot.INSTANCE, kit.getRef());
 
@@ -1164,6 +1181,7 @@ public class RaftActorTest extends AbstractActorTest {
 
         mockRaftActor.getSnapshotMessageSupport().setSnapshotReplyActorTimeout(Duration.create(200, TimeUnit.MILLISECONDS));
         reset(mockRaftActor.snapshotCohortDelegate);
+        doNothing().when(mockRaftActor.snapshotCohortDelegate).createSnapshot(any(ActorRef.class));
 
         raftActorRef.tell(GetSnapshot.INSTANCE, kit.getRef());
         Failure failure = kit.expectMsgClass(akka.actor.Status.Failure.class);
@@ -1175,6 +1193,7 @@ public class RaftActorTest extends AbstractActorTest {
 
         mockRaftActor.setPersistence(false);
         reset(mockRaftActor.snapshotCohortDelegate);
+        doNothing().when(mockRaftActor.snapshotCohortDelegate).createSnapshot(any(ActorRef.class));
 
         raftActorRef.tell(GetSnapshot.INSTANCE, kit.getRef());
         reply = kit.expectMsgClass(GetSnapshotReply.class);
index 51cff35..cc81e71 100644 (file)
@@ -8,7 +8,9 @@
 package org.opendaylight.controller.cluster.raft;
 
 import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.same;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.verify;
@@ -56,6 +58,8 @@ public class ReplicatedLogImplTest {
     public void setup() {
         MockitoAnnotations.initMocks(this);
 
+        doNothing().when(mockPersistence).persist(any(Object.class), any(Procedure.class));
+
         context = new RaftActorContextImpl(null, null, "test",
                 new ElectionTermImpl(mockPersistence, "test", LOG),
                 -1, -1, Collections.<String,String>emptyMap(), configParams, mockPersistence, LOG);
@@ -88,7 +92,10 @@ public class ReplicatedLogImplTest {
 
         reset(mockPersistence);
 
+        doNothing().when(mockPersistence).persist(any(MockReplicatedLogEntry.class), any(Procedure.class));
+
         Procedure<ReplicatedLogEntry> mockCallback = Mockito.mock(Procedure.class);
+        doNothing().when(mockCallback).apply(logEntry);
         log.appendAndPersist(logEntry, mockCallback);
 
         verifyPersist(logEntry);
@@ -114,6 +121,8 @@ public class ReplicatedLogImplTest {
 
         reset(mockPersistence);
 
+        doNothing().when(mockPersistence).persist(any(MockReplicatedLogEntry.class), any(Procedure.class));
+
         log.appendAndPersist(logEntry2);
         verifyPersist(logEntry2);
 
@@ -142,6 +151,8 @@ public class ReplicatedLogImplTest {
 
         reset(mockPersistence);
 
+        doNothing().when(mockPersistence).persist(any(MockReplicatedLogEntry.class), any(Procedure.class));
+
         logEntry = new MockReplicatedLogEntry(1, 3, new MockPayload("3", 5));
 
         log.appendAndPersist(logEntry);
index 27596df..6b0cd3a 100644 (file)
@@ -14,6 +14,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyLong;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
@@ -71,7 +72,7 @@ public class SnapshotManagerTest extends AbstractActorTest {
     private TestActorRef<MessageCollectorActor> actorRef;
 
     @Before
-    public void setUp(){
+    public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
 
         doReturn(false).when(mockRaftActorContext).hasFollowers();
@@ -82,6 +83,8 @@ public class SnapshotManagerTest extends AbstractActorTest {
         doReturn("123").when(mockRaftActorContext).getId();
         doReturn(mockDataPersistenceProvider).when(mockRaftActorContext).getPersistenceProvider();
         doReturn("123").when(mockRaftActorBehavior).getLeaderId();
+        doReturn(null).when(mockRaftActorBehavior).handleMessage(any(ActorRef.class), any(Object.class));
+        doReturn(0L).when(mockRaftActorBehavior).getReplicatedToAllIndex();
 
         doReturn(mockElectionTerm).when(mockRaftActorContext).getTermInformation();
         doReturn(5L).when(mockElectionTerm).getCurrentTerm();
@@ -92,6 +95,26 @@ public class SnapshotManagerTest extends AbstractActorTest {
 
         actorRef = factory.createTestActor(MessageCollectorActor.props(), factory.generateActorId("test-"));
         doReturn(actorRef).when(mockRaftActorContext).getActor();
+        doReturn(0L).when(mockRaftActorContext).getLastApplied();
+        doReturn(null).when(mockRaftActorContext).getPeerServerInfo(any(boolean.class));
+        doReturn(null).when(mockReplicatedLog).get(any(long.class));
+        doReturn(null).when(mockReplicatedLog).getFrom(any(long.class));
+        doReturn(0).when(mockReplicatedLog).dataSize();
+        doReturn(0L).when(mockReplicatedLog).size();
+        doReturn(0L).when(mockReplicatedLog).getSnapshotIndex();
+        doReturn(0L).when(mockReplicatedLog).getSnapshotTerm();
+        doNothing().when(mockReplicatedLog).snapshotPreCommit(any(long.class), any(long.class));
+        doNothing().when(mockReplicatedLog).snapshotRollback();
+        doNothing().when(mockReplicatedLog).snapshotCommit();
+        doNothing().when(mockRaftActorBehavior).setReplicatedToAllIndex(any(long.class));
+
+        doReturn(0L).when(mockDataPersistenceProvider).getLastSequenceNumber();
+        doNothing().when(mockDataPersistenceProvider).saveSnapshot(any(Object.class));
+        doNothing().when(mockDataPersistenceProvider).persist(any(Object.class), any(Procedure.class));
+        doNothing().when(mockDataPersistenceProvider).deleteSnapshots(any(SnapshotSelectionCriteria.class));
+        doNothing().when(mockDataPersistenceProvider).deleteMessages(any(long.class));
+
+        doNothing().when(mockProcedure).apply(null);
 
         snapshotManager.setCreateSnapshotCallable(mockProcedure);
     }
index 8dd81da..c251279 100644 (file)
@@ -157,6 +157,8 @@ public class CandidateTest extends AbstractRaftActorBehaviorTest {
     public void testBecomeLeaderOnReceivingMajorityVotesWithNonVotingPeers(){
         ElectionTerm mockElectionTerm = Mockito.mock(ElectionTerm.class);
         Mockito.doReturn(1L).when(mockElectionTerm).getCurrentTerm();
+        Mockito.doNothing().when(mockElectionTerm).updateAndPersist(Mockito.any(long.class), Mockito.any(String.class));
+
         RaftActorContext raftActorContext = new RaftActorContextImpl(candidateActor, candidateActor.actorContext(),
                 "candidate", mockElectionTerm, -1, -1, setupPeers(4), new DefaultConfigParamsImpl(),
                 new NonPersistentDataProvider(), LOG);
@@ -314,6 +316,7 @@ public class CandidateTest extends AbstractRaftActorBehaviorTest {
 
         // Send an unknown message so that the state of the RaftActor remains unchanged
         RaftActorBehavior expected = behavior.handleMessage(candidateActor, "unknown");
+        assertTrue(expected instanceof Candidate);
 
         RaftActorBehavior raftBehavior = behavior.handleMessage(candidateActor, appendEntries);
 
@@ -333,6 +336,7 @@ public class CandidateTest extends AbstractRaftActorBehaviorTest {
         return new MockRaftActorContext("candidate", getSystem(), candidateActor);
     }
 
+    @SuppressWarnings("unchecked")
     private Map<String, String> setupPeers(int count) {
         Map<String, String> peerMap = new HashMap<>();
         peerActors = new TestActorRef[count];
index 1b15ecb..505f6d1 100644 (file)
@@ -840,6 +840,7 @@ 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);
 
@@ -967,6 +968,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;
index b51f0a7..21aa900 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.controller.cluster.raft.behaviors;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
@@ -1972,6 +1973,7 @@ public class LeaderTest extends AbstractLeaderTest {
         MessageCollectorActor.clearMessages(followerActor);
 
         RaftActorLeadershipTransferCohort mockTransferCohort = mock(RaftActorLeadershipTransferCohort.class);
+        doNothing().when(mockTransferCohort).transferComplete();
         leader.transferLeadership(mockTransferCohort);
 
         verify(mockTransferCohort, never()).transferComplete();
@@ -2004,6 +2006,7 @@ public class LeaderTest extends AbstractLeaderTest {
         MessageCollectorActor.clearMessages(followerActor);
 
         RaftActorLeadershipTransferCohort mockTransferCohort = mock(RaftActorLeadershipTransferCohort.class);
+        doNothing().when(mockTransferCohort).transferComplete();
         leader.transferLeadership(mockTransferCohort);
 
         verify(mockTransferCohort, never()).transferComplete();
@@ -2034,6 +2037,7 @@ public class LeaderTest extends AbstractLeaderTest {
         MessageCollectorActor.clearMessages(followerActor);
 
         RaftActorLeadershipTransferCohort mockTransferCohort = mock(RaftActorLeadershipTransferCohort.class);
+        doNothing().when(mockTransferCohort).transferComplete();
         leader.transferLeadership(mockTransferCohort);
 
         verify(mockTransferCohort, never()).transferComplete();
@@ -2078,6 +2082,7 @@ public class LeaderTest extends AbstractLeaderTest {
         MessageCollectorActor.clearMessages(followerActor);
 
         RaftActorLeadershipTransferCohort mockTransferCohort = mock(RaftActorLeadershipTransferCohort.class);
+        doNothing().when(mockTransferCohort).abortTransfer();
         leader.transferLeadership(mockTransferCohort);
 
         verify(mockTransferCohort, never()).transferComplete();

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.