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=896c0245393f22374f5077cacbe88680f58159cc;hp=e61b54f067e7bcba09a0ef7d476f7cd3b04c938d;hb=927bce5688e4b9d33d3e5e9b769d8a0dba5ccdd4;hpb=54916d10764a5234881040e9a68ae35d63b3dac9 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 e61b54f067..896c024539 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,34 +7,31 @@ */ package org.opendaylight.controller.remote.rpc.registry.gossip; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyMap; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.reset; +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.TestActorRef; +import akka.testkit.javadsl.TestKit; import com.typesafe.config.ConfigFactory; +import java.util.Map; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.opendaylight.controller.remote.rpc.RemoteOpsProviderConfig; import org.opendaylight.controller.remote.rpc.TerminationMonitor; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyMap; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.opendaylight.controller.remote.rpc.registry.gossip.Messages.GossiperMessages.GossipEnvelope; -import static org.opendaylight.controller.remote.rpc.registry.gossip.Messages.GossiperMessages.GossipStatus; - public class GossiperTest { @@ -44,7 +41,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"); @@ -53,64 +50,53 @@ public class GossiperTest { @AfterClass public static void teardown() { - if (system != null) - system.shutdown(); + TestKit.shutdownActorSystem(system); } @Before - public void createMocks(){ + public void createMocks() { mockGossiper = spy(gossiper); } @After - public void resetMocks(){ + public void resetMocks() { reset(mockGossiper); - } @Test - public void testReceiveGossipTick_WhenNoRemoteMemberShouldIgnore(){ - - mockGossiper.setClusterMembers(Collections.EMPTY_LIST); - doNothing().when(mockGossiper).getLocalStatusAndSendTo(any(Address.class)); + public void testReceiveGossipTick_WhenNoRemoteMemberShouldIgnore() { + mockGossiper.setClusterMembers(); + 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(){ - List
members = new ArrayList<>(); - Address remote = new Address("tcp", "member"); - members.add(remote); - - mockGossiper.setClusterMembers(members); - doNothing().when(mockGossiper).getLocalStatusAndSendTo(any(Address.class)); + public void testReceiveGossipTick_WhenRemoteMemberExistsShouldSendStatus() { + mockGossiper.setClusterMembers(new Address("tcp", "member")); + 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(){ - + public void testReceiveGossipStatus_WhenSenderIsNonMemberShouldIgnore() { Address nonMember = new Address("tcp", "non-member"); GossipStatus remoteStatus = new GossipStatus(nonMember, mock(Map.class)); //add a member - List
members = new ArrayList<>(); - members.add(new Address("tcp", "member")); - - mockGossiper.setClusterMembers(members); + mockGossiper.setClusterMembers(new Address("tcp", "member")); mockGossiper.receiveGossipStatus(remoteStatus); verify(mockGossiper, times(0)).getSender(); } + @SuppressWarnings("unchecked") @Test - public void testReceiveGossip_WhenNotAddressedToSelfShouldIgnore(){ - Address notSelf = new Address("tcp", "not-self"); - - GossipEnvelope envelope = new GossipEnvelope(notSelf, notSelf, mock(Map.class)); + public void testReceiveGossipWhenNotAddressedToSelfShouldIgnore() { 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()); } @@ -119,11 +105,13 @@ public class GossiperTest { * * @return instance of Gossiper class */ - private static Gossiper createGossiper(){ - - final Props props = Props.create(Gossiper.class, false); + private static Gossiper createGossiper() { + 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(); } -} \ No newline at end of file +}