2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.remote.rpc.registry;
11 import akka.actor.ActorRef;
12 import akka.actor.ActorSystem;
13 import akka.testkit.JavaTestKit;
14 import junit.framework.Assert;
15 import org.junit.AfterClass;
16 import org.junit.BeforeClass;
17 import org.junit.Test;
18 import org.mockito.Mockito;
19 import org.opendaylight.controller.remote.rpc.RouteIdentifierImpl;
20 import org.opendaylight.controller.remote.rpc.messages.AddRoutedRpc;
21 import org.opendaylight.controller.remote.rpc.messages.AddRpc;
22 import org.opendaylight.controller.remote.rpc.messages.GetRoutedRpc;
23 import org.opendaylight.controller.remote.rpc.messages.GetRoutedRpcReply;
24 import org.opendaylight.controller.remote.rpc.messages.GetRpc;
25 import org.opendaylight.controller.remote.rpc.messages.GetRpcReply;
26 import org.opendaylight.controller.remote.rpc.messages.RemoveRoutedRpc;
27 import org.opendaylight.controller.remote.rpc.messages.RemoveRpc;
28 import org.opendaylight.controller.sal.connector.api.RpcRouter;
29 import org.opendaylight.yangtools.yang.common.QName;
32 import java.net.URISyntaxException;
33 import java.util.HashSet;
36 public class RpcRegistryOldTest {
38 static ActorSystem system;
42 public static void setup() {
43 system = ActorSystem.create();
47 public static void teardown() {
48 JavaTestKit.shutdownActorSystem(system);
53 This test add, read and remove an entry in global rpc
56 public void testGlobalRpc() throws URISyntaxException {
57 new JavaTestKit(system) {{
58 ActorRef rpcRegistry = system.actorOf(RpcRegistryOld.props(Mockito.mock(ClusterWrapper.class)));
59 QName type = new QName(new URI("actor1"), "actor1");
60 RouteIdentifierImpl routeId = new RouteIdentifierImpl(null, type, null);
61 final String route = "actor1";
63 AddRpc rpcMsg = new AddRpc(routeId, route);
64 rpcRegistry.tell(rpcMsg, getRef());
65 expectMsgEquals(duration("2 second"), "Success");
67 GetRpc getRpc = new GetRpc(routeId);
68 rpcRegistry.tell(getRpc, getRef());
70 Boolean getMsg = new ExpectMsg<Boolean>("GetRpcReply") {
71 protected Boolean match(Object in) {
72 if (in instanceof GetRpcReply) {
73 GetRpcReply reply = (GetRpcReply)in;
74 return route.equals(reply.getRoutePath());
79 }.get(); // this extracts the received message
81 Assert.assertTrue(getMsg);
83 RemoveRpc removeMsg = new RemoveRpc(routeId);
84 rpcRegistry.tell(removeMsg, getRef());
85 expectMsgEquals(duration("2 second"), "Success");
87 rpcRegistry.tell(getRpc, getRef());
89 Boolean getNullMsg = new ExpectMsg<Boolean>("GetRpcReply") {
90 protected Boolean match(Object in) {
91 if (in instanceof GetRpcReply) {
92 GetRpcReply reply = (GetRpcReply)in;
93 return reply.getRoutePath() == null;
99 Assert.assertTrue(getNullMsg);
105 This test add, read and remove an entry in routed rpc
108 public void testRoutedRpc() throws URISyntaxException {
109 new JavaTestKit(system) {{
110 ActorRef rpcRegistry = system.actorOf(RpcRegistryOld.props(Mockito.mock(ClusterWrapper.class)));
111 QName type = new QName(new URI("actor1"), "actor1");
112 RouteIdentifierImpl routeId = new RouteIdentifierImpl(null, type, null);
113 final String route = "actor1";
115 Set<RpcRouter.RouteIdentifier<?, ?, ?>> routeIds = new HashSet<>();
116 routeIds.add(routeId);
118 AddRoutedRpc rpcMsg = new AddRoutedRpc(routeIds, route);
119 rpcRegistry.tell(rpcMsg, getRef());
120 expectMsgEquals(duration("2 second"), "Success");
122 GetRoutedRpc getRpc = new GetRoutedRpc(routeId);
123 rpcRegistry.tell(getRpc, getRef());
125 Boolean getMsg = new ExpectMsg<Boolean>("GetRoutedRpcReply") {
126 protected Boolean match(Object in) {
127 if (in instanceof GetRoutedRpcReply) {
128 GetRoutedRpcReply reply = (GetRoutedRpcReply)in;
129 return route.equals(reply.getRoutePath());
134 }.get(); // this extracts the received message
136 Assert.assertTrue(getMsg);
138 RemoveRoutedRpc removeMsg = new RemoveRoutedRpc(routeIds, route);
139 rpcRegistry.tell(removeMsg, getRef());
140 expectMsgEquals(duration("2 second"), "Success");
142 rpcRegistry.tell(getRpc, getRef());
144 Boolean getNullMsg = new ExpectMsg<Boolean>("GetRoutedRpcReply") {
145 protected Boolean match(Object in) {
146 if (in instanceof GetRoutedRpcReply) {
147 GetRoutedRpcReply reply = (GetRoutedRpcReply)in;
148 return reply.getRoutePath() == null;
154 Assert.assertTrue(getNullMsg);