diff options
author | waqas.ikram <waqas.ikram@ericsson.com> | 2018-07-17 15:35:47 +0100 |
---|---|---|
committer | waqas.ikram <waqas.ikram@ericsson.com> | 2018-07-18 16:10:29 +0100 |
commit | dcae33d8d9a3dcb8a9249d5d33f103f1e97d2e6c (patch) | |
tree | e9c54c365154595a9fbd996204ee3fa9eca69025 /testsuites/performance/performance-context-metrics/src/test/java/org/onap/policy/apex/plugins/context/metrics/TestMetrics.java | |
parent | 84c349f342da7f67fe728bb2ef3a3b59afb4cd7e (diff) |
Refactoring Metrics test
Change-Id: I99290a3dec61b3ce0f4d5fd33d6b429d091b48ca
Issue-ID: POLICY-954
Signed-off-by: waqas.ikram <waqas.ikram@ericsson.com>
Diffstat (limited to 'testsuites/performance/performance-context-metrics/src/test/java/org/onap/policy/apex/plugins/context/metrics/TestMetrics.java')
-rw-r--r-- | testsuites/performance/performance-context-metrics/src/test/java/org/onap/policy/apex/plugins/context/metrics/TestMetrics.java | 55 |
1 files changed, 39 insertions, 16 deletions
diff --git a/testsuites/performance/performance-context-metrics/src/test/java/org/onap/policy/apex/plugins/context/metrics/TestMetrics.java b/testsuites/performance/performance-context-metrics/src/test/java/org/onap/policy/apex/plugins/context/metrics/TestMetrics.java index 5607f8711..9f051eb82 100644 --- a/testsuites/performance/performance-context-metrics/src/test/java/org/onap/policy/apex/plugins/context/metrics/TestMetrics.java +++ b/testsuites/performance/performance-context-metrics/src/test/java/org/onap/policy/apex/plugins/context/metrics/TestMetrics.java @@ -22,36 +22,59 @@ package org.onap.policy.apex.plugins.context.metrics; import static org.junit.Assert.fail; +import java.io.File; import java.io.IOException; +import java.util.Arrays; +import java.util.TreeSet; -import org.apache.curator.test.TestingServer; -import org.junit.After; -import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.onap.policy.apex.context.test.utils.NetworkUtils; +import org.onap.policy.apex.model.utilities.ResourceUtils; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; public class TestMetrics { - // Zookeeper test server - TestingServer zkTestServer; + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestMetrics.class); + private static final String HAZELCAST_CONFIG = "hazelcast.config"; - @Before - public void beforeTest() throws Exception { - zkTestServer = new TestingServer(62181); - } + private static final String JAVA_NET_PREFER_IPV4_STACK = "java.net.preferIPv4Stack"; + private static final String HAZELCAST_XML_FILE = "src/test/resources/hazelcast/hazelcast.xml"; + + @Rule + public final TemporaryFolder folder = new TemporaryFolder(); + + @BeforeClass + public static void configure() throws Exception { + System.setProperty(JAVA_NET_PREFER_IPV4_STACK, "true"); + final String hazelCastfileLocation = ResourceUtils.getFilePath4Resource(HAZELCAST_XML_FILE); + System.setProperty(HAZELCAST_CONFIG, hazelCastfileLocation); + + final TreeSet<String> ipAddressSet = NetworkUtils.getIPv4NonLoopAddresses(); + + if (ipAddressSet.size() == 0) { + throw new Exception("cound not find real IP address for test"); + } + LOGGER.info("For Infinispan, setting jgroups.tcp.address to: {}", ipAddressSet.first()); + System.setProperty("jgroups.tcp.address", ipAddressSet.first()); - @After - public void afterTest() throws IOException { - zkTestServer.stop(); } @Test - public void getSingleJVMMetrics() { - final String[] args = {"singleJVMTestNL", "1", "32", "1000", "65536", "0", "localhost:62181", "false"}; + public void getSingleJVMMetrics() throws IOException { + final File zookeeperDirectory = folder.newFolder("zookeeperDirectory"); + final String[] args = {"singleJVMTestNL", "1", "32", "1000", "65536", "0", "localhost", "62181", + zookeeperDirectory.getAbsolutePath()}; + LOGGER.info("Starting with args: {}", Arrays.toString(args)); try { ConcurrentContextMetrics.main(args); - } catch (final Exception e) { + } catch (final Exception exception) { + LOGGER.error("Unexpected error", exception); fail("Metrics test failed"); - e.printStackTrace(); } } } |