BUG 4151 : Create a shared actor system
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / RemoteRpcProviderTest.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
10 package org.opendaylight.controller.remote.rpc;
11
12
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.when;
15
16 import akka.actor.ActorRef;
17 import akka.actor.ActorSystem;
18 import akka.testkit.JavaTestKit;
19 import com.typesafe.config.Config;
20 import java.util.concurrent.TimeUnit;
21 import org.junit.AfterClass;
22 import org.junit.Assert;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService;
26 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
27 import org.opendaylight.controller.sal.core.api.Broker;
28 import org.opendaylight.controller.sal.core.api.model.SchemaService;
29 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
30 import scala.concurrent.Await;
31 import scala.concurrent.duration.Duration;
32
33 public class RemoteRpcProviderTest {
34
35   static ActorSystem system;
36   static RemoteRpcProviderConfig moduleConfig;
37
38   @BeforeClass
39   public static void setup() throws InterruptedException {
40     moduleConfig = new RemoteRpcProviderConfig.Builder("odl-cluster-rpc").build();
41     final Config config = moduleConfig.get();
42     system = ActorSystem.create("odl-cluster-rpc", config);
43
44   }
45
46   @AfterClass
47   public static void teardown() {
48     JavaTestKit.shutdownActorSystem(system);
49     system = null;
50   }
51
52   @Test
53   public void testRemoteRpcProvider() throws Exception {
54     final RemoteRpcProvider rpcProvider = new RemoteRpcProvider(system, mock(DOMRpcProviderService.class),
55             new RemoteRpcProviderConfig(system.settings().config()));
56     final Broker.ProviderSession session = mock(Broker.ProviderSession.class);
57     final SchemaService schemaService = mock(SchemaService.class);
58     when(schemaService.getGlobalContext()). thenReturn(mock(SchemaContext.class));
59     when(session.getService(SchemaService.class)).thenReturn(schemaService);
60     when(session.getService(DOMRpcService.class)).thenReturn(mock(DOMRpcService.class));
61
62     rpcProvider.onSessionInitiated(session);
63
64     final ActorRef actorRef = Await.result(
65             system.actorSelection(
66                     moduleConfig.getRpcManagerPath()).resolveOne(Duration.create(1, TimeUnit.SECONDS)),
67                                                                  Duration.create(2, TimeUnit.SECONDS));
68
69     Assert.assertTrue(actorRef.path().toString().contains(moduleConfig.getRpcManagerPath()));
70   }
71 }