X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2Fregistry%2Fgossip%2FGossiperTest.java;h=7ed3112ddb079bf9a7a55690806c99d0871d3d3c;hp=cd4f6d54c811392a836e8f421d67cbd90dc33e21;hb=25be1b9989e89b50a9207b5e47178084e01eeec6;hpb=2418a6052d7eba917d5972f0630cf746d22f690c diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/gossip/GossiperTest.java b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/gossip/GossiperTest.java index cd4f6d54c8..7ed3112ddb 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/gossip/GossiperTest.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/gossip/GossiperTest.java @@ -7,8 +7,8 @@ */ package org.opendaylight.controller.remote.rpc.registry.gossip; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyMap; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; @@ -16,11 +16,12 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import akka.actor.ActorSelection; import akka.actor.ActorSystem; import akka.actor.Address; import akka.actor.Props; -import akka.testkit.JavaTestKit; import akka.testkit.TestActorRef; +import akka.testkit.javadsl.TestKit; import com.typesafe.config.ConfigFactory; import java.util.Map; import org.junit.After; @@ -28,11 +29,8 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.opendaylight.controller.remote.rpc.RemoteRpcProviderConfig; +import org.opendaylight.controller.remote.rpc.RemoteOpsProviderConfig; import org.opendaylight.controller.remote.rpc.TerminationMonitor; -import org.opendaylight.controller.remote.rpc.registry.gossip.Messages.GossiperMessages.GossipEnvelope; -import org.opendaylight.controller.remote.rpc.registry.gossip.Messages.GossiperMessages.GossipStatus; - public class GossiperTest { @@ -42,7 +40,7 @@ public class GossiperTest { private Gossiper mockGossiper; @BeforeClass - public static void setup() throws InterruptedException { + public static void setup() { system = ActorSystem.create("opendaylight-rpc", ConfigFactory.load().getConfig("unit-test")); system.actorOf(Props.create(TerminationMonitor.class), "termination-monitor"); @@ -51,7 +49,7 @@ public class GossiperTest { @AfterClass public static void teardown() { - JavaTestKit.shutdownActorSystem(system); + TestKit.shutdownActorSystem(system); } @Before @@ -62,29 +60,27 @@ public class GossiperTest { @After public void resetMocks() { reset(mockGossiper); - } @Test public void testReceiveGossipTick_WhenNoRemoteMemberShouldIgnore() { mockGossiper.setClusterMembers(); - doNothing().when(mockGossiper).getLocalStatusAndSendTo(any(Address.class)); + doNothing().when(mockGossiper).getLocalStatusAndSendTo(any(ActorSelection.class)); mockGossiper.receiveGossipTick(); - verify(mockGossiper, times(0)).getLocalStatusAndSendTo(any(Address.class)); + verify(mockGossiper, times(0)).getLocalStatusAndSendTo(any(ActorSelection.class)); } @Test public void testReceiveGossipTick_WhenRemoteMemberExistsShouldSendStatus() { mockGossiper.setClusterMembers(new Address("tcp", "member")); - doNothing().when(mockGossiper).getLocalStatusAndSendTo(any(Address.class)); + doNothing().when(mockGossiper).getLocalStatusAndSendTo(any(ActorSelection.class)); mockGossiper.receiveGossipTick(); - verify(mockGossiper, times(1)).getLocalStatusAndSendTo(any(Address.class)); + verify(mockGossiper, times(1)).getLocalStatusAndSendTo(any(ActorSelection.class)); } @SuppressWarnings("unchecked") @Test public void testReceiveGossipStatus_WhenSenderIsNonMemberShouldIgnore() { - Address nonMember = new Address("tcp", "non-member"); GossipStatus remoteStatus = new GossipStatus(nonMember, mock(Map.class)); @@ -94,14 +90,12 @@ public class GossiperTest { verify(mockGossiper, times(0)).getSender(); } - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings("unchecked") @Test public void testReceiveGossipWhenNotAddressedToSelfShouldIgnore() { - Address notSelf = new Address("tcp", "not-self"); - - GossipEnvelope envelope = new GossipEnvelope(notSelf, notSelf, mock(Map.class)); doNothing().when(mockGossiper).updateRemoteBuckets(anyMap()); - mockGossiper.receiveGossip(envelope); + Address notSelf = new Address("tcp", "not-self"); + mockGossiper.receiveGossip(new GossipEnvelope(notSelf, notSelf, mock(Map.class))); verify(mockGossiper, times(0)).updateRemoteBuckets(anyMap()); } @@ -111,7 +105,10 @@ public class GossiperTest { * @return instance of Gossiper class */ private static Gossiper createGossiper() { - final Props props = Gossiper.testProps(new RemoteRpcProviderConfig(system.settings().config())); + final RemoteOpsProviderConfig config = + new RemoteOpsProviderConfig.Builder("unit-test") + .withConfigReader(ConfigFactory::load).build(); + final Props props = Gossiper.testProps(config); final TestActorRef testRef = TestActorRef.create(system, props, "testGossiper"); return testRef.underlyingActor();