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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.plugins.context.metrics;
23 import static org.junit.Assert.fail;
26 import java.io.IOException;
27 import java.util.Arrays;
28 import java.util.TreeSet;
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.common.utils.resources.ResourceUtils;
36 import org.slf4j.ext.XLogger;
37 import org.slf4j.ext.XLoggerFactory;
39 public class TestMetrics {
40 // Logger for this class
41 private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestMetrics.class);
42 private static final String HAZELCAST_CONFIG = "hazelcast.config";
44 private static final String JAVA_NET_PREFER_IPV4_STACK = "java.net.preferIPv4Stack";
45 private static final String HAZELCAST_XML_FILE = "src/test/resources/hazelcast/hazelcast.xml";
48 public final TemporaryFolder folder = new TemporaryFolder();
51 public static void configure() throws Exception {
52 System.setProperty(JAVA_NET_PREFER_IPV4_STACK, "true");
53 final String hazelCastfileLocation = ResourceUtils.getFilePath4Resource(HAZELCAST_XML_FILE);
54 System.setProperty(HAZELCAST_CONFIG, hazelCastfileLocation);
56 final TreeSet<String> ipAddressSet = NetworkUtils.getIPv4NonLoopAddresses();
58 if (ipAddressSet.size() == 0) {
59 throw new Exception("cound not find real IP address for test");
61 LOGGER.info("For Infinispan, setting jgroups.tcp.address to: {}", ipAddressSet.first());
62 System.setProperty("jgroups.tcp.address", ipAddressSet.first());
67 public void getSingleJVMMetrics() throws IOException {
68 final File zookeeperDirectory = folder.newFolder("zookeeperDirectory");
69 final String[] args = {"singleJVMTestNL", "1", "32", "1000", "65536", "0", "localhost", "62181",
70 zookeeperDirectory.getAbsolutePath()};
72 LOGGER.info("Starting with args: {}", Arrays.toString(args));
74 ConcurrentContextMetrics.main(args);
75 } catch (final Exception exception) {
76 LOGGER.error("Unexpected error", exception);
77 fail("Metrics test failed");