From 3eee17a3bbd0f7ca65aa812164b0fe3df7b79cfc Mon Sep 17 00:00:00 2001 From: Ivan Hrasko Date: Wed, 5 Apr 2017 14:54:06 +0200 Subject: [PATCH] Unit test for RemoteRpcRegistryMXBeanImpl class Change-Id: Ic00c607f3f66b327336b49f92afe6eb29c144a92 Signed-off-by: Ivan Hrasko --- .../RemoteRpcRegistryMXBeanImplTest.java | 162 ++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/mbeans/RemoteRpcRegistryMXBeanImplTest.java diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/mbeans/RemoteRpcRegistryMXBeanImplTest.java b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/mbeans/RemoteRpcRegistryMXBeanImplTest.java new file mode 100644 index 0000000000..b48d40bac8 --- /dev/null +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/registry/mbeans/RemoteRpcRegistryMXBeanImplTest.java @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.remote.rpc.registry.mbeans; + +import akka.actor.ActorRef; +import akka.actor.ActorSystem; +import akka.actor.Props; +import akka.testkit.JavaTestKit; +import akka.testkit.TestActorRef; +import com.google.common.collect.Lists; +import com.google.common.util.concurrent.Uninterruptibles; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier; +import org.opendaylight.controller.remote.rpc.RemoteRpcProviderConfig; +import org.opendaylight.controller.remote.rpc.registry.RpcRegistry; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; + +public class RemoteRpcRegistryMXBeanImplTest { + + private static final QName LOCAL_QNAME = QName.create("base", "local"); + private static final SchemaPath EMPTY_SCHEMA_PATH = SchemaPath.ROOT; + private static final SchemaPath LOCAL_SCHEMA_PATH = SchemaPath.create(true, LOCAL_QNAME); + + private ActorSystem system; + private TestActorRef testActor; + private List buckets; + private RemoteRpcRegistryMXBeanImpl mxBean; + + @Before + public void setUp() throws Exception { + system = ActorSystem.create("test"); + + final DOMRpcIdentifier emptyRpcIdentifier = DOMRpcIdentifier.create( + EMPTY_SCHEMA_PATH, YangInstanceIdentifier.EMPTY); + final DOMRpcIdentifier localRpcIdentifier = DOMRpcIdentifier.create( + LOCAL_SCHEMA_PATH, YangInstanceIdentifier.of(LOCAL_QNAME)); + + buckets = Lists.newArrayList(emptyRpcIdentifier, localRpcIdentifier); + + final RemoteRpcProviderConfig config = new RemoteRpcProviderConfig.Builder("system").build(); + final JavaTestKit invoker = new JavaTestKit(system); + final JavaTestKit registrar = new JavaTestKit(system); + final JavaTestKit supervisor = new JavaTestKit(system); + final Props props = RpcRegistry.props(config, invoker.getRef(), registrar.getRef()); + testActor = new TestActorRef<>(system, props, supervisor.getRef(), "testActor"); + final RpcRegistry rpcRegistry = testActor.underlyingActor(); + + mxBean = new RemoteRpcRegistryMXBeanImpl(rpcRegistry); + Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS); + } + + @After + public void tearDown() throws Exception { + JavaTestKit.shutdownActorSystem(system, null, Boolean.TRUE); + } + + @Test + public void testGetGlobalRpcEmptyBuckets() throws Exception { + final Set globalRpc = mxBean.getGlobalRpc(); + + Assert.assertNotNull(globalRpc); + Assert.assertTrue(globalRpc.isEmpty()); + } + + @Test + public void testGetGlobalRpc() throws Exception { + testActor.tell(new RpcRegistry.Messages.AddOrUpdateRoutes(Lists.newArrayList(buckets)), ActorRef.noSender()); + final Set globalRpc = mxBean.getGlobalRpc(); + + Assert.assertNotNull(globalRpc); + Assert.assertEquals(1, globalRpc.size()); + + final String rpc = globalRpc.iterator().next(); + Assert.assertEquals(EMPTY_SCHEMA_PATH.toString(), rpc); + } + + @Test + public void testGetLocalRegisteredRoutedRpcEmptyBuckets() throws Exception { + final Set localRegisteredRoutedRpc = mxBean.getLocalRegisteredRoutedRpc(); + + Assert.assertNotNull(localRegisteredRoutedRpc); + Assert.assertTrue(localRegisteredRoutedRpc.isEmpty()); + } + + @Test + public void testGetLocalRegisteredRoutedRpc() throws Exception { + testActor.tell(new RpcRegistry.Messages.AddOrUpdateRoutes(Lists.newArrayList(buckets)), ActorRef.noSender()); + final Set localRegisteredRoutedRpc = mxBean.getLocalRegisteredRoutedRpc(); + + Assert.assertNotNull(localRegisteredRoutedRpc); + Assert.assertEquals(1, localRegisteredRoutedRpc.size()); + + final String localRpc = localRegisteredRoutedRpc.iterator().next(); + Assert.assertTrue(localRpc.contains(LOCAL_QNAME.toString())); + Assert.assertTrue(localRpc.contains(LOCAL_SCHEMA_PATH.toString())); + } + + @Test + public void testFindRpcByNameEmptyBuckets() throws Exception { + final Map rpcByName = mxBean.findRpcByName(""); + + Assert.assertNotNull(rpcByName); + Assert.assertTrue(rpcByName.isEmpty()); + } + + @Test + public void testFindRpcByName() throws Exception { + testActor.tell(new RpcRegistry.Messages.AddOrUpdateRoutes(Lists.newArrayList(buckets)), ActorRef.noSender()); + final Map rpcByName = mxBean.findRpcByName(""); + + Assert.assertNotNull(rpcByName); + Assert.assertEquals(1, rpcByName.size()); + Assert.assertTrue(rpcByName.containsValue(LOCAL_QNAME.getLocalName())); + } + + @Test + public void testFindRpcByRouteEmptyBuckets() throws Exception { + final Map rpcByRoute = mxBean.findRpcByRoute(""); + + Assert.assertNotNull(rpcByRoute); + Assert.assertTrue(rpcByRoute.isEmpty()); + } + + @Test + public void testFindRpcByRoute() throws Exception { + testActor.tell(new RpcRegistry.Messages.AddOrUpdateRoutes(Lists.newArrayList(buckets)), ActorRef.noSender()); + final Map rpcByRoute = mxBean.findRpcByRoute(""); + + Assert.assertNotNull(rpcByRoute); + Assert.assertEquals(1, rpcByRoute.size()); + Assert.assertTrue(rpcByRoute.containsValue(LOCAL_QNAME.getLocalName())); + } + + @Test + public void testGetBucketVersionsEmptyBuckets() throws Exception { + final String bucketVersions = mxBean.getBucketVersions(); + Assert.assertEquals(Collections.EMPTY_MAP.toString(), bucketVersions); + } + + @Test + public void testGetBucketVersions() throws Exception { + testActor.tell(new RpcRegistry.Messages.AddOrUpdateRoutes(Lists.newArrayList(buckets)), ActorRef.noSender()); + final String bucketVersions = mxBean.getBucketVersions(); + + Assert.assertTrue(bucketVersions.contains(testActor.provider().getDefaultAddress().toString())); + } +} \ No newline at end of file -- 2.36.6