Fix unit test errors due to Mockito upgrade 11/35211/2
authorTom Pantelis <tpanteli@brocade.com>
Mon, 22 Feb 2016 05:08:52 +0000 (00:08 -0500)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 22 Feb 2016 18:56:48 +0000 (18:56 +0000)
The Mockito version was recently upgraded which causes some unit tests
to fail. Mockito no longer support never() used with timeout() so
workaround that.

Change-Id: I861e3ea198a630347b8de4c915d49b2718cc3d2c
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
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/behaviors/AbstractLeaderElectionScenarioTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipIntegrationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipListenerSupportTest.java

index 787faaf..624369b 100644 (file)
@@ -1295,7 +1295,8 @@ public class RaftActorTest extends AbstractActorTest {
 
         mockRaftActor.waitForRecoveryComplete();
 
-        verify(mockRaftActor.snapshotCohortDelegate, timeout(500).never()).applySnapshot(any(byte[].class));
+        Uninterruptibles.sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
+        verify(mockRaftActor.snapshotCohortDelegate, never()).applySnapshot(any(byte[].class));
 
         RaftActorContext context = mockRaftActor.getRaftActorContext();
         assertEquals("Journal log size", 1, context.getReplicatedLog().size());
index 950180c..63d9643 100644 (file)
@@ -27,6 +27,7 @@ import org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl;
 import org.opendaylight.controller.cluster.raft.MockRaftActorContext;
 import org.opendaylight.controller.cluster.raft.RaftActorContext;
 import org.opendaylight.controller.cluster.raft.RaftState;
+import org.opendaylight.controller.cluster.raft.TestActorFactory;
 import org.opendaylight.controller.cluster.raft.base.messages.SendHeartBeat;
 import org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply;
 import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor;
@@ -140,6 +141,7 @@ public class AbstractLeaderElectionScenarioTest {
 
     protected final Logger testLog = LoggerFactory.getLogger(MockRaftActorContext.class);
     protected final ActorSystem system = ActorSystem.create("test");
+    protected final TestActorFactory factory = new TestActorFactory(system);
     protected TestActorRef<MemberActor> member1ActorRef;
     protected TestActorRef<MemberActor> member2ActorRef;
     protected TestActorRef<MemberActor> member3ActorRef;
@@ -214,7 +216,8 @@ public class AbstractLeaderElectionScenarioTest {
     }
 
     TestActorRef<MemberActor> newMemberActor(String name) throws Exception {
-        TestActorRef<MemberActor> actor = TestActorRef.create(system, MemberActor.props(), name);
+        TestActorRef<MemberActor> actor = factory.createTestActor(MemberActor.props().
+                withDispatcher(Dispatchers.DefaultDispatcherId()), name);
         MessageCollectorActor.waitUntilReady(actor);
         return actor;
     }
index 744ad22..8567512 100644 (file)
@@ -13,6 +13,7 @@ import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.AdditionalMatchers.or;
 import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
@@ -174,7 +175,8 @@ public class DistributedEntityOwnershipIntegrationTest {
 
         leaderEntityOwnershipService.registerCandidate(ENTITY1_2);
         verify(leaderMockListener2, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1_2, false, true, true));
-        verify(leaderMockListener, timeout(300).never()).ownershipChanged(ownershipChange(ENTITY1_2));
+        Uninterruptibles.sleepUninterruptibly(300, TimeUnit.MILLISECONDS);
+        verify(leaderMockListener, never()).ownershipChanged(ownershipChange(ENTITY1_2));
         reset(leaderMockListener2);
 
         // Register follower1 candidate for entity1 and verify it gets added but doesn't become owner
@@ -182,8 +184,9 @@ public class DistributedEntityOwnershipIntegrationTest {
         follower1EntityOwnershipService.registerCandidate(ENTITY1);
         verifyCandidates(leaderDistributedDataStore, ENTITY1, "member-1", "member-2");
         verifyOwner(leaderDistributedDataStore, ENTITY1, "member-1");
-        verify(leaderMockListener, timeout(300).never()).ownershipChanged(ownershipChange(ENTITY1));
-        verify(follower1MockListener, timeout(300).never()).ownershipChanged(ownershipChange(ENTITY1));
+        Uninterruptibles.sleepUninterruptibly(300, TimeUnit.MILLISECONDS);
+        verify(leaderMockListener, never()).ownershipChanged(ownershipChange(ENTITY1));
+        verify(follower1MockListener, never()).ownershipChanged(ownershipChange(ENTITY1));
 
         // Register follower1 candidate for entity2 and verify it becomes owner
 
@@ -452,7 +455,8 @@ public class DistributedEntityOwnershipIntegrationTest {
 
         // Register a candidate for follower1 - should get queued since follower1 has no leader
         EntityOwnershipCandidateRegistration candidateReg = follower1EntityOwnershipService.registerCandidate(ENTITY1);
-        verify(leaderMockListener, timeout(300).never()).ownershipChanged(ownershipChange(ENTITY1));
+        Uninterruptibles.sleepUninterruptibly(300, TimeUnit.MILLISECONDS);
+        verify(leaderMockListener, never()).ownershipChanged(ownershipChange(ENTITY1));
 
         // Add replica in follower1
         AddShardReplica addReplica = new AddShardReplica(ENTITY_OWNERSHIP_SHARD_NAME);
index 9e41757..27fe827 100644 (file)
@@ -19,8 +19,10 @@ import akka.actor.ActorRef;
 import akka.actor.Props;
 import akka.testkit.JavaTestKit;
 import akka.testkit.TestActorRef;
+import com.google.common.util.concurrent.Uninterruptibles;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -82,7 +84,8 @@ public class EntityOwnershipListenerSupportTest extends AbstractEntityOwnershipT
 
         verify(mockListener1, timeout(5000)).ownershipChanged(ownershipChange(entity1, false, true, true));
         verify(mockListener1_2, timeout(5000)).ownershipChanged(ownershipChange(entity1, false, true, true));
-        verify(mockListener2, timeout(300).never()).ownershipChanged(any(EntityOwnershipChange.class));
+        Uninterruptibles.sleepUninterruptibly(300, TimeUnit.MILLISECONDS);
+        verify(mockListener2, never()).ownershipChanged(any(EntityOwnershipChange.class));
         assertEquals("# of listener actors", 2, actorContext.children().size());
         reset(mockListener1, mockListener2, mockListener1_2);
 
@@ -91,7 +94,8 @@ public class EntityOwnershipListenerSupportTest extends AbstractEntityOwnershipT
         support.notifyEntityOwnershipListeners(entity2, false, true, true);
 
         verify(mockListener2, timeout(5000)).ownershipChanged(ownershipChange(entity2, false, true, true));
-        verify(mockListener1, timeout(300).never()).ownershipChanged(any(EntityOwnershipChange.class));
+        Uninterruptibles.sleepUninterruptibly(300, TimeUnit.MILLISECONDS);
+        verify(mockListener1, never()).ownershipChanged(any(EntityOwnershipChange.class));
         verify(mockListener1_2, never()).ownershipChanged(any(EntityOwnershipChange.class));
         assertEquals("# of listener actors", 3, actorContext.children().size());
         reset(mockListener1, mockListener2, mockListener1_2);
@@ -100,7 +104,8 @@ public class EntityOwnershipListenerSupportTest extends AbstractEntityOwnershipT
 
         support.notifyEntityOwnershipListeners(entity3, true, false, true);
 
-        verify(mockListener1, timeout(300).never()).ownershipChanged(any(EntityOwnershipChange.class));
+        Uninterruptibles.sleepUninterruptibly(300, TimeUnit.MILLISECONDS);
+        verify(mockListener1, never()).ownershipChanged(any(EntityOwnershipChange.class));
         verify(mockListener2, never()).ownershipChanged(any(EntityOwnershipChange.class));
         verify(mockListener1_2, never()).ownershipChanged(any(EntityOwnershipChange.class));
         reset(mockListener1, mockListener2, mockListener1_2);
@@ -114,7 +119,8 @@ public class EntityOwnershipListenerSupportTest extends AbstractEntityOwnershipT
         support.notifyEntityOwnershipListeners(entity1, true, false, true);
 
         verify(mockListener1_2, timeout(5000)).ownershipChanged(ownershipChange(entity1, true, false, true));
-        verify(mockListener1, timeout(300).never()).ownershipChanged(any(EntityOwnershipChange.class));
+        Uninterruptibles.sleepUninterruptibly(300, TimeUnit.MILLISECONDS);
+        verify(mockListener1, never()).ownershipChanged(any(EntityOwnershipChange.class));
         reset(mockListener1, mockListener2, mockListener1_2);
 
         // Unregister all listeners and verify their listener actors are destroyed.