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
10 package org.opendaylight.controller.remote.rpc;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.when;
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;
33 public class RemoteRpcProviderTest {
35 static ActorSystem system;
36 static RemoteRpcProviderConfig moduleConfig;
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);
47 public static void teardown() {
48 JavaTestKit.shutdownActorSystem(system);
53 public void testRemoteRpcProvider() throws Exception {
54 try (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));
62 rpcProvider.onSessionInitiated(session);
64 final ActorRef actorRef = Await.result(
65 system.actorSelection(moduleConfig.getRpcManagerPath()).resolveOne(
66 Duration.create(1, TimeUnit.SECONDS)), Duration.create(2, TimeUnit.SECONDS));
68 Assert.assertTrue(actorRef.path().toString().contains(moduleConfig.getRpcManagerPath()));