Teach sal-remoterpc-connector to route actions
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / registry / mbeans / RemoteRpcRegistryMXBeanImplTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.remote.rpc.registry.mbeans;
9
10 import akka.actor.ActorRef;
11 import akka.actor.ActorSystem;
12 import akka.actor.Props;
13 import akka.dispatch.Dispatchers;
14 import akka.testkit.TestActorRef;
15 import akka.testkit.javadsl.TestKit;
16 import akka.util.Timeout;
17 import com.google.common.collect.Lists;
18 import java.util.Collections;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Set;
22 import java.util.concurrent.TimeUnit;
23 import org.junit.After;
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.opendaylight.controller.remote.rpc.RemoteOpsProviderConfig;
28 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
29 import org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreAccess;
30 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
31 import org.opendaylight.yangtools.yang.common.QName;
32 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
33 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
34
35 public class RemoteRpcRegistryMXBeanImplTest {
36
37     private static final QName LOCAL_QNAME = QName.create("base", "local");
38     private static final SchemaPath EMPTY_SCHEMA_PATH = SchemaPath.ROOT;
39     private static final SchemaPath LOCAL_SCHEMA_PATH = SchemaPath.create(true, LOCAL_QNAME);
40
41     private ActorSystem system;
42     private TestActorRef<RpcRegistry> testActor;
43     private List<DOMRpcIdentifier> buckets;
44     private RemoteRpcRegistryMXBeanImpl mxBean;
45
46     @Before
47     public void setUp() {
48         system = ActorSystem.create("test");
49
50         final DOMRpcIdentifier emptyRpcIdentifier = DOMRpcIdentifier.create(
51                 EMPTY_SCHEMA_PATH, YangInstanceIdentifier.EMPTY);
52         final DOMRpcIdentifier localRpcIdentifier = DOMRpcIdentifier.create(
53                 LOCAL_SCHEMA_PATH, YangInstanceIdentifier.of(LOCAL_QNAME));
54
55         buckets = Lists.newArrayList(emptyRpcIdentifier, localRpcIdentifier);
56
57         final RemoteOpsProviderConfig config = new RemoteOpsProviderConfig.Builder("system").build();
58         final TestKit invoker = new TestKit(system);
59         final TestKit registrar = new TestKit(system);
60         final TestKit supervisor = new TestKit(system);
61         final Props props = RpcRegistry.props(config, invoker.getRef(), registrar.getRef())
62                 .withDispatcher(Dispatchers.DefaultDispatcherId());
63         testActor = new TestActorRef<>(system, props, supervisor.getRef(), "testActor");
64
65         final Timeout timeout = Timeout.apply(10, TimeUnit.SECONDS);
66         mxBean = new RemoteRpcRegistryMXBeanImpl(new BucketStoreAccess(testActor, system.dispatcher(), timeout),
67                 timeout);
68     }
69
70     @After
71     public void tearDown() {
72         TestKit.shutdownActorSystem(system, Boolean.TRUE);
73     }
74
75     @Test
76     public void testGetGlobalRpcEmptyBuckets() {
77         final Set<String> globalRpc = mxBean.getGlobalRpc();
78
79         Assert.assertNotNull(globalRpc);
80         Assert.assertTrue(globalRpc.isEmpty());
81     }
82
83     @Test
84     public void testGetGlobalRpc() {
85         testActor.tell(new RpcRegistry.Messages.AddOrUpdateRoutes(Lists.newArrayList(buckets)), ActorRef.noSender());
86         final Set<String> globalRpc = mxBean.getGlobalRpc();
87
88         Assert.assertNotNull(globalRpc);
89         Assert.assertEquals(1, globalRpc.size());
90
91         final String rpc = globalRpc.iterator().next();
92         Assert.assertEquals(EMPTY_SCHEMA_PATH.toString(), rpc);
93     }
94
95     @Test
96     public void testGetLocalRegisteredRoutedRpcEmptyBuckets() {
97         final Set<String> localRegisteredRoutedRpc = mxBean.getLocalRegisteredRoutedRpc();
98
99         Assert.assertNotNull(localRegisteredRoutedRpc);
100         Assert.assertTrue(localRegisteredRoutedRpc.isEmpty());
101     }
102
103     @Test
104     public void testGetLocalRegisteredRoutedRpc() {
105         testActor.tell(new RpcRegistry.Messages.AddOrUpdateRoutes(Lists.newArrayList(buckets)), ActorRef.noSender());
106         final Set<String> localRegisteredRoutedRpc = mxBean.getLocalRegisteredRoutedRpc();
107
108         Assert.assertNotNull(localRegisteredRoutedRpc);
109         Assert.assertEquals(1, localRegisteredRoutedRpc.size());
110
111         final String localRpc = localRegisteredRoutedRpc.iterator().next();
112         Assert.assertTrue(localRpc.contains(LOCAL_QNAME.toString()));
113         Assert.assertTrue(localRpc.contains(LOCAL_SCHEMA_PATH.toString()));
114     }
115
116     @Test
117     public void testFindRpcByNameEmptyBuckets() {
118         final Map<String, String> rpcByName = mxBean.findRpcByName("");
119
120         Assert.assertNotNull(rpcByName);
121         Assert.assertTrue(rpcByName.isEmpty());
122     }
123
124     @Test
125     public void testFindRpcByName() {
126         testActor.tell(new RpcRegistry.Messages.AddOrUpdateRoutes(Lists.newArrayList(buckets)), ActorRef.noSender());
127         final Map<String, String> rpcByName = mxBean.findRpcByName("");
128
129         Assert.assertNotNull(rpcByName);
130         Assert.assertEquals(1, rpcByName.size());
131         Assert.assertTrue(rpcByName.containsValue(LOCAL_QNAME.getLocalName()));
132     }
133
134     @Test
135     public void testFindRpcByRouteEmptyBuckets() {
136         final Map<String, String> rpcByRoute = mxBean.findRpcByRoute("");
137
138         Assert.assertNotNull(rpcByRoute);
139         Assert.assertTrue(rpcByRoute.isEmpty());
140     }
141
142     @Test
143     public void testFindRpcByRoute() {
144         testActor.tell(new RpcRegistry.Messages.AddOrUpdateRoutes(Lists.newArrayList(buckets)), ActorRef.noSender());
145         final Map<String, String> rpcByRoute = mxBean.findRpcByRoute("");
146
147         Assert.assertNotNull(rpcByRoute);
148         Assert.assertEquals(1, rpcByRoute.size());
149         Assert.assertTrue(rpcByRoute.containsValue(LOCAL_QNAME.getLocalName()));
150     }
151
152     @Test
153     public void testGetBucketVersionsEmptyBuckets() {
154         final String bucketVersions = mxBean.getBucketVersions();
155         Assert.assertEquals(Collections.EMPTY_MAP.toString(), bucketVersions);
156     }
157
158     @Test
159     public void testGetBucketVersions() {
160         testActor.tell(new RpcRegistry.Messages.AddOrUpdateRoutes(Lists.newArrayList(buckets)), ActorRef.noSender());
161         final String bucketVersions = mxBean.getBucketVersions();
162
163         Assert.assertTrue(bucketVersions.contains(testActor.provider().getDefaultAddress().toString()));
164     }
165 }

©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.