7bc30550f76a9a6159717bbe7b50fee378df2bc3
[ccsdk/features.git] /
1 /*******************************************************************************
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk feature sdnr wt
4  *  ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  ******************************************************************************/
21 package org.onap.ccsdk.features.sdnr.wt.devicemanager.test;
22
23 import static org.junit.Assert.fail;
24 import java.io.File;
25 import org.junit.Test;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.conf.odlAkka.AkkaConfig;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.conf.odlAkka.ClusterNodeInfo;
28
29 public class TestAkkaConfig {
30
31     private static String getAkkaConfigSingleNodeText() {
32         return "\n" + "odl-cluster-data {\n" + "  akka {\n" + "    remote {\n" + "      artery {\n"
33                 + "        enabled = off\n" + "        canonical.hostname = \"127.0.0.1\"\n"
34                 + "        canonical.port = 2550\n" + "      }\n" + "      netty.tcp {\n"
35                 + "        hostname = \"127.0.0.1\"\n" + "        port = 2550\n" + "      }\n"
36                 + "      # when under load we might trip a false positive on the failure detector\n"
37                 + "      # transport-failure-detector {\n" + "        # heartbeat-interval = 4 s\n"
38                 + "        # acceptable-heartbeat-pause = 16s\n" + "      # }\n" + "    }\n" + "\n" + "    cluster {\n"
39                 + "      # Remove \".tcp\" when using artery.\n"
40                 + "      seed-nodes = [\"akka.tcp://opendaylight-cluster-data@127.0.0.1:2550\"]\n" + "\n"
41                 + "      roles = [\n" + "        \"member-1\"\n" + "      ]\n" + "\n" + "    }\n" + "\n"
42                 + "    persistence {\n"
43                 + "      # By default the snapshots/journal directories live in KARAF_HOME. You can choose to put it somewhere else by\n"
44                 + "      # modifying the following two properties. The directory location specified may be a relative or absolute path. \n"
45                 + "      # The relative path is always relative to KARAF_HOME.\n" + "\n"
46                 + "      # snapshot-store.local.dir = \"target/snapshots\"\n"
47                 + "      # journal.leveldb.dir = \"target/journal\"\n" + "\n" + "      journal {\n"
48                 + "        leveldb {\n" + "          # Set native = off to use a Java-only implementation of leveldb.\n"
49                 + "          # Note that the Java-only version is not currently considered by Akka to be production quality.\n"
50                 + "\n" + "          # native = off\n" + "        }\n" + "      }\n" + "    }\n" + "  }\n" + "}";
51     }
52
53     private static String getAkkaConfigClusterNodeText() {
54         return "\n" + "odl-cluster-data {\n" + "\n" + "  akka {\n" + "    loglevel = \"\"\n" + "    remote {\n"
55                 + "      netty.tcp {\n" + "        hostname = \"zltcmtn23arbc01.2f0377.mtn23a.tci.att.com\"\n"
56                 + "        port = 2550\n" + "      }\n" + "    }\n" + "    actor {\n" + "    debug{\n"
57                 + "        autoreceive = on\n" + "        lifecycle = on\n" + "        unhandled = on\n"
58                 + "        fsm = on\n" + "        event-stream = on\n" + "     }\n" + "    }\n" + "    cluster {\n"
59                 + "      seed-nodes = [\"akka.tcp://opendaylight-cluster-data@zltcmtn23arbc01.2f0377.mtn23a.tci.att.com:2550\", \"akka.tcp://opendaylight-cluster-data@zltcmtn23arbc02.2f0377.mtn23a.tci.att.com:2550\", \"akka.tcp://opendaylight-cluster-data@zltcmtn23arbc03.2f0377.mtn23a.tci.att.com:2550\", \"akka.tcp://opendaylight-cluster-data@zltcmtn23brbc01.f84e7a.mtn23b.tci.att.com:2550\", \"akka.tcp://opendaylight-cluster-data@zltcmtn23brbc02.f84e7a.mtn23b.tci.att.com:2550\", \"akka.tcp://opendaylight-cluster-data@zltcmtn23brbc03.f84e7a.mtn23b.tci.att.com:2550\"]\n"
60                 + "      seed-node-timeout = 15s\n" + "      roles = [\"member-1\"]\n" + "\n" + "    }\n"
61                 + "    persistence {\n" + "    journal-plugin-fallback {\n" + "         circuit-breaker {\n"
62                 + "            max-failures = 10\n" + "            call-timeout = 60s\n"
63                 + "            reset-timeout = 30s\n" + "         }\n" + "     }\n" + "    }\n" + "  }\n" + "}\n" + "\n"
64                 + "odl-cluster-rpc {\n" + "\n" + "  akka {\n" + "    loglevel = \"\"\n" + "    remote {\n"
65                 + "      netty.tcp {\n" + "        hostname = \"zltcmtn23arbc01.2f0377.mtn23a.tci.att.com\"\n"
66                 + "        port = 2551\n" + "      }\n" + "    }\n" + "    actor {\n" + "    debug{\n"
67                 + "        autoreceive = on\n" + "        lifecycle = on\n" + "        unhandled = on\n"
68                 + "        fsm = on\n" + "        event-stream = on\n" + "     }\n" + "    }\n" + "    cluster {\n"
69                 + " seed-nodes = [\"akka.tcp://odl-cluster-rpc@zltcmtn23arbc01.2f0377.mtn23a.tci.att.com:2551\", \"akka.tcp://odl-cluster-rpc@zltcmtn23arbc02.2f0377.mtn23a.tci.att.com:2551\", \"akka.tcp://odl-cluster-rpc@zltcmtn23arbc03.2f0377.mtn23a.tci.att.com:2551\", \"akka.tcp://odl-cluster-rpc@zltcmtn23brbc01.f84e7a.mtn23b.tci.att.com:2551\", \"akka.tcp://odl-cluster-rpc@zltcmtn23brbc02.f84e7a.mtn23b.tci.att.com:2551\", \"akka.tcp://odl-cluster-rpc@zltcmtn23brbc03.f84e7a.mtn23b.tci.att.com:2551\"]\n"
70                 + "        seed-node-timeout = 15s\n" + "    }\n" + "    persistence {\n"
71                 + "    journal-plugin-fallback {\n" + "         circuit-breaker {\n" + "            max-failures = 10\n"
72                 + "            call-timeout = 60s\n" + "            reset-timeout = 30s\n" + "         }\n" + "     }\n"
73                 + "     }\n" + "  }\n" + "}\n" + "\n" + "";
74     }
75
76     @Test
77     public void test1() {
78         AkkaConfig cfg;
79         try {
80             System.out.println("testing clusternode config1");
81             System.out.println("===========================");
82             cfg = AkkaConfig.parse(getAkkaConfigClusterNodeText());
83             System.out.println("succeeded: ");
84             System.out.println(cfg.toString());
85             System.out.println(String.format("found %d cluster nodes", cfg.getClusterConfig().getSeedNodes().size()));
86             for (ClusterNodeInfo n : cfg.getClusterConfig().getSeedNodes()) {
87                 System.out.println(n.toString());
88             }
89         } catch (Exception e) {
90             String failMessage = "failed: " + e.getMessage();
91             System.out.println(failMessage);
92             fail(failMessage);
93         }
94     }
95
96     @Test
97     public void test2() {
98         AkkaConfig cfg;
99         try {
100             System.out.println("testing singlenode config1");
101             System.out.println("===========================");
102             cfg = AkkaConfig.parse(getAkkaConfigSingleNodeText());
103             System.out.println("succeeded: ");
104             System.out.println(cfg.toString());
105         } catch (Exception e) {
106             String failMessage = "failed: " + e.getMessage();
107             System.out.println(failMessage);
108             fail(failMessage);
109        }
110     }
111
112     @Test
113     public void test3() {
114         AkkaConfig cfg;
115
116         ClassLoader classLoader = getClass().getClassLoader();
117         File file = new File(classLoader.getResource("captured-akka.conf").getFile());
118         System.out.println(file.getAbsolutePath());
119
120         try {
121             System.out.println("testing clusternode config1");
122             System.out.println("===========================");
123             cfg = AkkaConfig.load(file.getAbsolutePath());
124             System.out.println("succeeded: "+cfg.hashCode());
125             System.out.println(cfg.toString());
126             System.out.println(String.format("found %d cluster nodes", cfg.getClusterConfig().getSeedNodes().size()));
127             for (ClusterNodeInfo n : cfg.getClusterConfig().getSeedNodes()) {
128                 System.out.println(n.toString());
129             }
130         } catch (Exception e) {
131             String failMessage = "failed: " + e.getMessage();
132             System.out.println(failMessage);
133             fail(failMessage);
134         }
135     }
136 }