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.testsuites.performance.context.metrics;
23 import static org.junit.Assert.fail;
26 import java.io.IOException;
27 import java.util.Arrays;
28 import java.util.SortedSet;
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;
41 * The Class TestMetrics.
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";
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";
52 public final TemporaryFolder folder = new TemporaryFolder();
57 * @throws Exception the exception
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);
65 final SortedSet<String> ipAddressSet = NetworkUtils.getIPv4NonLoopAddresses();
67 if (ipAddressSet.size() == 0) {
68 throw new Exception("cound not find real IP address for test");
70 LOGGER.info("For Infinispan, setting jgroups.tcp.address to: {}", ipAddressSet.first());
71 System.setProperty("jgroups.tcp.address", ipAddressSet.first());
76 * Gets the single jvm metrics.
78 * @throws IOException Signals that an I/O exception has occurred.
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()};
86 LOGGER.info("Starting with args: {}", Arrays.toString(args));
88 ConcurrentContextMetrics.main(args);
89 } catch (final Exception exception) {
90 LOGGER.error("Unexpected error", exception);
91 fail("Metrics test failed");