From dcae33d8d9a3dcb8a9249d5d33f103f1e97d2e6c Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Tue, 17 Jul 2018 15:35:47 +0100 Subject: Refactoring Metrics test Change-Id: I99290a3dec61b3ce0f4d5fd33d6b429d091b48ca Issue-ID: POLICY-954 Signed-off-by: waqas.ikram --- .../integration/integration-context-test/pom.xml | 14 +- .../test/locking/TestConcurrentContext.java | 312 ++++++---- .../resources/infinispan/default-jgroups-udp.xml | 7 +- .../context/metrics/ConcurrentContextMetrics.java | 433 ++++---------- .../metrics/ConcurrentContextMetricsJVM.java | 212 ------- .../metrics/ConcurrentContextMetricsJVMThread.java | 187 ------ .../metrics/ConcurrentContextMetricsThread.java | 170 ------ .../apex/plugins/context/metrics/TestMetrics.java | 55 +- .../src/test/resources/hazelcast/hazelcast.xml | 656 ++------------------- .../resources/infinispan/default-jgroups-tcp.xml | 76 +++ .../src/test/resources/infinispan/infinispan.xml | 2 +- 11 files changed, 457 insertions(+), 1667 deletions(-) delete mode 100644 testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetricsJVM.java delete mode 100644 testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetricsJVMThread.java delete mode 100644 testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetricsThread.java create mode 100644 testsuites/performance/performance-context-metrics/src/test/resources/infinispan/default-jgroups-tcp.xml (limited to 'testsuites') diff --git a/testsuites/integration/integration-context-test/pom.xml b/testsuites/integration/integration-context-test/pom.xml index 6454a8cd5..95e2c6b43 100644 --- a/testsuites/integration/integration-context-test/pom.xml +++ b/testsuites/integration/integration-context-test/pom.xml @@ -71,18 +71,6 @@ ${project.version} test - - org.apache.curator - curator-test - 4.0.0 - test - - - log4j - log4j - - - - + \ No newline at end of file diff --git a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/plugins/context/test/locking/TestConcurrentContext.java b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/plugins/context/test/locking/TestConcurrentContext.java index e2c2de97a..5c1329242 100644 --- a/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/plugins/context/test/locking/TestConcurrentContext.java +++ b/testsuites/integration/integration-context-test/src/test/java/org/onap/policy/apex/plugins/context/test/locking/TestConcurrentContext.java @@ -21,20 +21,17 @@ package org.onap.policy.apex.plugins.context.test.locking; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.onap.policy.apex.context.parameters.DistributorParameters.DEFAULT_DISTRIBUTOR_PLUGIN_CLASS; +import static org.onap.policy.apex.context.test.utils.Constants.TEST_VALUE; import java.io.File; import java.io.IOException; -import java.net.InetAddress; import java.net.InetSocketAddress; -import java.net.NetworkInterface; -import java.util.Collections; -import java.util.Enumeration; +import java.util.Map; import java.util.TreeSet; -import org.apache.zookeeper.server.NIOServerCnxnFactory; -import org.apache.zookeeper.server.ZooKeeperServer; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; @@ -44,7 +41,15 @@ import org.onap.policy.apex.context.impl.locking.jvmlocal.JVMLocalLockManager; import org.onap.policy.apex.context.parameters.ContextParameters; import org.onap.policy.apex.context.parameters.DistributorParameters; import org.onap.policy.apex.context.parameters.LockManagerParameters; +import org.onap.policy.apex.context.test.concepts.TestContextLongItem; +import org.onap.policy.apex.context.test.lock.modifier.LockType; import org.onap.policy.apex.context.test.locking.ConcurrentContext; +import org.onap.policy.apex.context.test.utils.ConfigrationProvider; +import org.onap.policy.apex.context.test.utils.ConfigrationProviderImpl; +import org.onap.policy.apex.context.test.utils.Constants; +import org.onap.policy.apex.context.test.utils.NetworkUtils; +import org.onap.policy.apex.context.test.utils.ZooKeeperServerServiceProvider; +import org.onap.policy.apex.core.infrastructure.messaging.util.MessagingUtils; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; import org.onap.policy.apex.model.basicmodel.service.ParameterService; @@ -58,8 +63,6 @@ import org.onap.policy.apex.plugins.context.locking.hazelcast.HazelcastLockManag import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; -import com.hazelcast.config.Config; - /** * The Class TestConcurrentContext tests concurrent use of context. * @@ -67,7 +70,7 @@ import com.hazelcast.config.Config; */ public class TestConcurrentContext { private static final String HAZELCAST_CONFIG = "hazelcast.config"; - + 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"; @@ -83,8 +86,6 @@ public class TestConcurrentContext { private static final int TEST_THREAD_COUNT_MULTI_JVM = 20; private static final int TEST_THREAD_LOOPS = 100; - private NIOServerCnxnFactory zookeeperFactory; - // We need to increment the Zookeeper port because sometimes the port is not released at the end // of the test for a few seconds. private static int nextZookeeperPort = ZOOKEEPER_START_PORT; @@ -93,157 +94,175 @@ public class TestConcurrentContext { @Rule public final TemporaryFolder folder = new TemporaryFolder(); + private ZooKeeperServerServiceProvider zooKeeperServerServiceProvider; + @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); - // The JGroups IP address must be set to a real (not loopback) IP address for Infinispan to - // work. IN order to ensure that all - // the JVMs in a test pick up the same IP address, this function sets the address to be the - // first non-loopback IPv4 address - // on a host - final TreeSet ipAddressSet = new TreeSet(); - - final Enumeration nets = NetworkInterface.getNetworkInterfaces(); - for (final NetworkInterface netint : Collections.list(nets)) { - final Enumeration inetAddresses = netint.getInetAddresses(); - for (final InetAddress inetAddress : Collections.list(inetAddresses)) { - // Look for real IPv4 internet addresses - if (!inetAddress.isLoopbackAddress() && inetAddress.getAddress().length == 4) { - ipAddressSet.add(inetAddress.getHostAddress()); - } - } - } + final TreeSet ipAddressSet = NetworkUtils.getIPv4NonLoopAddresses(); if (ipAddressSet.size() == 0) { throw new Exception("cound not find real IP address for test"); } - System.out.println("For Infinispan, setting jgroups.tcp.address to: " + ipAddressSet.first()); + logger.info("For Infinispan, setting jgroups.tcp.address to: {}", ipAddressSet.first()); System.setProperty("jgroups.tcp.address", ipAddressSet.first()); - final Config config = new Config(); - config.getNetworkConfig().setPublicAddress(ipAddressSet.first()); - config.getNetworkConfig().getInterfaces().addInterface(ipAddressSet.first()); } - @AfterClass - public static void teardown() throws IOException {} - - private void startZookeeperServer() throws IOException, InterruptedException { + private void startZookeeperServer() throws Exception { final File zookeeperDirectory = folder.newFolder("zookeeperDirectory"); zookeeperPort = nextZookeeperPort++; - - final ZooKeeperServer server = new ZooKeeperServer(zookeeperDirectory, zookeeperDirectory, 5000); - zookeeperFactory = new NIOServerCnxnFactory(); - zookeeperFactory.configure(new InetSocketAddress(zookeeperPort), 100); - - zookeeperFactory.startup(server); + final InetSocketAddress addr = new InetSocketAddress(MessagingUtils.findPort(zookeeperPort)); + zooKeeperServerServiceProvider = new ZooKeeperServerServiceProvider(zookeeperDirectory, addr); + zooKeeperServerServiceProvider.startZookeeperServer(); } private void stopZookeeperServer() { - zookeeperFactory.shutdown(); + if (zooKeeperServerServiceProvider != null) { + zooKeeperServerServiceProvider.stopZookeeperServer(); + } } @Test - public void testConcurrentContextJVMLocalVarSet() throws ApexModelException, IOException, ApexException { + public void testConcurrentContextJVMLocalVarSet() throws Exception { logger.debug("Running testConcurrentContextJVMLocalVarSet test . . ."); final ContextParameters contextParameters = new ContextParameters(); contextParameters.getLockManagerParameters().setPluginClass(JVMLocalLockManager.class.getCanonicalName()); - final long result = new ConcurrentContext().testConcurrentContext("JVMLocalVarSet", TEST_JVM_COUNT_SINGLE_JVM, - TEST_THREAD_COUNT_SINGLE_JVM, TEST_THREAD_LOOPS); - assertEquals(TEST_JVM_COUNT_SINGLE_JVM * TEST_THREAD_COUNT_SINGLE_JVM * TEST_THREAD_LOOPS, result); + final ConfigrationProvider configrationProvider = getConfigrationProvider("JVMLocalVarSet", + TEST_JVM_COUNT_SINGLE_JVM, TEST_THREAD_COUNT_SINGLE_JVM, TEST_THREAD_LOOPS); + + final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); + final Map result = concurrentContext.testConcurrentContext(); + + assertFalse(result.isEmpty()); + + final int expected = TEST_JVM_COUNT_SINGLE_JVM * TEST_THREAD_COUNT_SINGLE_JVM * TEST_THREAD_LOOPS; + final TestContextLongItem actual = result.get(TEST_VALUE); + assertNotNull(actual); + assertEquals(expected, actual.getLongValue()); logger.debug("Ran testConcurrentContextJVMLocalVarSet test"); } @Test - public void testConcurrentContextJVMLocalNoVarSet() throws ApexModelException, IOException, ApexException { + public void testConcurrentContextJVMLocalNoVarSet() throws Exception { logger.debug("Running testConcurrentContextJVMLocalNoVarSet test . . ."); new ContextParameters(); - final long result = new ConcurrentContext().testConcurrentContext("JVMLocalNoVarSet", TEST_JVM_COUNT_SINGLE_JVM, - TEST_THREAD_COUNT_SINGLE_JVM, TEST_THREAD_LOOPS); + final ConfigrationProvider configrationProvider = getConfigrationProvider("JVMLocalNoVarSet", + TEST_JVM_COUNT_SINGLE_JVM, TEST_THREAD_COUNT_SINGLE_JVM, TEST_THREAD_LOOPS); - assertEquals(TEST_JVM_COUNT_SINGLE_JVM * TEST_THREAD_COUNT_SINGLE_JVM * TEST_THREAD_LOOPS, result); + final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); + final Map result = concurrentContext.testConcurrentContext(); + + final int expected = TEST_JVM_COUNT_SINGLE_JVM * TEST_THREAD_COUNT_SINGLE_JVM * TEST_THREAD_LOOPS; + final TestContextLongItem actual = result.get(Constants.TEST_VALUE); + assertNotNull(actual); + assertEquals(expected, actual.getLongValue()); logger.debug("Ran testConcurrentContextJVMLocalNoVarSet test"); } @Test - public void testConcurrentContextMultiJVMNoLock() throws ApexModelException, IOException, ApexException { + public void testConcurrentContextMultiJVMNoLock() throws Exception { logger.debug("Running testConcurrentContextMultiJVMNoLock test . . ."); final ContextParameters contextParameters = new ContextParameters(); contextParameters.getDistributorParameters().setPluginClass(JVMLocalDistributor.class.getCanonicalName()); contextParameters.getLockManagerParameters().setPluginClass(JVMLocalLockManager.class.getCanonicalName()); - final long result = new ConcurrentContext().testConcurrentContext("testConcurrentContextMultiJVMNoLock", + final ConfigrationProvider configrationProvider = getConfigrationProvider("testConcurrentContextMultiJVMNoLock", TEST_JVM_COUNT_MULTI_JVM, TEST_THREAD_COUNT_MULTI_JVM, TEST_THREAD_LOOPS); + final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); + final Map result = concurrentContext.testConcurrentContext(); + // No concurrent map so result will be zero - assertEquals(0, result); + final TestContextLongItem actual = result.get(TEST_VALUE); + assertNotNull(actual); + assertEquals(0, actual.getLongValue()); logger.debug("Ran testConcurrentContextMultiJVMNoLock test"); } @Test - public void testConcurrentContextHazelcastLock() throws ApexModelException, IOException, ApexException { + public void testConcurrentContextHazelcastLock() throws Exception { logger.debug("Running testConcurrentContextHazelcastLock test . . ."); final ContextParameters contextParameters = new ContextParameters(); contextParameters.getDistributorParameters().setPluginClass(DEFAULT_DISTRIBUTOR_PLUGIN_CLASS); contextParameters.getLockManagerParameters().setPluginClass(HazelcastLockManager.class.getCanonicalName()); - final long result = new ConcurrentContext().testConcurrentContext("HazelcastLock", TEST_JVM_COUNT_SINGLE_JVM, - TEST_THREAD_COUNT_SINGLE_JVM, TEST_THREAD_LOOPS); - assertEquals(TEST_JVM_COUNT_SINGLE_JVM * TEST_THREAD_COUNT_SINGLE_JVM * TEST_THREAD_LOOPS, result); + final ConfigrationProvider configrationProvider = getConfigrationProvider("HazelcastLock", + TEST_JVM_COUNT_SINGLE_JVM, TEST_THREAD_COUNT_SINGLE_JVM, TEST_THREAD_LOOPS); + + final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); + final Map result = concurrentContext.testConcurrentContext(); + + final int expected = TEST_JVM_COUNT_SINGLE_JVM * TEST_THREAD_COUNT_SINGLE_JVM * TEST_THREAD_LOOPS; + final TestContextLongItem actual = result.get(TEST_VALUE); + assertNotNull(actual); + assertEquals(expected, actual.getLongValue()); + logger.debug("Ran testConcurrentContextHazelcastLock test"); } @Test - public void testConcurrentContextCuratorLock() - throws ApexModelException, IOException, ApexException, InterruptedException { + public void testConcurrentContextCuratorLock() throws Exception { logger.debug("Running testConcurrentContextCuratorLock test . . ."); - - startZookeeperServer(); - - final ContextParameters contextParameters = new ContextParameters(); - contextParameters.getDistributorParameters() - .setPluginClass(DistributorParameters.DEFAULT_DISTRIBUTOR_PLUGIN_CLASS); - - final CuratorLockManagerParameters curatorParameters = new CuratorLockManagerParameters(); - curatorParameters.setPluginClass(CuratorLockManager.class.getCanonicalName()); - curatorParameters.setZookeeperAddress(ZOOKEEPER_ADDRESS + ":" + zookeeperPort); - contextParameters.setLockManagerParameters(curatorParameters); - ParameterService.registerParameters(LockManagerParameters.class, curatorParameters); - - final long result = new ConcurrentContext().testConcurrentContext("CuratorLock", TEST_JVM_COUNT_SINGLE_JVM, - TEST_THREAD_COUNT_SINGLE_JVM, TEST_THREAD_LOOPS); - - assertEquals(TEST_JVM_COUNT_SINGLE_JVM * TEST_THREAD_COUNT_SINGLE_JVM * TEST_THREAD_LOOPS, result); - - stopZookeeperServer(); - logger.debug("Ran testConcurrentContextCuratorLock test"); + try { + startZookeeperServer(); + final ContextParameters contextParameters = new ContextParameters(); + final DistributorParameters distributorParameters = contextParameters.getDistributorParameters(); + distributorParameters.setPluginClass(DEFAULT_DISTRIBUTOR_PLUGIN_CLASS); + + final CuratorLockManagerParameters curatorParameters = new CuratorLockManagerParameters(); + curatorParameters.setPluginClass(CuratorLockManager.class.getCanonicalName()); + curatorParameters.setZookeeperAddress(ZOOKEEPER_ADDRESS + ":" + zookeeperPort); + contextParameters.setLockManagerParameters(curatorParameters); + ParameterService.registerParameters(LockManagerParameters.class, curatorParameters); + + final ConfigrationProvider configrationProvider = getConfigrationProvider("CuratorLock", + TEST_JVM_COUNT_SINGLE_JVM, TEST_THREAD_COUNT_SINGLE_JVM, TEST_THREAD_LOOPS); + + final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); + final Map result = concurrentContext.testConcurrentContext(); + + final int expected = TEST_JVM_COUNT_SINGLE_JVM * TEST_THREAD_COUNT_SINGLE_JVM * TEST_THREAD_LOOPS; + final TestContextLongItem actual = result.get(TEST_VALUE); + assertNotNull(actual); + assertEquals(expected, actual.getLongValue()); + logger.debug("Ran testConcurrentContextCuratorLock test"); + } finally { + stopZookeeperServer(); + } } @Test - public void testConcurrentContextHazelcastMultiJVMHazelcastLock() - throws ApexModelException, IOException, ApexException { + public void testConcurrentContextHazelcastMultiJVMHazelcastLock() throws Exception { logger.debug("Running testConcurrentContextHazelcastMultiJVMHazelcastLock test . . ."); final ContextParameters contextParameters = new ContextParameters(); - contextParameters.getDistributorParameters() - .setPluginClass(HazelcastContextDistributor.class.getCanonicalName()); + final DistributorParameters distributorParameters = contextParameters.getDistributorParameters(); + distributorParameters.setPluginClass(HazelcastContextDistributor.class.getCanonicalName()); contextParameters.getLockManagerParameters().setPluginClass(HazelcastLockManager.class.getCanonicalName()); - final long result = new ConcurrentContext().testConcurrentContext("HazelcastMultiHazelcastlock", + + final ConfigrationProvider configrationProvider = getConfigrationProvider("HazelcastMultiHazelcastlock", TEST_JVM_COUNT_MULTI_JVM, TEST_THREAD_COUNT_MULTI_JVM, TEST_THREAD_LOOPS); - assertEquals(TEST_JVM_COUNT_MULTI_JVM * TEST_THREAD_COUNT_MULTI_JVM * TEST_THREAD_LOOPS, result); + final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); + final Map result = concurrentContext.testConcurrentContext(); + + final int expected = TEST_JVM_COUNT_MULTI_JVM * TEST_THREAD_COUNT_MULTI_JVM * TEST_THREAD_LOOPS; + final TestContextLongItem actual = result.get(TEST_VALUE); + assertNotNull(actual); + assertEquals(expected, actual.getLongValue()); logger.debug("Ran testConcurrentContextHazelcastMultiJVMHazelcastLock test"); } @@ -259,65 +278,98 @@ public class TestConcurrentContext { contextParameters.setDistributorParameters(infinispanParameters); contextParameters.getLockManagerParameters().setPluginClass(HazelcastLockManager.class.getCanonicalName()); - final long result = new ConcurrentContext().testConcurrentContext("InfinispanMultiHazelcastlock", + final ConfigrationProvider configrationProvider = getConfigrationProvider("InfinispanMultiHazelcastlock", TEST_JVM_COUNT_MULTI_JVM, TEST_THREAD_COUNT_MULTI_JVM, TEST_THREAD_LOOPS); - assertEquals(TEST_JVM_COUNT_MULTI_JVM * TEST_THREAD_COUNT_MULTI_JVM * TEST_THREAD_LOOPS, result); + final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); + final Map result = concurrentContext.testConcurrentContext(); + + final int expected = TEST_JVM_COUNT_MULTI_JVM * TEST_THREAD_COUNT_MULTI_JVM * TEST_THREAD_LOOPS; + final TestContextLongItem actual = result.get(TEST_VALUE); + assertNotNull(actual); + assertEquals(expected, actual.getLongValue()); logger.debug("Ran testConcurrentContextInfinispanMultiJVMHazelcastlock test"); } @Test - public void testConcurrentContextInfinispanMultiJVMCuratorLock() - throws ApexModelException, IOException, ApexException, InterruptedException { + public void testConcurrentContextInfinispanMultiJVMCuratorLock() throws Exception { logger.debug("Running testConcurrentContextInfinispanMultiJVMCuratorLock test . . ."); - startZookeeperServer(); - - final ContextParameters contextParameters = new ContextParameters(); - final InfinispanDistributorParameters infinispanParameters = new InfinispanDistributorParameters(); - infinispanParameters.setPluginClass(InfinispanContextDistributor.class.getCanonicalName()); - infinispanParameters.setConfigFile("infinispan/infinispan-context-test.xml"); - contextParameters.setDistributorParameters(infinispanParameters); - - final CuratorLockManagerParameters curatorParameters = new CuratorLockManagerParameters(); - curatorParameters.setPluginClass(CuratorLockManager.class.getCanonicalName()); - curatorParameters.setZookeeperAddress(ZOOKEEPER_ADDRESS + ":" + zookeeperPort); - contextParameters.setLockManagerParameters(curatorParameters); - ParameterService.registerParameters(LockManagerParameters.class, curatorParameters); - - final long result = new ConcurrentContext().testConcurrentContext("InfinispanMultiCuratorLock", - TEST_JVM_COUNT_MULTI_JVM, TEST_THREAD_COUNT_MULTI_JVM, TEST_THREAD_LOOPS); - - assertEquals(TEST_JVM_COUNT_MULTI_JVM * TEST_THREAD_COUNT_MULTI_JVM * TEST_THREAD_LOOPS, result); - - stopZookeeperServer(); + try { + startZookeeperServer(); + + final ContextParameters contextParameters = new ContextParameters(); + final InfinispanDistributorParameters infinispanParameters = new InfinispanDistributorParameters(); + infinispanParameters.setPluginClass(InfinispanContextDistributor.class.getCanonicalName()); + infinispanParameters.setConfigFile("infinispan/infinispan-context-test.xml"); + contextParameters.setDistributorParameters(infinispanParameters); + + final CuratorLockManagerParameters curatorParameters = new CuratorLockManagerParameters(); + curatorParameters.setPluginClass(CuratorLockManager.class.getCanonicalName()); + curatorParameters.setZookeeperAddress(ZOOKEEPER_ADDRESS + ":" + zookeeperPort); + contextParameters.setLockManagerParameters(curatorParameters); + ParameterService.registerParameters(LockManagerParameters.class, curatorParameters); + + final ConfigrationProvider configrationProvider = getConfigrationProvider("InfinispanMultiCuratorLock", + TEST_JVM_COUNT_MULTI_JVM, TEST_THREAD_COUNT_MULTI_JVM, TEST_THREAD_LOOPS); + + final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); + final Map result = concurrentContext.testConcurrentContext(); + + final int expected = TEST_JVM_COUNT_MULTI_JVM * TEST_THREAD_COUNT_MULTI_JVM * TEST_THREAD_LOOPS; + final TestContextLongItem actual = result.get(TEST_VALUE); + assertNotNull(actual); + assertEquals(expected, actual.getLongValue()); + } finally { + stopZookeeperServer(); + } logger.debug("Ran testConcurrentContextInfinispanMultiJVMCuratorLock test"); } @Test - public void testConcurrentContextHazelcastMultiJVMCuratorLock() - throws ApexModelException, IOException, ApexException, InterruptedException { + public void testConcurrentContextHazelcastMultiJVMCuratorLock() throws Exception { logger.debug("Running testConcurrentContextHazelcastMultiJVMCuratorLock test . . ."); - startZookeeperServer(); - - final ContextParameters contextParameters = new ContextParameters(); - contextParameters.getDistributorParameters() - .setPluginClass(HazelcastContextDistributor.class.getCanonicalName()); - - final CuratorLockManagerParameters curatorParameters = new CuratorLockManagerParameters(); - curatorParameters.setPluginClass(CuratorLockManager.class.getCanonicalName()); - curatorParameters.setZookeeperAddress(ZOOKEEPER_ADDRESS + ":" + zookeeperPort); - contextParameters.setLockManagerParameters(curatorParameters); - ParameterService.registerParameters(LockManagerParameters.class, curatorParameters); - - final long result = new ConcurrentContext().testConcurrentContext("HazelcastMultiCuratorLock", - TEST_JVM_COUNT_MULTI_JVM, TEST_THREAD_COUNT_MULTI_JVM, TEST_THREAD_LOOPS); + try { + startZookeeperServer(); + + final ContextParameters contextParameters = new ContextParameters(); + contextParameters.getDistributorParameters() + .setPluginClass(HazelcastContextDistributor.class.getCanonicalName()); + + final CuratorLockManagerParameters curatorParameters = new CuratorLockManagerParameters(); + curatorParameters.setPluginClass(CuratorLockManager.class.getCanonicalName()); + curatorParameters.setZookeeperAddress(ZOOKEEPER_ADDRESS + ":" + zookeeperPort); + contextParameters.setLockManagerParameters(curatorParameters); + ParameterService.registerParameters(LockManagerParameters.class, curatorParameters); + + final ConfigrationProvider configrationProvider = getConfigrationProvider("HazelcastMultiCuratorLock", + TEST_JVM_COUNT_MULTI_JVM, TEST_THREAD_COUNT_MULTI_JVM, TEST_THREAD_LOOPS); + final Map result = + new ConcurrentContext(configrationProvider).testConcurrentContext(); + + final int expected = TEST_JVM_COUNT_MULTI_JVM * TEST_THREAD_COUNT_MULTI_JVM * TEST_THREAD_LOOPS; + final TestContextLongItem actual = result.get(TEST_VALUE); + assertNotNull(actual); + assertEquals(expected, actual.getLongValue()); + } finally { + stopZookeeperServer(); + } + logger.debug("Ran testConcurrentContextHazelcastMultiJVMCuratorLock test"); + } - assertEquals(TEST_JVM_COUNT_MULTI_JVM * TEST_THREAD_COUNT_MULTI_JVM * TEST_THREAD_LOOPS, result); + ConfigrationProvider getConfigrationProvider(final String testType, final int jvmCount, final int threadCount, + final int threadLoops) { + return new ConfigrationProviderImpl(testType, jvmCount, threadCount, threadLoops, 16, + LockType.WRITE_LOCK_SINGLE_VALUE_UPDATE.getValue()) { + @Override + public Map getContextAlbumInitValues() { + final Map initValues = super.getContextAlbumInitValues(); + initValues.put(TEST_VALUE, new TestContextLongItem(0l)); + return initValues; + } - stopZookeeperServer(); - logger.debug("Ran testConcurrentContextHazelcastMultiJVMCuratorLock test"); + }; } } diff --git a/testsuites/integration/integration-context-test/src/test/resources/infinispan/default-jgroups-udp.xml b/testsuites/integration/integration-context-test/src/test/resources/infinispan/default-jgroups-udp.xml index 17ba5eaca..a84a737b5 100644 --- a/testsuites/integration/integration-context-test/src/test/resources/infinispan/default-jgroups-udp.xml +++ b/testsuites/integration/integration-context-test/src/test/resources/infinispan/default-jgroups-udp.xml @@ -24,6 +24,8 @@ xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups-4.0.xsd"> + + - + result = concurrentContext.testConcurrentContext(); - outMetricLine(testName, "Totaled"); - } catch (final Exception e) { - e.printStackTrace(); + long total = 0; + for (final Entry entry : result.entrySet()) { + LOGGER.trace("Album key: {}, value: {}", entry.getKey(), entry.getValue()); + total += entry.getValue().getLongValue(); } + LOGGER.info("Album total value after execution: {}", total); - if (lockType == 2) { - if (total == jvmCount * threadCount * threadLoops) { - outMetricLine(testName, "VerifiedOK"); - } else { - outMetricLine(testName, "VerifiedFail"); - } - } else { - if (total == 0) { - outMetricLine(testName, "VerifiedOK"); - } else { - outMetricLine(testName, "VerifiedFail"); - } - } + LOGGER.info("Completed {} ...", testName); } - /** - * Clear context. - * - * @param testName the test name - * @throws ContextException the context exception - */ - private void clearContext(final String testName) throws ContextException { - contextDistributor.clear(); - contextDistributor = null; - outMetricLine(testName, "Cleared"); - } - - /** - * Out metric line. - * - * @param testName the test name - * @param testPhase the test phase - */ - public void outMetricLine(final String testName, final String testPhase) { - System.out.println("ContextMetrics," + dateFormat.format(new Date()) + "," + System.currentTimeMillis() + "," - + testLabel + "," + testName + "," + testPhase + "," + jvmCount + "," + threadCount + "," + threadLoops - + "," + longArraySize + "," + lockType + "," + total); - } } diff --git a/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetricsJVM.java b/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetricsJVM.java deleted file mode 100644 index ed81e39a1..000000000 --- a/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetricsJVM.java +++ /dev/null @@ -1,212 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.metrics; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.Arrays; - -import org.onap.policy.apex.context.ContextAlbum; -import org.onap.policy.apex.context.Distributor; -import org.onap.policy.apex.context.impl.distribution.DistributorFactory; -import org.onap.policy.apex.context.test.factory.TestContextAlbumFactory; -import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.service.AbstractParameters; -import org.onap.policy.apex.model.basicmodel.service.ParameterService; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; -import org.onap.policy.apex.model.utilities.Assertions; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -import com.google.gson.Gson; -import com.google.gson.JsonSyntaxException; - -/** - * The Class ConcurrentContextMetricsJVM rins in its own JVM to test concurrent context updates and - * lockings across JVMs. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public final class ConcurrentContextMetricsJVM { - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ConcurrentContextMetricsJVM.class); - - private static final int NUM_ARGS = 6; - private static final int ARG_JVM_NO = 1; - private static final int ARG_THREAD_COUNT = 2; - private static final int ARG_ITERATIONS = 3; - private static final int ARG_ARRAY_SIZE = 4; - private static final int ARG_LOCK_TYPE = 5; - - private static final int WAIT_10_MS = 10; - - /** - * The Constructor for this class. - * - * @param testType the test type - * @param jvmNo the jvm no - * @param threadCount the thread count - * @param threadLoops the thread loops - * @param longArraySize the long array size - * @param lockType the lock type - * @throws ApexException the apex exception - * @throws IOException the IO exception - */ - private ConcurrentContextMetricsJVM(final String testType, final int jvmNo, final int threadCount, - final int threadLoops, final int longArraySize, final int lockType) throws ApexException, IOException { - LOGGER.debug("starting JVMs and threads . . ."); - - final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); - - // Set up the distributor for this JVM - final AxArtifactKey distributorKey = new AxArtifactKey("ApexDistributor", "0.0.1"); - final Distributor contextDistributor = new DistributorFactory().getDistributor(distributorKey); - - final AxArtifactKey[] usedArtifactStackArray = {new AxArtifactKey("testC-top_" + jvmNo, "0.0.1"), - new AxArtifactKey("testC-next_" + jvmNo, "0.0.1"), new AxArtifactKey("testC-bot_" + jvmNo, "0.0.1")}; - - final AxContextModel testAxContextModel = TestContextAlbumFactory.createLongContextModel(); - contextDistributor.registerModel(testAxContextModel); - final ContextAlbum testContextAlbum = - contextDistributor.createContextAlbum(new AxArtifactKey("LongSameTypeContextAlbum", "0.0.1")); - Assertions.argumentNotNull(testContextAlbum, "testContextAlbum may not be null"); - testContextAlbum.setUserArtifactStack(usedArtifactStackArray); - - final Thread[] threadArray = new Thread[threadCount]; - - for (int t = 0; t < threadCount; t++) { - threadArray[t] = - new Thread(new ConcurrentContextMetricsThread(jvmNo, t, threadLoops, longArraySize, lockType)); - threadArray[t].setName(testType + ":ConcurrentContextMetricsThread_" + jvmNo + "_" + t); - threadArray[t].start(); - LOGGER.debug("started thread " + threadArray[t].getName()); - } - - System.out.println("ReadyToGo"); - while (true) { - final String goLine = bufferedReader.readLine(); - if (!goLine.trim().equals("OffYouGo")) { - throw new IOException("Expected OffYouGo"); - } - break; - } - - boolean allFinished; - do { - allFinished = true; - for (int t = 0; t < threadCount; t++) { - if (threadArray[t].isAlive()) { - allFinished = false; - ThreadUtilities.sleep(WAIT_10_MS); - break; - } - } - } while (!allFinished); - - System.out.println("AllFinished"); - while (true) { - final String goLine = bufferedReader.readLine(); - if (!goLine.trim().equals("FinishItOut")) { - throw new IOException("Expected FinishItOut"); - } - break; - } - - LOGGER.debug("threads finished"); - contextDistributor.clear(); - } - - /** - * The main method. - * - * @param args the args - * @throws JsonSyntaxException the json syntax exception - * @throws ClassNotFoundException the class not found exception - */ - @SuppressWarnings("unchecked") - public static void main(final String[] args) throws JsonSyntaxException, ClassNotFoundException { - if (args.length < NUM_ARGS || (args.length % 2 != 0)) { - LOGGER.error("invalid arguments: " + Arrays.toString(args)); - LOGGER.error( - "usage: ConcurrentContextMetricsJVM testLabel jvmNo threadCount threadLoops longArraySize lockType [parameterKey parameterJson].... "); - return; - } - - int jvmNo = -1; - int threadCount = -1; - int threadLoops = -1; - int longArraySize = -1; - int lockType = -1; - - try { - jvmNo = Integer.parseInt(args[ARG_JVM_NO]); - } catch (final Exception e) { - LOGGER.error("invalid argument jvmNo", e); - return; - } - - try { - threadCount = Integer.parseInt(args[ARG_THREAD_COUNT]); - } catch (final Exception e) { - LOGGER.error("invalid argument threadCount", e); - return; - } - - try { - threadLoops = Integer.parseInt(args[ARG_ITERATIONS]); - } catch (final Exception e) { - LOGGER.error("invalid argument threadLoops", e); - return; - } - - try { - longArraySize = Integer.parseInt(args[ARG_ARRAY_SIZE]); - } catch (final Exception e) { - LOGGER.error("invalid argument longArraySize", e); - return; - } - - try { - lockType = Integer.parseInt(args[ARG_LOCK_TYPE]); - } catch (final Exception e) { - LOGGER.error("invalid argument lockType", e); - return; - } - - for (int p = NUM_ARGS; p < args.length - 1; p += 2) { - @SuppressWarnings("rawtypes") - final Class parametersClass = Class.forName(args[p]); - final AbstractParameters parameters = - (AbstractParameters) new Gson().fromJson(args[p + 1], parametersClass); - ParameterService.registerParameters(parametersClass, parameters); - } - - try { - new ConcurrentContextMetricsJVM(args[0], jvmNo, threadCount, threadLoops, longArraySize, lockType); - } catch (final Exception e) { - LOGGER.error("error running test in JVM", e); - return; - } - } -} diff --git a/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetricsJVMThread.java b/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetricsJVMThread.java deleted file mode 100644 index 64bc0cab6..000000000 --- a/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetricsJVMThread.java +++ /dev/null @@ -1,187 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.metrics; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; - -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.service.AbstractParameters; -import org.onap.policy.apex.model.basicmodel.service.ParameterService; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -import com.google.gson.Gson; - -/** - * The Class ConcurrentContextMetricsJVMThread gets metrics for concurrent use of context. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ConcurrentContextMetricsJVMThread implements Runnable { - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ConcurrentContextMetricsJVMThread.class); - - private final String testType; - private final int jvm; - private final int threadCount; - private final int threadLoops; - private final int longArraySize; - private final int lockType; - - private boolean readyToGo = false; - private boolean allFinished = false; - - private PrintWriter processWriter; - - /** - * The Constructor. - * - * @param testType the test type - * @param jvm the jvm - * @param threadCount the thread count - * @param threadLoops the thread loops - * @param longArraySize the long array size - * @param lockType the lock type - * @throws ApexException the apex exception - */ - public ConcurrentContextMetricsJVMThread(final String testType, final int jvm, final int threadCount, - final int threadLoops, final int longArraySize, final int lockType) throws ApexException { - this.testType = testType; - this.jvm = jvm; - this.threadCount = threadCount; - this.threadLoops = threadLoops; - this.longArraySize = longArraySize; - this.lockType = lockType; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Runnable#run() - */ - @Override - public void run() { - final List commandList = new ArrayList<>(); - commandList.add(System.getProperty("java.home") + System.getProperty("file.separator") + "bin" - + System.getProperty("file.separator") + "java"); - commandList.add("-cp"); - commandList.add(System.getProperty("java.class.path")); - for (final Entry property : System.getProperties().entrySet()) { - if (property.getKey().toString().startsWith("APEX") - || property.getKey().toString().equals("java.net.preferIPv4Stack") - || property.getKey().toString().equals("jgroups.bind_addr")) { - commandList.add("-D" + property.getKey().toString() + "=" + property.getValue().toString()); - } - } - commandList.add("org.onap.policy.apex.plugins.context.metrics.ConcurrentContextMetricsJVM"); - commandList.add(testType); - commandList.add(new Integer(jvm).toString()); - commandList.add(new Integer(threadCount).toString()); - commandList.add(new Integer(threadLoops).toString()); - commandList.add(new Integer(longArraySize).toString()); - commandList.add(new Integer(lockType).toString()); - - for (final Entry, AbstractParameters> parameterServiceEntry : ParameterService.getAll()) { - commandList.add(parameterServiceEntry.getKey().getCanonicalName()); - commandList.add(new Gson().toJson(parameterServiceEntry.getValue())); - } - - LOGGER.info("starting JVM " + jvm); - - // Run the JVM - final ProcessBuilder processBuilder = new ProcessBuilder(commandList); - processBuilder.redirectErrorStream(true); - Process process; - - try { - process = processBuilder.start(); - - final InputStream is = process.getInputStream(); - processWriter = new PrintWriter(process.getOutputStream()); - final InputStreamReader isr = new InputStreamReader(is); - final BufferedReader br = new BufferedReader(isr); - - String line; - - LOGGER.info("JVM Output for command " + commandList + "\n"); - while ((line = br.readLine()) != null) { - LOGGER.info(line); - - if (line.trim().equals("ReadyToGo")) { - readyToGo = true; - } else if (line.trim().equals("AllFinished")) { - allFinished = true; - } - } - - // Wait to get exit value - try { - final int exitValue = process.waitFor(); - LOGGER.info("\n\nJVM " + jvm + " finished, exit value is " + exitValue); - } catch (final InterruptedException e) { - e.printStackTrace(); - } - } catch (final IOException e1) { - e1.printStackTrace(); - } - } - - /** - * Checks if is ready to go. - * - * @return true, if checks if is ready to go - */ - public boolean isReadyToGo() { - return readyToGo; - } - - /** - * Checks if is all finished. - * - * @return true, if checks if is all finished - */ - public boolean isAllFinished() { - return allFinished; - } - - /** - * Off you go. - */ - public void offYouGo() { - processWriter.println("OffYouGo"); - processWriter.flush(); - } - - /** - * Finish it out. - */ - public void finishItOut() { - processWriter.println("FinishItOut"); - processWriter.flush(); - } -} diff --git a/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetricsThread.java b/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetricsThread.java deleted file mode 100644 index e207832c1..000000000 --- a/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetricsThread.java +++ /dev/null @@ -1,170 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.context.metrics; - -import java.util.Random; - -import org.onap.policy.apex.context.ContextAlbum; -import org.onap.policy.apex.context.ContextException; -import org.onap.policy.apex.context.Distributor; -import org.onap.policy.apex.context.impl.distribution.DistributorFactory; -import org.onap.policy.apex.context.test.concepts.TestContextLongItem; -import org.onap.policy.apex.context.test.factory.TestContextAlbumFactory; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class ConcurrentContextMetricsThread gets metrics for concurrent use of context. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ConcurrentContextMetricsThread implements Runnable { - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ConcurrentContextMetricsThread.class); - private final Distributor contextDistributor; - private final int jvm; - private final int instance; - private final int threadLoops; - private final int longArraySize; - private final int lockType; - - /** - * The Constructor. - * - * @param jvm the jvm - * @param instance the instance - * @param threadLoops the thread loops - * @param longArraySize the long array size - * @param lockType the lock type - * @throws ApexException the apex exception - */ - public ConcurrentContextMetricsThread(final int jvm, final int instance, final int threadLoops, - final int longArraySize, final int lockType) throws ApexException { - this.jvm = jvm; - this.instance = instance; - this.threadLoops = threadLoops; - this.longArraySize = longArraySize; - this.lockType = lockType; - - final AxArtifactKey distributorKey = new AxArtifactKey("ApexDistributor_" + jvm + "_" + instance, "0.0.1"); - contextDistributor = new DistributorFactory().getDistributor(distributorKey); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Runnable#run() - */ - @Override - public void run() { - LOGGER.info("running ConcurrentContextMetricsThread_" + jvm + "_" + instance + " . . ."); - - ContextAlbum lTypeAlbum = null; - try { - final AxContextModel axTestContextModel = TestContextAlbumFactory.createMultiAlbumsContextModel(); - contextDistributor.registerModel(axTestContextModel); - lTypeAlbum = contextDistributor.createContextAlbum(new AxArtifactKey("LTypeContextAlbum", "0.0.1")); - } catch (final Exception e) { - LOGGER.error("could not get the test context album", e); - LOGGER.error("failed ConcurrentContextMetricsThread_" + jvm + "_" + instance); - return; - } - - if (lTypeAlbum == null) { - LOGGER.error("could not find the test context album"); - LOGGER.error("failed ConcurrentContextMetricsThread_" + jvm + "_" + instance); - return; - } - - final AxArtifactKey[] usedArtifactStackArray = - {new AxArtifactKey("testCC-top", "0.0.1"), new AxArtifactKey("testCC-" + instance, "0.0.1")}; - - lTypeAlbum.setUserArtifactStack(usedArtifactStackArray); - - final Random rand = new Random(); - - for (int i = 0; i < threadLoops; i++) { - // Get the next random entry to use - final String nextLongKey = Integer.toString(rand.nextInt(longArraySize)); - - if (lockType == 0) { - final TestContextLongItem item = (TestContextLongItem) lTypeAlbum.get(nextLongKey); - final long value = item.getLongValue(); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("lock type=" + lockType + ", value=" + value); - } - continue; - } - - if (lockType == 1) { - try { - lTypeAlbum.lockForReading(nextLongKey); - } catch (final ContextException e) { - LOGGER.error("could not acquire read lock on context album, key=" + nextLongKey, e); - continue; - } - - final TestContextLongItem item = (TestContextLongItem) lTypeAlbum.get(nextLongKey); - final long value = item.getLongValue(); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("lock type=" + lockType + ", value=" + value); - } - - try { - lTypeAlbum.unlockForReading(nextLongKey); - } catch (final ContextException e) { - LOGGER.error("could not release read lock on context album, key=" + nextLongKey, e); - } - - continue; - } - - if (lockType == 2) { - try { - lTypeAlbum.lockForWriting(nextLongKey); - } catch (final ContextException e) { - LOGGER.error("could not acquire write lock on context album, key=" + nextLongKey, e); - continue; - } - - final TestContextLongItem item = (TestContextLongItem) lTypeAlbum.get(nextLongKey); - long value = item.getLongValue(); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("lock type=" + lockType + ", value=" + value); - } - item.setLongValue(++value); - lTypeAlbum.put(nextLongKey, item); - - try { - lTypeAlbum.unlockForWriting(nextLongKey); - } catch (final ContextException e) { - LOGGER.error("could not release write lock on context album, key=" + nextLongKey, e); - } - continue; - } - } - - LOGGER.info("completed ConcurrentContextMetricsThread_" + jvm + "_" + instance); - } -} 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 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(); } } } diff --git a/testsuites/performance/performance-context-metrics/src/test/resources/hazelcast/hazelcast.xml b/testsuites/performance/performance-context-metrics/src/test/resources/hazelcast/hazelcast.xml index 84da4951e..b70bdc36e 100644 --- a/testsuites/performance/performance-context-metrics/src/test/resources/hazelcast/hazelcast.xml +++ b/testsuites/performance/performance-context-metrics/src/test/resources/hazelcast/hazelcast.xml @@ -19,625 +19,45 @@ ============LICENSE_END========================================================= --> - - - HazelcastGroup3.0EVAL - password3.0EVAL - - - 5706 - - - 224.2.2.10 - 54327 - - - 10.0.0.0 - - - - + + + HazelcastGroup3.0EVAL + password3.0EVAL + + + 5706 + + + 224.2.2.10 + 54327 + + + 127.0.0.1 + + + - 127.0.0.* - - - - true - slf4j + 127.0.0.* + + + + false + slf4j - false - 60 - - - 16 - - - - 100000 - - - - - 1 - - NONE - - 0 - - 25 - - - - 1 - - LRU - - 1000000 - - 5 - - - 0 - - - - - - - - 1 - - LRU - - 1000000 - - 5 - - - 7200 - - - - - - - 1 - - LRU - - 1000000 - - 5 - - - 3600 - - - - - - - - - 1 - - LRU - - 1000000 - - 5 - - - 7200 - - - - - - - - - - 1 - - - true - - LRU - - 3000000 - - 5 - - - 7200 - - - - - - - - - - - 2 - - NONE - - 10000000 - - 0 - - - - 0 - - - - - - - - - - 0 - - - 0 - - - NONE - - - 2000 - - - true - - - - - - - - - - 1 - - NONE - - 10000000 - - 0 - - - - 60 - - - - - - - 2 - - 0 - - - - NONE - - 1000 - - - - 0 - - - - - 2 - - 0 - - - - NONE - - 10000 - - - 0 - - - - - - - 2 - - NONE - - 10000000 - - 0 - - - - 0 - - - - - - - - - - 2 - - NONE - - 10000000 - - 0 - - - - 0 - - - - - - - - - - - 1 - - - true - - LRU - - 3000000 - - 5 - - - 7200 - - - - - - - - - - 100000 - - - - - 0 - - - - - 2 - NONE - 50 - 0 - 0 - - - - - 0 - 100000 - - - - - 3 - - true - - NONE - - 1000 - - 0 - - - - - 0 - - - - 3 - - true - - NONE - - 1000 - - 0 - - - - - 0 - - - - 100000 - - - - - 1 - NONE - 0 - - + false + 60 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + + + 2 + diff --git a/testsuites/performance/performance-context-metrics/src/test/resources/infinispan/default-jgroups-tcp.xml b/testsuites/performance/performance-context-metrics/src/test/resources/infinispan/default-jgroups-tcp.xml new file mode 100644 index 000000000..028cf1df6 --- /dev/null +++ b/testsuites/performance/performance-context-metrics/src/test/resources/infinispan/default-jgroups-tcp.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + diff --git a/testsuites/performance/performance-context-metrics/src/test/resources/infinispan/infinispan.xml b/testsuites/performance/performance-context-metrics/src/test/resources/infinispan/infinispan.xml index a8541333e..46722477a 100644 --- a/testsuites/performance/performance-context-metrics/src/test/resources/infinispan/infinispan.xml +++ b/testsuites/performance/performance-context-metrics/src/test/resources/infinispan/infinispan.xml @@ -23,7 +23,7 @@ - + -- cgit 1.2.3-korg