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 akka.actor.ActorRef;
14 import akka.actor.ActorSystem;
15 import akka.testkit.JavaTestKit;
16 import com.typesafe.config.Config;
17 import org.junit.AfterClass;
18 import org.junit.Assert;
19 import org.junit.BeforeClass;
20 import org.junit.Test;
21 import org.opendaylight.controller.sal.core.api.Broker;
22 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
23 import org.opendaylight.controller.sal.core.api.model.SchemaService;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 import scala.concurrent.Await;
26 import scala.concurrent.duration.Duration;
28 import java.util.concurrent.TimeUnit;
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.when;
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 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 RemoteRpcProvider rpcProvider = new RemoteRpcProvider(system, mock(RpcProvisionRegistry.class));
55 Broker.ProviderSession session = mock(Broker.ProviderSession.class);
56 SchemaService schemaService = mock(SchemaService.class);
57 when(schemaService.getGlobalContext()). thenReturn(mock(SchemaContext.class));
58 when(session.getService(SchemaService.class)).thenReturn(schemaService);
60 rpcProvider.onSessionInitiated(session);
62 ActorRef actorRef = Await.result(
63 system.actorSelection(
64 moduleConfig.getRpcManagerPath()).resolveOne(Duration.create(1, TimeUnit.SECONDS)),
65 Duration.create(2, TimeUnit.SECONDS));
67 Assert.assertTrue(actorRef.path().toString().contains(moduleConfig.getRpcManagerPath()));