Add support for reusable streaming
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / RemoteOpsProviderConfigTest.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 package org.opendaylight.controller.remote.rpc;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14
15 import akka.actor.ActorSystem;
16 import akka.actor.Props;
17 import akka.actor.UntypedAbstractActor;
18 import akka.testkit.TestActorRef;
19 import com.typesafe.config.Config;
20 import com.typesafe.config.ConfigFactory;
21 import java.util.concurrent.TimeUnit;
22 import org.junit.Test;
23 import org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader;
24 import scala.concurrent.duration.FiniteDuration;
25
26 public class RemoteOpsProviderConfigTest {
27
28     @Test
29     public void testConfigDefaults() {
30         RemoteOpsProviderConfig config = new RemoteOpsProviderConfig.Builder("unit-test").build();
31
32         //Assert on configurations from common config
33         assertFalse(config.isMetricCaptureEnabled()); //should be disabled by default
34         assertNotNull(config.getMailBoxCapacity());
35         assertNotNull(config.getMailBoxName());
36         assertNotNull(config.getMailBoxPushTimeout());
37
38         //rest of the configurations should be set
39         assertNotNull(config.getActorSystemName());
40         assertNotNull(config.getRpcBrokerName());
41         assertNotNull(config.getRpcBrokerPath());
42         assertNotNull(config.getRpcManagerName());
43         assertNotNull(config.getRpcManagerPath());
44         assertNotNull(config.getRpcRegistryName());
45         assertNotNull(config.getActionRegistryName());
46         assertNotNull(config.getRpcRegistryPath());
47         assertNotNull(config.getActionRegistryPath());
48         assertNotNull(config.getAskDuration());
49         assertNotNull(config.getGossipTickInterval());
50     }
51
52     @Test
53     public void testConfigCustomizations() {
54
55         AkkaConfigurationReader reader = new TestConfigReader();
56
57         final int expectedCapacity = 100;
58         String timeOutVal = "10ms";
59         FiniteDuration expectedTimeout = FiniteDuration.create(10, TimeUnit.MILLISECONDS);
60
61         RemoteOpsProviderConfig config = new RemoteOpsProviderConfig.Builder("unit-test")
62                 .metricCaptureEnabled(true)//enable metric capture
63                 .mailboxCapacity(expectedCapacity)
64                 .mailboxPushTimeout(timeOutVal)
65                 .withConfigReader(reader)
66                 .build();
67
68         assertTrue(config.isMetricCaptureEnabled());
69         assertEquals(expectedCapacity, config.getMailBoxCapacity().intValue());
70         assertEquals(expectedTimeout.toMillis(), config.getMailBoxPushTimeout().toMillis());
71
72         //Now check this config inside an actor
73         ActorSystem system = ActorSystem.create("unit-test", config.get());
74         TestActorRef<ConfigTestActor> configTestActorTestActorRef =
75                 TestActorRef.create(system, Props.create(ConfigTestActor.class));
76
77         ConfigTestActor actor = configTestActorTestActorRef.underlyingActor();
78         Config actorConfig = actor.getConfig();
79
80         config = new RemoteOpsProviderConfig(actorConfig);
81
82         assertTrue(config.isMetricCaptureEnabled());
83         assertEquals(expectedCapacity, config.getMailBoxCapacity().intValue());
84         assertEquals(expectedTimeout.toMillis(), config.getMailBoxPushTimeout().toMillis());
85     }
86
87     public static class ConfigTestActor extends UntypedAbstractActor {
88
89         private final Config actorSystemConfig;
90
91         public ConfigTestActor() {
92             this.actorSystemConfig = getContext().system().settings().config();
93         }
94
95         @Override
96         public void onReceive(final Object message) {
97         }
98
99         /**
100          * Only for testing. NEVER expose actor's internal state like this.
101          */
102         public Config getConfig() {
103             return actorSystemConfig;
104         }
105     }
106
107     public static class TestConfigReader implements AkkaConfigurationReader {
108
109         @Override
110         public Config read() {
111             return ConfigFactory.parseResources("application.conf");
112
113         }
114     }
115 }

©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.