13610121a282a2720858ea446bc71be223f227fe
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.testsuites.performance.context.metrics;
22
23 import static org.junit.Assert.fail;
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.util.Arrays;
28 import java.util.SortedSet;
29
30 import org.junit.BeforeClass;
31 import org.junit.Rule;
32 import org.junit.Test;
33 import org.junit.rules.TemporaryFolder;
34 import org.onap.policy.apex.context.test.utils.NetworkUtils;
35 import org.onap.policy.apex.testsuites.performance.context.metrics.ConcurrentContextMetrics;
36 import org.onap.policy.common.utils.resources.ResourceUtils;
37 import org.slf4j.ext.XLogger;
38 import org.slf4j.ext.XLoggerFactory;
39
40 /**
41  * The Class TestMetrics.
42  */
43 public class TestMetrics {
44     // Logger for this class
45     private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestMetrics.class);
46     private static final String HAZELCAST_CONFIG = "hazelcast.config";
47
48     private static final String JAVA_NET_PREFER_IPV4_STACK = "java.net.preferIPv4Stack";
49     private static final String HAZELCAST_XML_FILE = "src/test/resources/hazelcast/hazelcast.xml";
50
51     @Rule
52     public final TemporaryFolder folder = new TemporaryFolder();
53
54     /**
55      * Configure.
56      *
57      * @throws Exception the exception
58      */
59     @BeforeClass
60     public static void configure() throws Exception {
61         System.setProperty(JAVA_NET_PREFER_IPV4_STACK, "true");
62         final String hazelCastfileLocation = ResourceUtils.getFilePath4Resource(HAZELCAST_XML_FILE);
63         System.setProperty(HAZELCAST_CONFIG, hazelCastfileLocation);
64
65         final SortedSet<String> ipAddressSet = NetworkUtils.getIPv4NonLoopAddresses();
66
67         if (ipAddressSet.size() == 0) {
68             throw new Exception("cound not find real IP address for test");
69         }
70         LOGGER.info("For Infinispan, setting jgroups.tcp.address to: {}", ipAddressSet.first());
71         System.setProperty("jgroups.tcp.address", ipAddressSet.first());
72
73     }
74
75     /**
76      * Gets the single jvm metrics.
77      *
78      * @throws IOException Signals that an I/O exception has occurred.
79      */
80     @Test
81     public void getSingleJvmMetrics() throws IOException {
82         final File zookeeperDirectory = folder.newFolder("zookeeperDirectory");
83         final String[] args = {"singleJVMTestNL", "1", "32", "1000", "65536", "0", "localhost", "62181",
84                 zookeeperDirectory.getAbsolutePath()};
85
86         LOGGER.info("Starting with args: {}", Arrays.toString(args));
87         try {
88             ConcurrentContextMetrics.main(args);
89         } catch (final Exception exception) {
90             LOGGER.error("Unexpected error", exception);
91             fail("Metrics test failed");
92         }
93     }
94 }