Add support for reusable streaming
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / RemoteRpcProviderTest.java
1 /*
2  * Copyright (c) 2014, 2017 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 package org.opendaylight.controller.remote.rpc;
9
10 import static org.mockito.Mockito.mock;
11
12 import akka.actor.ActorRef;
13 import akka.actor.ActorSystem;
14 import akka.testkit.javadsl.TestKit;
15 import com.typesafe.config.Config;
16 import com.typesafe.config.ConfigFactory;
17 import java.util.concurrent.TimeUnit;
18 import org.junit.AfterClass;
19 import org.junit.Assert;
20 import org.junit.BeforeClass;
21 import org.junit.Test;
22 import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
23 import org.opendaylight.mdsal.dom.api.DOMRpcService;
24 import scala.concurrent.Await;
25 import scala.concurrent.duration.FiniteDuration;
26
27 public class RemoteRpcProviderTest {
28     static ActorSystem system;
29     static RemoteRpcProviderConfig moduleConfig;
30
31     @BeforeClass
32     public static void setup() {
33         moduleConfig = new RemoteRpcProviderConfig.Builder("odl-cluster-rpc")
34                 .withConfigReader(ConfigFactory::load).build();
35         final Config config = moduleConfig.get();
36         system = ActorSystem.create("odl-cluster-rpc", config);
37
38     }
39
40     @AfterClass
41     public static void teardown() {
42         TestKit.shutdownActorSystem(system);
43         system = null;
44     }
45
46     @Test
47     public void testRemoteRpcProvider() throws Exception {
48         try (RemoteRpcProvider rpcProvider = new RemoteRpcProvider(system, mock(DOMRpcProviderService.class),
49             mock(DOMRpcService.class), new RemoteRpcProviderConfig(system.settings().config()))) {
50
51             rpcProvider.start();
52
53             final ActorRef actorRef = Await.result(
54                     system.actorSelection(moduleConfig.getRpcManagerPath()).resolveOne(
55                             FiniteDuration.create(1, TimeUnit.SECONDS)), FiniteDuration.create(2, TimeUnit.SECONDS));
56
57             Assert.assertTrue(actorRef.path().toString().contains(moduleConfig.getRpcManagerPath()));
58         }
59     }
60 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.