BUG 3340 : Log the count of modifications on a given transaction context
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / RouteRpcListenerTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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
9 package org.opendaylight.controller.remote.rpc;
10
11
12 import akka.actor.ActorRef;
13 import akka.actor.ActorSystem;
14 import akka.testkit.JavaTestKit;
15 import com.typesafe.config.ConfigFactory;
16 import org.junit.AfterClass;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.controller.md.sal.common.impl.routing.RoutingUtils;
20 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
21 import org.opendaylight.controller.sal.core.api.RpcRoutingContext;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24
25 import java.net.URI;
26 import java.net.URISyntaxException;
27
28 public class RouteRpcListenerTest {
29
30   static ActorSystem system;
31
32
33   @BeforeClass
34   public static void setup() throws InterruptedException {
35     system = ActorSystem.create("opendaylight-rpc", ConfigFactory.load().getConfig("odl-cluster-rpc"));
36   }
37
38   @AfterClass
39   public static void teardown() {
40     JavaTestKit.shutdownActorSystem(system);
41     system = null;
42   }
43
44   @Test
45   public void testRouteAdd() throws URISyntaxException, InterruptedException {
46     new JavaTestKit(system) {
47       {
48         // Test announcements
49         JavaTestKit probeReg = new JavaTestKit(system);
50         ActorRef rpcRegistry = probeReg.getRef();
51
52         RoutedRpcListener rpcListener = new RoutedRpcListener(rpcRegistry);
53
54         QName qName = new QName(new URI("actor2"), "actor2");
55         RpcRoutingContext context = RpcRoutingContext.create(qName, qName);
56         YangInstanceIdentifier identifier = YangInstanceIdentifier.create(new YangInstanceIdentifier.NodeIdentifier(qName));
57         rpcListener.onRouteChange(RoutingUtils.announcementChange(context, identifier));
58
59         probeReg.expectMsgClass(RpcRegistry.Messages.AddOrUpdateRoutes.class);
60       }};
61   }
62
63   @Test
64   public void testRouteRemove() throws URISyntaxException, InterruptedException {
65     new JavaTestKit(system) {
66       {
67         // Test announcements
68         JavaTestKit probeReg = new JavaTestKit(system);
69         ActorRef rpcRegistry = probeReg.getRef();
70
71         RoutedRpcListener rpcListener = new RoutedRpcListener(rpcRegistry);
72
73         QName qName = new QName(new URI("actor2"), "actor2");
74         RpcRoutingContext context = RpcRoutingContext.create(qName, qName);
75         YangInstanceIdentifier identifier = YangInstanceIdentifier.create(new YangInstanceIdentifier.NodeIdentifier(qName));
76         rpcListener.onRouteChange(RoutingUtils.removalChange(context, identifier));
77
78         probeReg.expectMsgClass(RpcRegistry.Messages.RemoveRoutes.class);
79       }};
80   }
81 }