From cd68fc9bae7d6258f77ff59c1431e4f925f61a4c Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 13 Sep 2018 23:48:50 +0100 Subject: Address sonar/Checkstyle Issues Sweep through Apex codebase to fix most ceheckstyle and straightforward sonar issues. Issue-ID: POLICY-1034 Change-Id: I149d9a94ad893affc93573e8de5e3304b6bdde2d Signed-off-by: liamfallon --- .../engine/benchmark/ApexBaseBenchMarkTest.java | 139 ------ .../engine/benchmark/ApexEngineBenchmark.java | 137 ------ .../engine/benchmark/TestApexEventListener.java | 92 ---- .../policy/apex/service/engine/main/BaseTest.java | 120 ------ .../service/engine/main/TestAsyncEventMIMO.java | 36 -- .../service/engine/main/TestAsyncEventMISO.java | 33 -- .../service/engine/main/TestAsyncEventSIMO.java | 36 -- .../service/engine/main/TestAsyncEventSISO.java | 33 -- .../service/engine/main/TestSyncEventMIMO.java | 36 -- .../service/engine/main/TestSyncEventSISO.java | 33 -- .../engine/runtime/ApexServiceModelUpdateTest.java | 363 ---------------- .../service/engine/runtime/ApexServiceTest.java | 474 -------------------- .../policy/apex/service/engine/utils/Utils.java | 40 -- .../engine/benchmark/ApexBaseBenchMarkTest.java | 175 ++++++++ .../engine/benchmark/ApexEngineBenchmark.java | 183 ++++++++ .../engine/benchmark/TestApexEventListener.java | 126 ++++++ .../benchmark/engine/main/BaseTest.java | 122 ++++++ .../benchmark/engine/main/TestAsyncEventMimo.java | 43 ++ .../benchmark/engine/main/TestAsyncEventMiso.java | 33 ++ .../benchmark/engine/main/TestAsyncEventSimo.java | 43 ++ .../benchmark/engine/main/TestAsyncEventSiso.java | 33 ++ .../benchmark/engine/main/TestSyncEventMimo.java | 43 ++ .../benchmark/engine/main/TestSyncEventSiso.java | 33 ++ .../engine/runtime/ApexServiceModelUpdateTest.java | 362 ++++++++++++++++ .../benchmark/engine/runtime/ApexServiceTest.java | 477 +++++++++++++++++++++ .../performance/benchmark/engine/utils/Utils.java | 55 +++ .../context/metrics/ConcurrentContextMetrics.java | 322 -------------- .../apex/plugins/context/metrics/package-info.java | 27 -- .../context/metrics/ConcurrentContextMetrics.java | 323 ++++++++++++++ .../performance/context/metrics/package-info.java | 27 ++ .../apex/plugins/context/metrics/TestMetrics.java | 80 ---- .../performance/context/metrics/TestMetrics.java | 94 ++++ 32 files changed, 2172 insertions(+), 2001 deletions(-) delete mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/ApexBaseBenchMarkTest.java delete mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/ApexEngineBenchmark.java delete mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/TestApexEventListener.java delete mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/BaseTest.java delete mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventMIMO.java delete mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventMISO.java delete mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventSIMO.java delete mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventSISO.java delete mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestSyncEventMIMO.java delete mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestSyncEventSISO.java delete mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/runtime/ApexServiceModelUpdateTest.java delete mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/runtime/ApexServiceTest.java delete mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/utils/Utils.java create mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexBaseBenchMarkTest.java create mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexEngineBenchmark.java create mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/TestApexEventListener.java create mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/BaseTest.java create mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventMimo.java create mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventMiso.java create mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventSimo.java create mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventSiso.java create mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestSyncEventMimo.java create mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestSyncEventSiso.java create mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/runtime/ApexServiceModelUpdateTest.java create mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/runtime/ApexServiceTest.java create mode 100644 testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/utils/Utils.java delete mode 100644 testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetrics.java delete mode 100644 testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/package-info.java create mode 100644 testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/testsuites/performance/context/metrics/ConcurrentContextMetrics.java create mode 100644 testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/testsuites/performance/context/metrics/package-info.java delete mode 100644 testsuites/performance/performance-context-metrics/src/test/java/org/onap/policy/apex/plugins/context/metrics/TestMetrics.java create mode 100644 testsuites/performance/performance-context-metrics/src/test/java/org/onap/policy/apex/testsuites/performance/context/metrics/TestMetrics.java (limited to 'testsuites/performance') diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/ApexBaseBenchMarkTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/ApexBaseBenchMarkTest.java deleted file mode 100644 index 43211bc73..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/ApexBaseBenchMarkTest.java +++ /dev/null @@ -1,139 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 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.service.engine.benchmark; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters; -import org.onap.policy.apex.context.parameters.ContextParameters; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.core.engine.EngineParameters; -import org.onap.policy.apex.core.engine.ExecutorParameters; -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.plugins.context.schema.avro.AvroSchemaHelperParameters; -import org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters; -import org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters; -import org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters; -import org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters; -import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; -import org.onap.policy.apex.service.engine.event.ApexEvent; -import org.onap.policy.apex.service.engine.runtime.ApexEventListener; -import org.onap.policy.apex.service.engine.runtime.ApexServiceModelUpdateTest; -import org.onap.policy.apex.service.engine.runtime.EngineService; -import org.onap.policy.apex.service.engine.runtime.EngineServiceEventInterface; -import org.onap.policy.apex.service.engine.runtime.impl.EngineServiceImpl; -import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -public class ApexBaseBenchMarkTest { - private static final long STOP_TIME_OUT = TimeUnit.SECONDS.toMillis(30); - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexServiceModelUpdateTest.class); - private static final long MAX_START_WAIT = TimeUnit.SECONDS.toMillis(10); - private final AxArtifactKey engineServiceKey = new AxArtifactKey("Machine-1_process-1_engine-1", "0.0.0"); - private final String model; - private final int threads; - private final ApexEventListener listener; - private EngineService service; - private EngineServiceEventInterface engineServiceEventInterface; - - - public ApexBaseBenchMarkTest(final String model, final int threads, final ApexEventListener listener) { - this.model = model; - this.threads = threads; - this.listener = listener; - } - - public void setUp() throws Exception { - final EngineServiceParameters parameters = new EngineServiceParameters(); - parameters.setInstanceCount(threads); - parameters.setName(engineServiceKey.getName()); - parameters.setVersion(engineServiceKey.getVersion()); - parameters.setId(100); - - final EngineParameters engineParameters = parameters.getEngineParameters(); - final Map executorParameterMap = engineParameters.getExecutorParameterMap(); - executorParameterMap.put("MVEL", new MvelExecutorParameters()); - executorParameterMap.put("JAVASCRIPT", new JavascriptExecutorParameters()); - executorParameterMap.put("JYTHON", new JythonExecutorParameters()); - executorParameterMap.put("JAVA", new JavaExecutorParameters()); - executorParameterMap.put("JRUBY", new JrubyExecutorParameters()); - - final ContextParameters contextParameters = engineParameters.getContextParameters(); - final SchemaParameters schemaParameters = contextParameters.getSchemaParameters(); - schemaParameters.getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); - schemaParameters.getSchemaHelperParameterMap().put("Java", new JavaSchemaHelperParameters()); - service = EngineServiceImpl.create(parameters); - - service = EngineServiceImpl.create(parameters); - service.registerActionListener("listener", listener); - service.updateModel(parameters.getEngineKey(), model, true); - - LOGGER.info("Starting EngineService ... "); - service.startAll(); - - final long starttime = System.currentTimeMillis(); - while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { - ThreadUtilities.sleep(50); - } - if (!service.isStarted()) { - LOGGER.error("Apex Service {} failed to start after {} ms", service.getKey(), MAX_START_WAIT); - new ApexException("Unable to start engine service "); - } - - engineServiceEventInterface = service.getEngineServiceEventInterface(); - } - - public void sendEvents(final List events) { - for (final ApexEvent event : events) { - engineServiceEventInterface.sendEvent(event); - } - } - - public void sendEvent(final ApexEvent event) { - engineServiceEventInterface.sendEvent(event); - } - - - public EngineService getService() { - return service; - } - - public void destroy() throws Exception { - if (service != null) { - LOGGER.info("Stopping EngineService ... "); - service.stop(); - final long currentTimeInMillSec = System.currentTimeMillis(); - while (!service.isStopped()) { - if (System.currentTimeMillis() - currentTimeInMillSec > STOP_TIME_OUT) { - LOGGER.warn("Timed Out EngineService status: ", service.isStopped()); - break; - } - ThreadUtilities.sleep(500); - } - service = null; - } - } - -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/ApexEngineBenchmark.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/ApexEngineBenchmark.java deleted file mode 100644 index d7a4ef800..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/ApexEngineBenchmark.java +++ /dev/null @@ -1,137 +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.service.engine.benchmark; - -import static org.junit.Assert.assertEquals; - -import java.util.concurrent.TimeUnit; - -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; -import org.onap.policy.apex.service.engine.event.ApexEvent; -import org.onap.policy.apex.service.engine.utils.Utils; -import org.onap.policy.apex.test.common.model.EvalDomainModelFactory; -import org.python.icu.impl.Assert; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class ApexEngineBenchmark. - */ -public class ApexEngineBenchmark { - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEngineBenchmark.class); - - private static final String TARGET = "apex"; - private static final String SOURCE = "test"; - private static final String NAME = "Event0000"; - private static final String VERSION = "0.0.1"; - private static final String PACKAGE = "org.onap.policy.apex.domains.sample.events"; - - private static final long TIME_OUT_IN_MILLISEC = TimeUnit.MINUTES.toMillis(1); - - private String apexECAModelString; - private String apexOODAModelString; - - @Before - public void setUp() throws Exception { - apexECAModelString = Utils.getModelString(new EvalDomainModelFactory().getECAPolicyModel()); - apexOODAModelString = Utils.getModelString(new EvalDomainModelFactory().getOODAPolicyModel()); - } - - @Test - public void testBenchmark_SingletonWorker() throws Exception { - executeTest(apexECAModelString, 100, 1, 20); - executeTest(apexOODAModelString, 100, 1, 20); - } - - @Test - public void testBenchmark_3ThreadWorker() throws Exception { - executeTest(apexECAModelString, 1000, 3, 10); - executeTest(apexOODAModelString, 100, 3, 10); - } - - @Test - public void testBenchmark_10ThreadWorker() throws Exception { - executeTest(apexECAModelString, 2000, 10, 10); - executeTest(apexOODAModelString, 2000, 10, 10); - } - - @Test - public void testBenchmark_50ThreadWorker() throws Exception { - executeTest(apexECAModelString, 3000, 50, 10); - executeTest(apexOODAModelString, 3000, 50, 10); - } - - @Test - public void TestE_AvailableProcessorsThreadWorker() throws Exception { - final int cores = Runtime.getRuntime().availableProcessors(); - executeTest(apexECAModelString, 3000, cores, 10); - executeTest(apexOODAModelString, 3000, cores, 10); - } - - private void executeTest(final String policyModel, final int eventsCount, final int threads, final int loop) - throws Exception { - - LOGGER.info("Running Test with Event count: {}, Instance count: {} and loop: {}", eventsCount, threads, loop); - final TestApexEventListener apexEventListener = new TestApexEventListener(); - - final ApexBaseBenchMarkTest apexBaseBenchMarkTest = - new ApexBaseBenchMarkTest(policyModel, threads, apexEventListener); - - try { - apexBaseBenchMarkTest.setUp(); - for (int i = 0; i < loop; i++) { - sendEvents(apexBaseBenchMarkTest, eventsCount); - final long currentTimeInMillSec = System.currentTimeMillis(); - while (apexEventListener.getEventReceived() < eventsCount) { - if (System.currentTimeMillis() - currentTimeInMillSec > TIME_OUT_IN_MILLISEC) { - LOGGER.warn("Wait timed out ... "); - break; - } - ThreadUtilities.sleep(500); - } - assertEquals(eventsCount, apexEventListener.getEventReceived()); - apexEventListener.printResult(); - apexEventListener.reset(); - } - } catch (final Exception exception) { - Assert.fail(exception); - } finally { - apexBaseBenchMarkTest.destroy(); - LOGGER.info("Finished Running Test with Event count: {}, Instance count: {} and loop: {}", eventsCount, - threads, loop); - } - } - - public void sendEvents(final ApexBaseBenchMarkTest apexBaseBenchMarkTest, final int eventsCount) throws Exception { - for (int eventNum = 0; eventNum < eventsCount; eventNum++) { - final long currentTimeMillis = System.currentTimeMillis(); - final ApexEvent event = new ApexEvent(NAME, VERSION, PACKAGE, SOURCE, TARGET); - event.put("TestTemperature", eventNum); - event.put("FirstEventTimestamp", currentTimeMillis); - event.put("SentTimestamp", currentTimeMillis); - event.put("EventNumber", eventNum); - apexBaseBenchMarkTest.sendEvent(event); - } - } -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/TestApexEventListener.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/TestApexEventListener.java deleted file mode 100644 index b2de8f072..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/benchmark/TestApexEventListener.java +++ /dev/null @@ -1,92 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 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.service.engine.benchmark; - -import static org.junit.Assert.assertNull; - -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.atomic.AtomicLong; - -import org.onap.policy.apex.service.engine.event.ApexEvent; -import org.onap.policy.apex.service.engine.runtime.ApexEventListener; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -public class TestApexEventListener implements ApexEventListener { - - private static final String SENT_TIMESTAMP = "SentTimestamp"; - private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestApexEventListener.class); - private static final String RECVD_TIMESTAMP = "RecvdTimestamp"; - private Queue queue; - - private final AtomicLong eventReceived = new AtomicLong(); - - public TestApexEventListener() { - this.queue = new ConcurrentLinkedQueue(); - } - - @Override - public void onApexEvent(final ApexEvent apexEvent) { - apexEvent.put(RECVD_TIMESTAMP, System.currentTimeMillis()); - eventReceived.incrementAndGet(); - queue.add(apexEvent); - } - - public void printResult() { - if (!queue.isEmpty()) { - long maxTimeInMilliSeconds = 0; - long minTimeInMilliSeconds = Long.MAX_VALUE; - final long numEvents = queue.size(); - long totalTimeInMilliSeconds = 0; - for (final ApexEvent apexEvent : queue) { - assertNull(apexEvent.getExceptionMessage()); - final Long endTimeInMilliSeconds = (Long) apexEvent.get(RECVD_TIMESTAMP); - final Long startTimeInMilliSeconds = (Long) apexEvent.get(SENT_TIMESTAMP); - final long timeTaken = endTimeInMilliSeconds - startTimeInMilliSeconds; - totalTimeInMilliSeconds += timeTaken; - if (timeTaken > maxTimeInMilliSeconds) { - maxTimeInMilliSeconds = timeTaken; - } - if (timeTaken < minTimeInMilliSeconds) { - minTimeInMilliSeconds = timeTaken; - } - } - LOGGER.info("Average Time Taken to process {} events: {} ms", numEvents, - (totalTimeInMilliSeconds / numEvents)); - LOGGER.info("Max Time Taken: {} ms", maxTimeInMilliSeconds); - LOGGER.info("Min Time Taken: {} ms", minTimeInMilliSeconds); - } - } - - public void reset() { - this.queue = new ConcurrentLinkedQueue(); - eventReceived.set(0);; - } - - public Queue getQueue() { - return queue; - } - - public long getEventReceived() { - return eventReceived.get(); - } - -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/BaseTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/BaseTest.java deleted file mode 100644 index d38107daf..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/BaseTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 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.service.engine.main; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.concurrent.TimeUnit; - -import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; -import org.onap.policy.apex.model.utilities.TextFileUtils; - -public class BaseTest { - protected final static long TIME_OUT_IN_MS = TimeUnit.SECONDS.toMillis(10); - - protected long getFileLength(final String file, final long expectedFileSize) throws IOException { - return getFileLength(10, file, expectedFileSize); - } - - protected long getFileLength(final int loopTime, final String file, final long expectedFileSize) - throws IOException { - long length = 0; - for (int i = 0; i < loopTime; i++) { - final String fileString = TextFileUtils.getTextFileAsString(file).replaceAll("\\s+", ""); - length = fileString.length(); - if (length > 0 && length >= expectedFileSize) { - break; - } - ThreadUtilities.sleep(500); - } - return length; - } - - protected void waitForOutFiles(final File... files) { - final long timeInMillis = System.currentTimeMillis(); - while (!isFilesExist(files)) { - if (System.currentTimeMillis() - timeInMillis > TIME_OUT_IN_MS) { - break; - } - ThreadUtilities.sleep(500); - } - - } - - private void assertFilesExists(final File... files) { - for (final File file : files) { - assertTrue("Test failed, the output " + file + "event file was not created", file.exists()); - } - } - - private void deleteFiles(final File... files) throws IOException { - for (final File file : files) { - Files.deleteIfExists(file.toPath()); - } - } - - private boolean isFilesExist(final File[] files) { - for (final File file : files) { - if (!file.exists()) { - return false; - } - } - return true; - } - - protected File[] toFile(final String[] filesPath) { - if (filesPath == null || filesPath.length == 0) { - return new File[] {}; - } - final File[] files = new File[filesPath.length]; - - for (int index = 0; index < filesPath.length; index++) { - files[index] = new File(filesPath[index]); - } - - return files; - } - - protected void testFileEvents(final String[] args, final String[] expectedFilesPath, final long expectedFileSize) - throws Exception { - final ApexMain apexMain = new ApexMain(args); - - final File[] expectedFiles = toFile(expectedFilesPath); - try { - - waitForOutFiles(expectedFiles); - assertFilesExists(expectedFiles); - - for (final String filePath : expectedFilesPath) { - assertEquals(expectedFileSize, getFileLength(filePath, expectedFileSize)); - } - - apexMain.shutdown(); - - } finally { - deleteFiles(expectedFiles); - } - } - -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventMIMO.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventMIMO.java deleted file mode 100644 index 714deba30..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventMIMO.java +++ /dev/null @@ -1,36 +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.service.engine.main; - -import org.junit.Test; - -public class TestAsyncEventMIMO extends BaseTest { - - @Test - public void testJsonFileAsyncMIMO() throws Exception { - final String[] args = {"-c", "src/test/resources/parameters/File2FileJsonEventAsyncMIMO.json"}; - final String[] outFilePaths = {"src/test/resources/events/EventsOutMulti0.json", - "src/test/resources/events/EventsOutMulti1.json", "src/test/resources/events/EventsOutMulti2.json"}; - - testFileEvents(args, outFilePaths, 48956 * 3); - } - -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventMISO.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventMISO.java deleted file mode 100644 index c5e7f4d9c..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventMISO.java +++ /dev/null @@ -1,33 +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.service.engine.main; - -import org.junit.Test; - -public class TestAsyncEventMISO extends BaseTest { - - @Test - public void testJsonFileAsyncMISO() throws Exception { - final String[] args = {"-c", "src/test/resources/parameters/File2FileJsonEventAsyncMISO.json"}; - - testFileEvents(args, new String[] {"src/test/resources/events/EventsOutSingle.json"}, 48956 * 3); - } -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventSIMO.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventSIMO.java deleted file mode 100644 index 0f570679a..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventSIMO.java +++ /dev/null @@ -1,36 +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.service.engine.main; - -import org.junit.Test; - -public class TestAsyncEventSIMO extends BaseTest { - - @Test - public void testJsonFileAsyncSIMO() throws Exception { - final String[] args = {"-c", "src/test/resources/parameters/File2FileJsonEventAsyncSIMO.json"}; - final String[] outFilePaths = {"src/test/resources/events/EventsOutMulti0.json", - "src/test/resources/events/EventsOutMulti1.json", "src/test/resources/events/EventsOutMulti2.json"}; - - testFileEvents(args, outFilePaths, 48956); - } - -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventSISO.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventSISO.java deleted file mode 100644 index 4152e20c9..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestAsyncEventSISO.java +++ /dev/null @@ -1,33 +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.service.engine.main; - -import org.junit.Test; - -public class TestAsyncEventSISO extends BaseTest { - - @Test - public void testJsonFileAsyncSISO() throws Exception { - final String[] args = {"-c", "src/test/resources/parameters/File2FileJsonEventAsyncSISO.json"}; - - testFileEvents(args, new String[] {"src/test/resources/events/EventsOutSingle.json"}, 48956); - } -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestSyncEventMIMO.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestSyncEventMIMO.java deleted file mode 100644 index ad1a9810a..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestSyncEventMIMO.java +++ /dev/null @@ -1,36 +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.service.engine.main; - -import org.junit.Test; - -public class TestSyncEventMIMO extends BaseTest { - - @Test - public void testJsonFileAsyncMIMO() throws Exception { - final String[] args = {"-c", "src/test/resources/parameters/File2FileJsonEventSyncMIMO.json"}; - final String[] outFilePaths = {"src/test/resources/events/EventsOutMulti0.json", - "src/test/resources/events/EventsOutMulti1.json", "src/test/resources/events/EventsOutMulti2.json"}; - - testFileEvents(args, outFilePaths, 48956 * 3); - } - -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestSyncEventSISO.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestSyncEventSISO.java deleted file mode 100644 index 395c2fe0b..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/main/TestSyncEventSISO.java +++ /dev/null @@ -1,33 +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.service.engine.main; - -import org.junit.Test; - -public class TestSyncEventSISO extends BaseTest { - - @Test - public void testJsonFileAsyncSISO() throws Exception { - final String[] args = {"-c", "src/test/resources/parameters/File2FileJsonEventSyncSISO.json"}; - - testFileEvents(args, new String[] {"src/test/resources/events/EventsOutSingle.json"}, 48956); - } -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/runtime/ApexServiceModelUpdateTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/runtime/ApexServiceModelUpdateTest.java deleted file mode 100644 index aa95e73b3..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/runtime/ApexServiceModelUpdateTest.java +++ /dev/null @@ -1,363 +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.service.engine.runtime; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -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.ModelService; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; -import org.onap.policy.apex.service.engine.event.ApexEvent; -import org.onap.policy.apex.service.engine.event.ApexEventException; -import org.onap.policy.apex.service.engine.runtime.impl.EngineServiceImpl; -import org.onap.policy.apex.service.engine.utils.Utils; -import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters; -import org.onap.policy.apex.test.common.model.SampleDomainModelFactory; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - - -/** - * The Class ApexServiceTest. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ApexServiceModelUpdateTest { - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexServiceModelUpdateTest.class); - - private final AxArtifactKey engineServiceKey = new AxArtifactKey("Machine-1_process-1_engine-1", "0.0.0"); - private final EngineServiceParameters parameters = new EngineServiceParameters(); - private EngineService service = null; - private TestListener listener = null; - private int actionEventsReceived = 0; - - private AxPolicyModel apexSamplePolicyModel = null; - private String apexSampleModelString; - - /** - * Sets up the test by creating an engine and reading in the test policy. - * - * @throws ApexException if something goes wron - * @throws IOException - */ - @Before - public void setUp() throws ApexException, IOException { - // create engine with 3 threads - parameters.setInstanceCount(3); - parameters.setName(engineServiceKey.getName()); - parameters.setVersion(engineServiceKey.getVersion()); - parameters.setId(100); - parameters.getEngineParameters().getExecutorParameterMap().put("MVEL", new MvelExecutorParameters()); - service = EngineServiceImpl.create(parameters); - - LOGGER.debug("Running TestApexEngine. . ."); - - apexSamplePolicyModel = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); - assertNotNull(apexSamplePolicyModel); - - apexSampleModelString = Utils.getModelString(apexSamplePolicyModel); - - // create engine - listener = new TestListener(); - service.registerActionListener("MyListener", listener); - } - - /** - * Tear down the the test infrastructure. - * - * @throws ApexException if there is an error - */ - @After - public void tearDown() throws Exception { - if (service != null) { - service.stop(); - } - service = null; - } - - /** - * Test start with no model. - */ - @Test - public void testNoModelStart() { - try { - service.startAll(); - fail("Engine should not start with no model"); - } catch (final Exception e) { - e.printStackTrace(); - assertEquals("start()<-Machine-1_process-1_engine-1-0:0.0.0,STOPPED, cannot start engine, " - + "engine has not been initialized, its model is not loaded", e.getMessage()); - } - } - - /** - * Test model update with string model without force. - * - * @throws ApexException if there is an error - */ - @Test - public void testModelUpdateStringNewNoForce() throws ApexException { - service.updateModel(parameters.getEngineKey(), apexSampleModelString, false); - service.startAll(); - assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); - } - - /** - * Test model update with string model with force. - * - * @throws ApexException if there is an error - */ - @Test - public void testModelUpdateStringNewForce() throws ApexException { - service.updateModel(parameters.getEngineKey(), apexSampleModelString, true); - service.startAll(); - assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); - } - - /** - * Test model update with a new string model without force. - * - * @throws ApexException if there is an error - */ - @Test - public void testModelUpdateStringNewNewNoForce() throws ApexException { - service.updateModel(parameters.getEngineKey(), apexSampleModelString, false); - service.startAll(); - assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); - - sendEvents(); - - service.updateModel(parameters.getEngineKey(), apexSampleModelString, false); - assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); - - sendEvents(); - } - - /** - * Test incompatible model update with a model object without force. - * - * @throws ApexException if there is an error - */ - @Test - public void testModelUpdateIncoNoForce() throws ApexException { - service.updateModel(parameters.getEngineKey(), apexSamplePolicyModel, false); - service.startAll(); - assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); - - // Different model name, incompatible - final AxPolicyModel incoPolicyModel0 = new AxPolicyModel(apexSamplePolicyModel); - incoPolicyModel0.getKey().setName("INCOMPATIBLE"); - - try { - service.updateModel(parameters.getEngineKey(), incoPolicyModel0, false); - fail("model update should fail on incompatible model without force being true"); - } catch (final Exception e) { - System.err.println(e.getMessage()); - assertEquals( - "apex model update failed, supplied model with key \"INCOMPATIBLE:0.0.1\" is not a compatible " - + "model update from the existing engine model with key \"SamplePolicyModelMVEL:0.0.1\"", - e.getMessage()); - } - - // Still on old model - sendEvents(); - - // Different major version, incompatible - final AxPolicyModel incoPolicyModel1 = new AxPolicyModel(apexSamplePolicyModel); - incoPolicyModel1.getKey().setVersion("1.0.1"); - - try { - service.updateModel(parameters.getEngineKey(), incoPolicyModel1, false); - fail("model update should fail on incompatible model without force being true"); - } catch (final Exception e) { - System.err.println(e.getMessage()); - e.printStackTrace(); - assertEquals( - "apex model update failed, supplied model with key \"SamplePolicyModelMVEL:1.0.1\" is not a compatible " - + "model update from the existing engine model with key \"SamplePolicyModelMVEL:0.0.1\"", - e.getMessage()); - } - - // Still on old model - sendEvents(); - - // Different minor version, compatible - final AxPolicyModel coPolicyModel0 = new AxPolicyModel(apexSamplePolicyModel); - coPolicyModel0.getKey().setVersion("0.1.0"); - service.updateModel(parameters.getEngineKey(), coPolicyModel0, false); - - // On new compatible model - sendEvents(); - - // Different patch version, compatible - final AxPolicyModel coPolicyModel1 = new AxPolicyModel(apexSamplePolicyModel); - coPolicyModel1.getKey().setVersion("0.0.2"); - service.updateModel(parameters.getEngineKey(), coPolicyModel1, false); - - // On new compatible model - sendEvents(); - - } - - /** - * Test incompatible model update with a model object with force. - * - * @throws ApexException if there is an error - */ - @Test - public void testModelUpdateIncoForce() throws ApexException { - service.updateModel(parameters.getEngineKey(), apexSamplePolicyModel, false); - service.startAll(); - assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); - - // Different model name, incompatible - final AxPolicyModel incoPolicyModel0 = new AxPolicyModel(apexSamplePolicyModel); - incoPolicyModel0.getKey().setName("INCOMPATIBLE"); - service.updateModel(parameters.getEngineKey(), incoPolicyModel0, true); - - // On updated model - sendEvents(); - - // Different major version, incompatible - final AxPolicyModel incoPolicyModel1 = new AxPolicyModel(apexSamplePolicyModel); - incoPolicyModel1.getKey().setVersion("1.0.1"); - service.updateModel(parameters.getEngineKey(), incoPolicyModel1, true); - - // On updated model - sendEvents(); - - // Different minor version, compatible - final AxPolicyModel coPolicyModel0 = new AxPolicyModel(apexSamplePolicyModel); - coPolicyModel0.getKey().setVersion("0.1.0"); - service.updateModel(parameters.getEngineKey(), coPolicyModel0, true); - - // On new compatible model - sendEvents(); - - // Different patch version, compatible - final AxPolicyModel coPolicyModel1 = new AxPolicyModel(apexSamplePolicyModel); - coPolicyModel1.getKey().setVersion("0.0.2"); - service.updateModel(parameters.getEngineKey(), coPolicyModel1, true); - - // On new compatible model - sendEvents(); - - } - - /** - * Utility method to send some events into the test engine. - * - * @throws ApexEventException if there is an error - */ - private void sendEvents() throws ApexEventException { - final EngineServiceEventInterface engineServiceEventInterface = service.getEngineServiceEventInterface(); - - // Send some events - final Date testStartTime = new Date(); - final Map eventDataMap = new HashMap(); - eventDataMap.put("TestSlogan", "This is a test slogan"); - eventDataMap.put("TestMatchCase", (byte) 123); - eventDataMap.put("TestTimestamp", testStartTime.getTime()); - eventDataMap.put("TestTemperature", 34.5445667); - - final ApexEvent event = - new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); - event.putAll(eventDataMap); - engineServiceEventInterface.sendEvent(event); - - final ApexEvent event2 = - new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); - event2.putAll(eventDataMap); - engineServiceEventInterface.sendEvent(event2); - - // Wait for results - while (actionEventsReceived < 2) { - ThreadUtilities.sleep(100); - } - ThreadUtilities.sleep(500); - } - - /** - * The listener interface for receiving test events. The class that is interested in processing - * a test event implements this interface, and the object created with that class is registered - * with a component using the component's addTestListener method. When the test - * event occurs, that object's appropriate method is invoked. - * - * @see TestEvent - */ - private final class TestListener implements ApexEventListener { - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.service.engine.runtime.ApexEventListener#onApexEvent(org.onap.policy - * .apex.service.engine.event.ApexEvent) - */ - @Override - public synchronized void onApexEvent(final ApexEvent event) { - LOGGER.debug("result 1 is:" + event); - checkResult(event); - actionEventsReceived++; - - final Date testStartTime = new Date((Long) event.get("TestTimestamp")); - final Date testEndTime = new Date(); - - LOGGER.info("policy execution time: " + (testEndTime.getTime() - testStartTime.getTime()) + "ms"); - } - - /** - * Check result. - * - * @param result the result - */ - private void checkResult(final ApexEvent result) { - assertTrue(result.getName().startsWith("Event0004") || result.getName().startsWith("Event0104")); - - assertTrue(result.get("TestSlogan").equals("This is a test slogan")); - assertTrue(result.get("TestMatchCase").equals(new Byte((byte) 123))); - assertTrue(result.get("TestTemperature").equals(34.5445667)); - assertTrue(((byte) result.get("TestMatchCaseSelected")) >= 0 - && ((byte) result.get("TestMatchCaseSelected") <= 3)); - assertTrue(((byte) result.get("TestEstablishCaseSelected")) >= 0 - && ((byte) result.get("TestEstablishCaseSelected") <= 3)); - assertTrue(((byte) result.get("TestDecideCaseSelected")) >= 0 - && ((byte) result.get("TestDecideCaseSelected") <= 3)); - assertTrue( - ((byte) result.get("TestActCaseSelected")) >= 0 && ((byte) result.get("TestActCaseSelected") <= 3)); - } - } -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/runtime/ApexServiceTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/runtime/ApexServiceTest.java deleted file mode 100644 index c178cd9aa..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/runtime/ApexServiceTest.java +++ /dev/null @@ -1,474 +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.service.engine.runtime; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -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.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; -import org.onap.policy.apex.service.engine.event.ApexEvent; -import org.onap.policy.apex.service.engine.runtime.impl.EngineServiceImpl; -import org.onap.policy.apex.service.engine.utils.Utils; -import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters; -import org.onap.policy.apex.test.common.model.SampleDomainModelFactory; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class ApexServiceTest. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ApexServiceTest { - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexServiceTest.class); - - private static final long MAX_STOP_WAIT = 5000; // 5 sec - private static final long MAX_START_WAIT = 5000; // 5 sec - private static final long MAX_RECV_WAIT = 5000; // 5 sec - - private static final AxArtifactKey engineServiceKey = new AxArtifactKey("Machine-1_process-1_engine-1", "0.0.0"); - private static final EngineServiceParameters parameters = new EngineServiceParameters(); - private static EngineService service = null; - private static TestListener listener = null; - private static AxPolicyModel apexPolicyModel = null; - private static int actionEventsReceived = 0; - - private static String apexModelString; - - private boolean waitFlag = true; - - /** - * Sets the up. - * - * @throws Exception the exception - */ - @BeforeClass - public static void setUp() throws Exception { - // create engine with 3 threads - parameters.setInstanceCount(3); - parameters.setName(engineServiceKey.getName()); - parameters.setVersion(engineServiceKey.getVersion()); - parameters.setId(100); - parameters.getEngineParameters().getExecutorParameterMap().put("MVEL", new MvelExecutorParameters()); - service = EngineServiceImpl.create(parameters); - - - LOGGER.debug("Running TestApexEngine. . ."); - - apexPolicyModel = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); - assertNotNull(apexPolicyModel); - - apexModelString = Utils.getModelString(apexPolicyModel); - - // create engine - listener = new TestListener(); - service.registerActionListener("Listener", listener); - } - - /** - * Update the engine then test the engine with 2 sample events. - * - * @throws ApexException if there is a problem - */ - @Test - public void testExecutionSet1() throws ApexException { - service.updateModel(parameters.getEngineKey(), apexModelString, true); - // Start the service - service.startAll(); - final long starttime = System.currentTimeMillis(); - for (final AxArtifactKey engineKey : service.getEngineKeys()) { - LOGGER.info("{}", service.getStatus(engineKey)); - } - while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { - ThreadUtilities.sleep(200); - } - if (!service.isStarted()) { - fail("Apex Service " + service.getKey() + " failed to start after " + MAX_START_WAIT + " ms"); - } - - final EngineServiceEventInterface engineServiceEventInterface = service.getEngineServiceEventInterface(); - - // Send some events - final Date testStartTime = new Date(); - final Map eventDataMap = new HashMap(); - eventDataMap.put("TestSlogan", "This is a test slogan"); - eventDataMap.put("TestMatchCase", (byte) 123); - eventDataMap.put("TestTimestamp", testStartTime.getTime()); - eventDataMap.put("TestTemperature", 34.5445667); - - final ApexEvent event = - new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); - event.setExecutionId(System.nanoTime()); - event.putAll(eventDataMap); - engineServiceEventInterface.sendEvent(event); - - final ApexEvent event2 = - new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); - event2.setExecutionId(System.nanoTime()); - event2.putAll(eventDataMap); - engineServiceEventInterface.sendEvent(event2); - - // Wait for results - final long recvtime = System.currentTimeMillis(); - while (actionEventsReceived < 2 && System.currentTimeMillis() - recvtime < MAX_RECV_WAIT) { - ThreadUtilities.sleep(100); - } - ThreadUtilities.sleep(500); - assertEquals(2, actionEventsReceived); - actionEventsReceived = 0; - - - // Stop all engines on this engine service - final long stoptime = System.currentTimeMillis(); - service.stop(); - while (!service.isStopped() && System.currentTimeMillis() - stoptime < MAX_STOP_WAIT) { - ThreadUtilities.sleep(200); - } - if (!service.isStopped()) { - fail("Apex Service " + service.getKey() + " failed to stop after " + MAX_STOP_WAIT + " ms"); - } - } - - /** - * Update the engine then test the engine with 2 sample events. - * - * @throws ApexException if there is a problem - */ - @Test - public void testExecutionSet1Sync() throws ApexException { - service.updateModel(parameters.getEngineKey(), apexModelString, true); - // Start the service - service.startAll(); - final long starttime = System.currentTimeMillis(); - for (final AxArtifactKey engineKey : service.getEngineKeys()) { - LOGGER.info("{}", service.getStatus(engineKey)); - } - while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { - ThreadUtilities.sleep(200); - } - if (!service.isStarted()) { - fail("Apex Service " + service.getKey() + " failed to start after " + MAX_START_WAIT + " ms"); - } - - // Send some events - final Date testStartTime = new Date(); - final Map eventDataMap = new HashMap(); - eventDataMap.put("TestSlogan", "This is a test slogan"); - eventDataMap.put("TestMatchCase", (byte) 123); - eventDataMap.put("TestTimestamp", testStartTime.getTime()); - eventDataMap.put("TestTemperature", 34.5445667); - - final ApexEvent event1 = - new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); - event1.putAll(eventDataMap); - event1.setExecutionId(System.nanoTime()); - - final ApexEventListener myEventListener1 = new ApexEventListener() { - @Override - public void onApexEvent(final ApexEvent responseEvent) { - assertNotNull("Synchronous sendEventWait failed", responseEvent); - assertEquals(event1.getExecutionId(), responseEvent.getExecutionId()); - waitFlag = false; - } - }; - - waitFlag = true; - service.registerActionListener("Listener1", myEventListener1); - service.getEngineServiceEventInterface().sendEvent(event1); - - while (waitFlag) { - ThreadUtilities.sleep(100); - } - - final ApexEvent event2 = - new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); - event2.setExecutionId(System.nanoTime()); - event2.putAll(eventDataMap); - - final ApexEventListener myEventListener2 = new ApexEventListener() { - @Override - public void onApexEvent(final ApexEvent responseEvent) { - assertNotNull("Synchronous sendEventWait failed", responseEvent); - assertEquals(event2.getExecutionId(), responseEvent.getExecutionId()); - assertEquals(2, actionEventsReceived); - waitFlag = false; - } - }; - - waitFlag = true; - service.deregisterActionListener("Listener1"); - service.registerActionListener("Listener2", myEventListener2); - service.getEngineServiceEventInterface().sendEvent(event2); - - while (waitFlag) { - ThreadUtilities.sleep(100); - } - service.deregisterActionListener("Listener2"); - - actionEventsReceived = 0; - - // Stop all engines on this engine service - final long stoptime = System.currentTimeMillis(); - service.stop(); - while (!service.isStopped() && System.currentTimeMillis() - stoptime < MAX_STOP_WAIT) { - ThreadUtilities.sleep(200); - } - if (!service.isStopped()) { - fail("Apex Service " + service.getKey() + " failed to stop after " + MAX_STOP_WAIT + " ms"); - } - } - - /** - * Update the engine then test the engine with 2 sample events - again. - * - * @throws ApexException if there is a problem - */ - @Test - public void testExecutionSet2() throws ApexException { - service.updateModel(parameters.getEngineKey(), apexModelString, true); - // Start the service - service.startAll(); - final long starttime = System.currentTimeMillis(); - for (final AxArtifactKey engineKey : service.getEngineKeys()) { - LOGGER.info("{}", service.getStatus(engineKey)); - } - while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { - ThreadUtilities.sleep(200); - } - if (!service.isStarted()) { - fail("Apex Service " + service.getKey() + " failed to start after " + MAX_START_WAIT + " ms"); - } - - final EngineServiceEventInterface engineServiceEventInterface = service.getEngineServiceEventInterface(); - - // Send some events - final Date testStartTime = new Date(); - final Map eventDataMap = new HashMap(); - eventDataMap.put("TestSlogan", "This is a test slogan"); - eventDataMap.put("TestMatchCase", (byte) 123); - eventDataMap.put("TestTimestamp", testStartTime.getTime()); - eventDataMap.put("TestTemperature", 34.5445667); - - final ApexEvent event = - new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); - event.setExecutionId(System.nanoTime()); - event.putAll(eventDataMap); - engineServiceEventInterface.sendEvent(event); - - final ApexEvent event2 = - new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); - event2.setExecutionId(System.nanoTime()); - event2.putAll(eventDataMap); - engineServiceEventInterface.sendEvent(event2); - - // Wait for results - final long recvtime = System.currentTimeMillis(); - while (actionEventsReceived < 2 && System.currentTimeMillis() - recvtime < MAX_RECV_WAIT) { - ThreadUtilities.sleep(100); - } - ThreadUtilities.sleep(500); - assertEquals(2, actionEventsReceived); - actionEventsReceived = 0; - - // Stop all engines on this engine service - final long stoptime = System.currentTimeMillis(); - service.stop(); - while (!service.isStopped() && System.currentTimeMillis() - stoptime < MAX_STOP_WAIT) { - ThreadUtilities.sleep(200); - } - if (!service.isStopped()) { - fail("Apex Service " + service.getKey() + " failed to stop after " + MAX_STOP_WAIT + " ms"); - } - } - - /** - * Update the engine then test the engine with 2 sample events - again. - * - * @throws ApexException if there is a problem - */ - @Test - public void testExecutionSet2Sync() throws ApexException { - service.updateModel(parameters.getEngineKey(), apexModelString, true); - // Start the service - service.startAll(); - final long starttime = System.currentTimeMillis(); - for (final AxArtifactKey engineKey : service.getEngineKeys()) { - LOGGER.info("{}", service.getStatus(engineKey)); - } - while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { - ThreadUtilities.sleep(200); - } - if (!service.isStarted()) { - fail("Apex Service " + service.getKey() + " failed to start after " + MAX_START_WAIT + " ms"); - } - - // Send some events - final Date testStartTime = new Date(); - final Map eventDataMap = new HashMap(); - eventDataMap.put("TestSlogan", "This is a test slogan"); - eventDataMap.put("TestMatchCase", (byte) 123); - eventDataMap.put("TestTimestamp", testStartTime.getTime()); - eventDataMap.put("TestTemperature", 34.5445667); - - final ApexEvent event1 = - new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); - event1.putAll(eventDataMap); - - final ApexEventListener myEventListener1 = new ApexEventListener() { - @Override - public void onApexEvent(final ApexEvent responseEvent) { - assertNotNull("Synchronous sendEventWait failed", responseEvent); - assertEquals(event1.getExecutionId(), responseEvent.getExecutionId()); - waitFlag = false; - } - }; - - waitFlag = true; - service.registerActionListener("Listener1", myEventListener1); - service.getEngineServiceEventInterface().sendEvent(event1); - - while (waitFlag) { - ThreadUtilities.sleep(100); - } - - final ApexEvent event2 = - new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); - event2.putAll(eventDataMap); - - final ApexEventListener myEventListener2 = new ApexEventListener() { - @Override - public void onApexEvent(final ApexEvent responseEvent) { - assertNotNull("Synchronous sendEventWait failed", responseEvent); - assertEquals(event2.getExecutionId(), responseEvent.getExecutionId()); - waitFlag = false; - } - }; - - waitFlag = true; - service.registerActionListener("Listener2", myEventListener2); - service.deregisterActionListener("Listener1"); - service.getEngineServiceEventInterface().sendEvent(event2); - - while (waitFlag) { - ThreadUtilities.sleep(100); - } - - service.deregisterActionListener("Listener2"); - - assertEquals(2, actionEventsReceived); - - actionEventsReceived = 0; - - // Stop all engines on this engine service - final long stoptime = System.currentTimeMillis(); - service.stop(); - while (!service.isStopped() && System.currentTimeMillis() - stoptime < MAX_STOP_WAIT) { - ThreadUtilities.sleep(200); - } - if (!service.isStopped()) { - fail("Apex Service " + service.getKey() + " failed to stop after " + MAX_STOP_WAIT + " ms"); - } - } - - /** - * Tear down the the test infrastructure. - * - * @throws ApexException if there is an error - */ - @AfterClass - public static void tearDown() throws Exception { - // Stop all engines on this engine service - final long stoptime = System.currentTimeMillis(); - service.stop(); - while (!service.isStopped() && System.currentTimeMillis() - stoptime < MAX_STOP_WAIT) { - ThreadUtilities.sleep(200); - } - if (!service.isStopped()) { - fail("Apex Service " + service.getKey() + " failed to stop after " + MAX_STOP_WAIT + " ms"); - } - service = null; - } - - /** - * The listener interface for receiving test events. The class that is interested in processing - * a test event implements this interface, and the object created with that class is registered - * with a component using the component's addTestListener method. When the test - * event occurs, that object's appropriate method is invoked. - * - * @see TestEvent - */ - private static final class TestListener implements ApexEventListener { - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.service.engine.runtime.ApexEventListener#onApexEvent(org.onap.policy - * .apex.service.engine.event.ApexEvent) - */ - @Override - public synchronized void onApexEvent(final ApexEvent event) { - LOGGER.debug("result 1 is:" + event); - checkResult(event); - actionEventsReceived++; - - final Date testStartTime = new Date((Long) event.get("TestTimestamp")); - final Date testEndTime = new Date(); - - LOGGER.info("policy execution time: " + (testEndTime.getTime() - testStartTime.getTime()) + "ms"); - } - - /** - * Check result. - * - * @param result the result - */ - private void checkResult(final ApexEvent result) { - assertTrue(result.getName().startsWith("Event0004") || result.getName().startsWith("Event0104")); - - assertTrue(result.get("TestSlogan").equals("This is a test slogan")); - assertTrue(result.get("TestMatchCase").equals(new Byte((byte) 123))); - assertTrue(result.get("TestTemperature").equals(34.5445667)); - assertTrue(((byte) result.get("TestMatchCaseSelected")) >= 0 - && ((byte) result.get("TestMatchCaseSelected") <= 3)); - assertTrue(((byte) result.get("TestEstablishCaseSelected")) >= 0 - && ((byte) result.get("TestEstablishCaseSelected") <= 3)); - assertTrue(((byte) result.get("TestDecideCaseSelected")) >= 0 - && ((byte) result.get("TestDecideCaseSelected") <= 3)); - assertTrue( - ((byte) result.get("TestActCaseSelected")) >= 0 && ((byte) result.get("TestActCaseSelected") <= 3)); - } - } -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/utils/Utils.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/utils/Utils.java deleted file mode 100644 index cfc787d64..000000000 --- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/service/engine/utils/Utils.java +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 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.service.engine.utils; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelWriter; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; - -public class Utils { - - private Utils() {} - - public static String getModelString(final AxPolicyModel ecaPolicyModel) throws ApexModelException, IOException { - try (final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream()) { - new ApexModelWriter(AxPolicyModel.class).write(ecaPolicyModel, baOutputStream); - return baOutputStream.toString(); - } - } - -} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexBaseBenchMarkTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexBaseBenchMarkTest.java new file mode 100644 index 000000000..fdefd5583 --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexBaseBenchMarkTest.java @@ -0,0 +1,175 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.testsuites.performance.benchmark.engine.benchmark; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters; +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.core.engine.EngineParameters; +import org.onap.policy.apex.core.engine.ExecutorParameters; +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.plugins.context.schema.avro.AvroSchemaHelperParameters; +import org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters; +import org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters; +import org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters; +import org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters; +import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; +import org.onap.policy.apex.service.engine.event.ApexEvent; +import org.onap.policy.apex.service.engine.runtime.ApexEventListener; +import org.onap.policy.apex.service.engine.runtime.EngineService; +import org.onap.policy.apex.service.engine.runtime.EngineServiceEventInterface; +import org.onap.policy.apex.service.engine.runtime.impl.EngineServiceImpl; +import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters; +import org.onap.policy.apex.testsuites.performance.benchmark.engine.runtime.ApexServiceModelUpdateTest; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class ApexBaseBenchMarkTest. + */ +public class ApexBaseBenchMarkTest { + private static final long STOP_TIME_OUT = TimeUnit.SECONDS.toMillis(30); + private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexServiceModelUpdateTest.class); + private static final long MAX_START_WAIT = TimeUnit.SECONDS.toMillis(10); + private final AxArtifactKey engineServiceKey = new AxArtifactKey("Machine-1_process-1_engine-1", "0.0.0"); + private final String model; + private final int threads; + private final ApexEventListener listener; + private EngineService service; + private EngineServiceEventInterface engineServiceEventInterface; + + + /** + * Instantiates a new apex base bench mark test. + * + * @param model the model + * @param threads the threads + * @param listener the listener + */ + public ApexBaseBenchMarkTest(final String model, final int threads, final ApexEventListener listener) { + this.model = model; + this.threads = threads; + this.listener = listener; + } + + /** + * Sets the up. + * + * @throws Exception the exception + */ + public void setUp() throws Exception { + final EngineServiceParameters parameters = new EngineServiceParameters(); + parameters.setInstanceCount(threads); + parameters.setName(engineServiceKey.getName()); + parameters.setVersion(engineServiceKey.getVersion()); + parameters.setId(100); + + final EngineParameters engineParameters = parameters.getEngineParameters(); + final Map executorParameterMap = engineParameters.getExecutorParameterMap(); + executorParameterMap.put("MVEL", new MvelExecutorParameters()); + executorParameterMap.put("JAVASCRIPT", new JavascriptExecutorParameters()); + executorParameterMap.put("JYTHON", new JythonExecutorParameters()); + executorParameterMap.put("JAVA", new JavaExecutorParameters()); + executorParameterMap.put("JRUBY", new JrubyExecutorParameters()); + + final ContextParameters contextParameters = engineParameters.getContextParameters(); + final SchemaParameters schemaParameters = contextParameters.getSchemaParameters(); + schemaParameters.getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters()); + schemaParameters.getSchemaHelperParameterMap().put("Java", new JavaSchemaHelperParameters()); + service = EngineServiceImpl.create(parameters); + + service = EngineServiceImpl.create(parameters); + service.registerActionListener("listener", listener); + service.updateModel(parameters.getEngineKey(), model, true); + + LOGGER.info("Starting EngineService ... "); + service.startAll(); + + final long starttime = System.currentTimeMillis(); + while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { + ThreadUtilities.sleep(50); + } + if (!service.isStarted()) { + LOGGER.error("Apex Service {} failed to start after {} ms", service.getKey(), MAX_START_WAIT); + new ApexException("Unable to start engine service "); + } + + engineServiceEventInterface = service.getEngineServiceEventInterface(); + } + + /** + * Send events. + * + * @param events the events + */ + public void sendEvents(final List events) { + for (final ApexEvent event : events) { + engineServiceEventInterface.sendEvent(event); + } + } + + /** + * Send event. + * + * @param event the event + */ + public void sendEvent(final ApexEvent event) { + engineServiceEventInterface.sendEvent(event); + } + + + /** + * Gets the service. + * + * @return the service + */ + public EngineService getService() { + return service; + } + + /** + * Destroy. + * + * @throws Exception the exception + */ + public void destroy() throws Exception { + if (service != null) { + LOGGER.info("Stopping EngineService ... "); + service.stop(); + final long currentTimeInMillSec = System.currentTimeMillis(); + while (!service.isStopped()) { + if (System.currentTimeMillis() - currentTimeInMillSec > STOP_TIME_OUT) { + LOGGER.warn("Timed Out EngineService status: ", service.isStopped()); + break; + } + ThreadUtilities.sleep(500); + } + service = null; + } + } + +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexEngineBenchmark.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexEngineBenchmark.java new file mode 100644 index 000000000..fa2a9934c --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/ApexEngineBenchmark.java @@ -0,0 +1,183 @@ +/*- + * ============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.testsuites.performance.benchmark.engine.benchmark; + +import static org.junit.Assert.assertEquals; + +import java.util.concurrent.TimeUnit; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.onap.policy.apex.service.engine.event.ApexEvent; +import org.onap.policy.apex.testsuites.integration.common.model.EvalDomainModelFactory; +import org.onap.policy.apex.testsuites.performance.benchmark.engine.utils.Utils; +import org.python.icu.impl.Assert; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class ApexEngineBenchmark. + */ +public class ApexEngineBenchmark { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEngineBenchmark.class); + + private static final String TARGET = "apex"; + private static final String SOURCE = "test"; + private static final String NAME = "Event0000"; + private static final String VERSION = "0.0.1"; + private static final String PACKAGE = "org.onap.policy.apex.domains.sample.events"; + + private static final long TIME_OUT_IN_MILLISEC = TimeUnit.MINUTES.toMillis(1); + + private String apexEcaModelString; + private String apexOodaModelString; + + /** + * Sets the up. + * + * @throws Exception the exception + */ + @Before + public void setUp() throws Exception { + apexEcaModelString = Utils.getModelString(new EvalDomainModelFactory().getEcaPolicyModel()); + apexOodaModelString = Utils.getModelString(new EvalDomainModelFactory().getOodaPolicyModel()); + } + + /** + * Test benchmark singleton worker. + * + * @throws Exception the exception + */ + @Test + public void testBenchmark_SingletonWorker() throws Exception { + executeTest(apexEcaModelString, 100, 1, 20); + executeTest(apexOodaModelString, 100, 1, 20); + } + + /** + * Test benchmark 3 thread worker. + * + * @throws Exception the exception + */ + @Test + public void testBenchmark_3ThreadWorker() throws Exception { + executeTest(apexEcaModelString, 1000, 3, 10); + executeTest(apexOodaModelString, 100, 3, 10); + } + + /** + * Test benchmark 10 thread worker. + * + * @throws Exception the exception + */ + @Test + public void testBenchmark_10ThreadWorker() throws Exception { + executeTest(apexEcaModelString, 2000, 10, 10); + executeTest(apexOodaModelString, 2000, 10, 10); + } + + /** + * Test benchmark 50 thread worker. + * + * @throws Exception the exception + */ + @Test + public void testBenchmark_50ThreadWorker() throws Exception { + executeTest(apexEcaModelString, 3000, 50, 10); + executeTest(apexOodaModelString, 3000, 50, 10); + } + + /** + * Test available processors thread worker. + * + * @throws Exception the exception + */ + @Test + public void testAvailableProcessorsThreadWorker() throws Exception { + final int cores = Runtime.getRuntime().availableProcessors(); + executeTest(apexEcaModelString, 3000, cores, 10); + executeTest(apexOodaModelString, 3000, cores, 10); + } + + /** + * Execute test. + * + * @param policyModel the policy model + * @param eventsCount the events count + * @param threads the threads + * @param loop the loop + * @throws Exception the exception + */ + private void executeTest(final String policyModel, final int eventsCount, final int threads, final int loop) + throws Exception { + + LOGGER.info("Running Test with Event count: {}, Instance count: {} and loop: {}", eventsCount, threads, loop); + final TestApexEventListener apexEventListener = new TestApexEventListener(); + + final ApexBaseBenchMarkTest apexBaseBenchMarkTest = + new ApexBaseBenchMarkTest(policyModel, threads, apexEventListener); + + try { + apexBaseBenchMarkTest.setUp(); + for (int i = 0; i < loop; i++) { + sendEvents(apexBaseBenchMarkTest, eventsCount); + final long currentTimeInMillSec = System.currentTimeMillis(); + while (apexEventListener.getEventReceived() < eventsCount) { + if (System.currentTimeMillis() - currentTimeInMillSec > TIME_OUT_IN_MILLISEC) { + LOGGER.warn("Wait timed out ... "); + break; + } + ThreadUtilities.sleep(500); + } + assertEquals(eventsCount, apexEventListener.getEventReceived()); + apexEventListener.printResult(); + apexEventListener.reset(); + } + } catch (final Exception exception) { + Assert.fail(exception); + } finally { + apexBaseBenchMarkTest.destroy(); + LOGGER.info("Finished Running Test with Event count: {}, Instance count: {} and loop: {}", eventsCount, + threads, loop); + } + } + + /** + * Send events. + * + * @param apexBaseBenchMarkTest the apex base bench mark test + * @param eventsCount the events count + * @throws Exception the exception + */ + public void sendEvents(final ApexBaseBenchMarkTest apexBaseBenchMarkTest, final int eventsCount) throws Exception { + for (int eventNum = 0; eventNum < eventsCount; eventNum++) { + final long currentTimeMillis = System.currentTimeMillis(); + final ApexEvent event = new ApexEvent(NAME, VERSION, PACKAGE, SOURCE, TARGET); + event.put("TestTemperature", eventNum); + event.put("FirstEventTimestamp", currentTimeMillis); + event.put("SentTimestamp", currentTimeMillis); + event.put("EventNumber", eventNum); + apexBaseBenchMarkTest.sendEvent(event); + } + } +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/TestApexEventListener.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/TestApexEventListener.java new file mode 100644 index 000000000..2b6c89de7 --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/benchmark/TestApexEventListener.java @@ -0,0 +1,126 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.testsuites.performance.benchmark.engine.benchmark; + +import static org.junit.Assert.assertNull; + +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.atomic.AtomicLong; + +import org.onap.policy.apex.service.engine.event.ApexEvent; +import org.onap.policy.apex.service.engine.runtime.ApexEventListener; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The listener interface for receiving testApexEvent events. + * The class that is interested in processing a testApexEvent + * event implements this interface, and the object created + * with that class is registered with a component using the + * component's addTestApexEventListener method. When + * the testApexEvent event occurs, that object's appropriate + * method is invoked. + * + * @see TestApexEventEvent + */ +public class TestApexEventListener implements ApexEventListener { + + private static final String SENT_TIMESTAMP = "SentTimestamp"; + private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestApexEventListener.class); + private static final String RECVD_TIMESTAMP = "RecvdTimestamp"; + private Queue queue; + + private final AtomicLong eventReceived = new AtomicLong(); + + /** + * Instantiates a new test apex event listener. + */ + public TestApexEventListener() { + this.queue = new ConcurrentLinkedQueue(); + } + + /* (non-Javadoc) + * @see org.onap.policy.apex.service.engine.runtime.ApexEventListener#onApexEventApexEvent) + */ + @Override + public void onApexEvent(final ApexEvent apexEvent) { + apexEvent.put(RECVD_TIMESTAMP, System.currentTimeMillis()); + eventReceived.incrementAndGet(); + queue.add(apexEvent); + } + + /** + * Prints the result. + */ + public void printResult() { + if (!queue.isEmpty()) { + long maxTimeInMilliSeconds = 0; + long minTimeInMilliSeconds = Long.MAX_VALUE; + final long numEvents = queue.size(); + long totalTimeInMilliSeconds = 0; + for (final ApexEvent apexEvent : queue) { + assertNull(apexEvent.getExceptionMessage()); + final Long endTimeInMilliSeconds = (Long) apexEvent.get(RECVD_TIMESTAMP); + final Long startTimeInMilliSeconds = (Long) apexEvent.get(SENT_TIMESTAMP); + final long timeTaken = endTimeInMilliSeconds - startTimeInMilliSeconds; + totalTimeInMilliSeconds += timeTaken; + if (timeTaken > maxTimeInMilliSeconds) { + maxTimeInMilliSeconds = timeTaken; + } + if (timeTaken < minTimeInMilliSeconds) { + minTimeInMilliSeconds = timeTaken; + } + } + LOGGER.info("Average Time Taken to process {} events: {} ms", numEvents, + (totalTimeInMilliSeconds / numEvents)); + LOGGER.info("Max Time Taken: {} ms", maxTimeInMilliSeconds); + LOGGER.info("Min Time Taken: {} ms", minTimeInMilliSeconds); + } + } + + /** + * Reset. + */ + public void reset() { + this.queue = new ConcurrentLinkedQueue(); + eventReceived.set(0);; + } + + /** + * Gets the queue. + * + * @return the queue + */ + public Queue getQueue() { + return queue; + } + + /** + * Gets the event received. + * + * @return the event received + */ + public long getEventReceived() { + return eventReceived.get(); + } + +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/BaseTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/BaseTest.java new file mode 100644 index 000000000..52bdb056b --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/BaseTest.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.testsuites.performance.benchmark.engine.main; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.concurrent.TimeUnit; + +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.onap.policy.apex.model.utilities.TextFileUtils; +import org.onap.policy.apex.service.engine.main.ApexMain; + +public class BaseTest { + protected static final long TIME_OUT_IN_MS = TimeUnit.SECONDS.toMillis(10); + + protected long getFileLength(final String file, final long expectedFileSize) throws IOException { + return getFileLength(10, file, expectedFileSize); + } + + protected long getFileLength(final int loopTime, final String file, final long expectedFileSize) + throws IOException { + long length = 0; + for (int i = 0; i < loopTime; i++) { + final String fileString = TextFileUtils.getTextFileAsString(file).replaceAll("\\s+", ""); + length = fileString.length(); + if (length > 0 && length >= expectedFileSize) { + break; + } + ThreadUtilities.sleep(500); + } + return length; + } + + protected void waitForOutFiles(final File... files) { + final long timeInMillis = System.currentTimeMillis(); + while (!isFilesExist(files)) { + if (System.currentTimeMillis() - timeInMillis > TIME_OUT_IN_MS) { + break; + } + ThreadUtilities.sleep(500); + } + + } + + private void assertFilesExists(final File... files) { + for (final File file : files) { + assertTrue("Test failed, the output " + file + "event file was not created", file.exists()); + } + } + + private void deleteFiles(final File... files) throws IOException { + for (final File file : files) { + Files.deleteIfExists(file.toPath()); + } + } + + private boolean isFilesExist(final File[] files) { + for (final File file : files) { + if (!file.exists()) { + return false; + } + } + return true; + } + + protected File[] toFile(final String[] filesPath) { + if (filesPath == null || filesPath.length == 0) { + return new File[] {}; + } + final File[] files = new File[filesPath.length]; + + for (int index = 0; index < filesPath.length; index++) { + files[index] = new File(filesPath[index]); + } + + return files; + } + + protected void testFileEvents(final String[] args, final String[] expectedFilesPath, final long expectedFileSize) + throws Exception { + final ApexMain apexMain = new ApexMain(args); + + final File[] expectedFiles = toFile(expectedFilesPath); + try { + + waitForOutFiles(expectedFiles); + assertFilesExists(expectedFiles); + + for (final String filePath : expectedFilesPath) { + assertEquals(expectedFileSize, getFileLength(filePath, expectedFileSize)); + } + + apexMain.shutdown(); + + } finally { + deleteFiles(expectedFiles); + } + } + +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventMimo.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventMimo.java new file mode 100644 index 000000000..195840c6d --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventMimo.java @@ -0,0 +1,43 @@ +/*- + * ============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.testsuites.performance.benchmark.engine.main; + +import org.junit.Test; + +public class TestAsyncEventMimo extends BaseTest { + + @Test + public void testJsonFileAsyncMimo() throws Exception { + final String[] args = { + "-c", + "src/test/resources/parameters/File2FileJsonEventAsyncMIMO.json" + }; + + final String[] outFilePaths = { + "src/test/resources/events/EventsOutMulti0.json", + "src/test/resources/events/EventsOutMulti1.json", + "src/test/resources/events/EventsOutMulti2.json" + }; + + testFileEvents(args, outFilePaths, 48956 * 3); + } + +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventMiso.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventMiso.java new file mode 100644 index 000000000..2e364647b --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventMiso.java @@ -0,0 +1,33 @@ +/*- + * ============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.testsuites.performance.benchmark.engine.main; + +import org.junit.Test; + +public class TestAsyncEventMiso extends BaseTest { + + @Test + public void testJsonFileAsyncMiso() throws Exception { + final String[] args = {"-c", "src/test/resources/parameters/File2FileJsonEventAsyncMISO.json"}; + + testFileEvents(args, new String[] {"src/test/resources/events/EventsOutSingle.json"}, 48956 * 3); + } +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventSimo.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventSimo.java new file mode 100644 index 000000000..0fb191c49 --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventSimo.java @@ -0,0 +1,43 @@ +/*- + * ============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.testsuites.performance.benchmark.engine.main; + +import org.junit.Test; + +public class TestAsyncEventSimo extends BaseTest { + + @Test + public void testJsonFileAsyncSimo() throws Exception { + final String[] args = { + "-c", + "src/test/resources/parameters/File2FileJsonEventAsyncSIMO.json" + }; + + final String[] outFilePaths = { + "src/test/resources/events/EventsOutMulti0.json", + "src/test/resources/events/EventsOutMulti1.json", + "src/test/resources/events/EventsOutMulti2.json" + }; + + testFileEvents(args, outFilePaths, 48956); + } + +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventSiso.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventSiso.java new file mode 100644 index 000000000..a89e630bc --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestAsyncEventSiso.java @@ -0,0 +1,33 @@ +/*- + * ============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.testsuites.performance.benchmark.engine.main; + +import org.junit.Test; + +public class TestAsyncEventSiso extends BaseTest { + + @Test + public void testJsonFileAsyncSiso() throws Exception { + final String[] args = {"-c", "src/test/resources/parameters/File2FileJsonEventAsyncSISO.json"}; + + testFileEvents(args, new String[] {"src/test/resources/events/EventsOutSingle.json"}, 48956); + } +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestSyncEventMimo.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestSyncEventMimo.java new file mode 100644 index 000000000..8b35e5dd8 --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestSyncEventMimo.java @@ -0,0 +1,43 @@ +/*- + * ============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.testsuites.performance.benchmark.engine.main; + +import org.junit.Test; + +public class TestSyncEventMimo extends BaseTest { + + @Test + public void testJsonFileAsyncMimo() throws Exception { + final String[] args = { + "-c", + "src/test/resources/parameters/File2FileJsonEventSyncMIMO.json" + }; + + final String[] outFilePaths = { + "src/test/resources/events/EventsOutMulti0.json", + "src/test/resources/events/EventsOutMulti1.json", + "src/test/resources/events/EventsOutMulti2.json" + }; + + testFileEvents(args, outFilePaths, 48956 * 3); + } + +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestSyncEventSiso.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestSyncEventSiso.java new file mode 100644 index 000000000..891ad7198 --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/main/TestSyncEventSiso.java @@ -0,0 +1,33 @@ +/*- + * ============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.testsuites.performance.benchmark.engine.main; + +import org.junit.Test; + +public class TestSyncEventSiso extends BaseTest { + + @Test + public void testJsonFileAsyncSiso() throws Exception { + final String[] args = {"-c", "src/test/resources/parameters/File2FileJsonEventSyncSISO.json"}; + + testFileEvents(args, new String[] {"src/test/resources/events/EventsOutSingle.json"}, 48956); + } +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/runtime/ApexServiceModelUpdateTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/runtime/ApexServiceModelUpdateTest.java new file mode 100644 index 000000000..cf930150e --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/runtime/ApexServiceModelUpdateTest.java @@ -0,0 +1,362 @@ +/*- + * ============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.testsuites.performance.benchmark.engine.runtime; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +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.ModelService; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; +import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; +import org.onap.policy.apex.service.engine.event.ApexEvent; +import org.onap.policy.apex.service.engine.event.ApexEventException; +import org.onap.policy.apex.service.engine.runtime.ApexEventListener; +import org.onap.policy.apex.service.engine.runtime.EngineService; +import org.onap.policy.apex.service.engine.runtime.EngineServiceEventInterface; +import org.onap.policy.apex.service.engine.runtime.impl.EngineServiceImpl; +import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters; +import org.onap.policy.apex.testsuites.integration.common.model.SampleDomainModelFactory; +import org.onap.policy.apex.testsuites.performance.benchmark.engine.utils.Utils; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class ApexServiceTest. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ApexServiceModelUpdateTest { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexServiceModelUpdateTest.class); + + private final AxArtifactKey engineServiceKey = new AxArtifactKey("Machine-1_process-1_engine-1", "0.0.0"); + private final EngineServiceParameters parameters = new EngineServiceParameters(); + private EngineService service = null; + private TestListener listener = null; + private int actionEventsReceived = 0; + + private AxPolicyModel apexSamplePolicyModel = null; + private String apexSampleModelString; + + /** + * Sets up the test by creating an engine and reading in the test policy. + * + * @throws ApexException if something goes wrong + * @throws IOException on IO exceptions + */ + @Before + public void setUp() throws ApexException, IOException { + // create engine with 3 threads + parameters.setInstanceCount(3); + parameters.setName(engineServiceKey.getName()); + parameters.setVersion(engineServiceKey.getVersion()); + parameters.setId(100); + parameters.getEngineParameters().getExecutorParameterMap().put("MVEL", new MvelExecutorParameters()); + service = EngineServiceImpl.create(parameters); + + LOGGER.debug("Running TestApexEngine. . ."); + + apexSamplePolicyModel = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); + assertNotNull(apexSamplePolicyModel); + + apexSampleModelString = Utils.getModelString(apexSamplePolicyModel); + + // create engine + listener = new TestListener(); + service.registerActionListener("MyListener", listener); + } + + /** + * Tear down the the test infrastructure. + * + * @throws ApexException if there is an error + */ + @After + public void tearDown() throws Exception { + if (service != null) { + service.stop(); + } + service = null; + } + + /** + * Test start with no model. + */ + @Test + public void testNoModelStart() { + try { + service.startAll(); + fail("Engine should not start with no model"); + } catch (final Exception e) { + e.printStackTrace(); + assertEquals("start()<-Machine-1_process-1_engine-1-0:0.0.0,STOPPED, cannot start engine, " + + "engine has not been initialized, its model is not loaded", e.getMessage()); + } + } + + /** + * Test model update with string model without force. + * + * @throws ApexException if there is an error + */ + @Test + public void testModelUpdateStringNewNoForce() throws ApexException { + service.updateModel(parameters.getEngineKey(), apexSampleModelString, false); + service.startAll(); + assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); + } + + /** + * Test model update with string model with force. + * + * @throws ApexException if there is an error + */ + @Test + public void testModelUpdateStringNewForce() throws ApexException { + service.updateModel(parameters.getEngineKey(), apexSampleModelString, true); + service.startAll(); + assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); + } + + /** + * Test model update with a new string model without force. + * + * @throws ApexException if there is an error + */ + @Test + public void testModelUpdateStringNewNewNoForce() throws ApexException { + service.updateModel(parameters.getEngineKey(), apexSampleModelString, false); + service.startAll(); + assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); + + sendEvents(); + + service.updateModel(parameters.getEngineKey(), apexSampleModelString, false); + assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); + + sendEvents(); + } + + /** + * Test incompatible model update with a model object without force. + * + * @throws ApexException if there is an error + */ + @Test + public void testModelUpdateIncoNoForce() throws ApexException { + service.updateModel(parameters.getEngineKey(), apexSamplePolicyModel, false); + service.startAll(); + assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); + + // Different model name, incompatible + final AxPolicyModel incoPolicyModel0 = new AxPolicyModel(apexSamplePolicyModel); + incoPolicyModel0.getKey().setName("INCOMPATIBLE"); + + try { + service.updateModel(parameters.getEngineKey(), incoPolicyModel0, false); + fail("model update should fail on incompatible model without force being true"); + } catch (final Exception e) { + System.err.println(e.getMessage()); + assertEquals("apex model update failed, supplied model with key \"INCOMPATIBLE:0.0.1\" is not a compatible " + + "model update from the existing engine model with key \"SamplePolicyModelMVEL:0.0.1\"", + e.getMessage()); + } + + // Still on old model + sendEvents(); + + // Different major version, incompatible + final AxPolicyModel incoPolicyModel1 = new AxPolicyModel(apexSamplePolicyModel); + incoPolicyModel1.getKey().setVersion("1.0.1"); + + try { + service.updateModel(parameters.getEngineKey(), incoPolicyModel1, false); + fail("model update should fail on incompatible model without force being true"); + } catch (final Exception e) { + System.err.println(e.getMessage()); + e.printStackTrace(); + assertEquals("apex model update failed, supplied model with key \"SamplePolicyModelMVEL:1.0.1\" is not " + + "a compatible model update from the existing engine model with key " + + "\"SamplePolicyModelMVEL:0.0.1\"", e.getMessage()); + } + + // Still on old model + sendEvents(); + + // Different minor version, compatible + final AxPolicyModel coPolicyModel0 = new AxPolicyModel(apexSamplePolicyModel); + coPolicyModel0.getKey().setVersion("0.1.0"); + service.updateModel(parameters.getEngineKey(), coPolicyModel0, false); + + // On new compatible model + sendEvents(); + + // Different patch version, compatible + final AxPolicyModel coPolicyModel1 = new AxPolicyModel(apexSamplePolicyModel); + coPolicyModel1.getKey().setVersion("0.0.2"); + service.updateModel(parameters.getEngineKey(), coPolicyModel1, false); + + // On new compatible model + sendEvents(); + + } + + /** + * Test incompatible model update with a model object with force. + * + * @throws ApexException if there is an error + */ + @Test + public void testModelUpdateIncoForce() throws ApexException { + service.updateModel(parameters.getEngineKey(), apexSamplePolicyModel, false); + service.startAll(); + assertEquals(apexSamplePolicyModel.getKey(), ModelService.getModel(AxPolicyModel.class).getKey()); + + // Different model name, incompatible + final AxPolicyModel incoPolicyModel0 = new AxPolicyModel(apexSamplePolicyModel); + incoPolicyModel0.getKey().setName("INCOMPATIBLE"); + service.updateModel(parameters.getEngineKey(), incoPolicyModel0, true); + + // On updated model + sendEvents(); + + // Different major version, incompatible + final AxPolicyModel incoPolicyModel1 = new AxPolicyModel(apexSamplePolicyModel); + incoPolicyModel1.getKey().setVersion("1.0.1"); + service.updateModel(parameters.getEngineKey(), incoPolicyModel1, true); + + // On updated model + sendEvents(); + + // Different minor version, compatible + final AxPolicyModel coPolicyModel0 = new AxPolicyModel(apexSamplePolicyModel); + coPolicyModel0.getKey().setVersion("0.1.0"); + service.updateModel(parameters.getEngineKey(), coPolicyModel0, true); + + // On new compatible model + sendEvents(); + + // Different patch version, compatible + final AxPolicyModel coPolicyModel1 = new AxPolicyModel(apexSamplePolicyModel); + coPolicyModel1.getKey().setVersion("0.0.2"); + service.updateModel(parameters.getEngineKey(), coPolicyModel1, true); + + // On new compatible model + sendEvents(); + + } + + /** + * Utility method to send some events into the test engine. + * + * @throws ApexEventException if there is an error + */ + private void sendEvents() throws ApexEventException { + final EngineServiceEventInterface engineServiceEventInterface = service.getEngineServiceEventInterface(); + + // Send some events + final Date testStartTime = new Date(); + final Map eventDataMap = new HashMap(); + eventDataMap.put("TestSlogan", "This is a test slogan"); + eventDataMap.put("TestMatchCase", (byte) 123); + eventDataMap.put("TestTimestamp", testStartTime.getTime()); + eventDataMap.put("TestTemperature", 34.5445667); + + final ApexEvent event = new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", + "test", "apex"); + event.putAll(eventDataMap); + engineServiceEventInterface.sendEvent(event); + + final ApexEvent event2 = new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", + "test", "apex"); + event2.putAll(eventDataMap); + engineServiceEventInterface.sendEvent(event2); + + // Wait for results + while (actionEventsReceived < 2) { + ThreadUtilities.sleep(100); + } + ThreadUtilities.sleep(500); + } + + /** + * The listener interface for receiving test events. The class that is interested in processing a test event + * implements this interface, and the object created with that class is registered with a component using the + * component's addTestListener method. When the test event occurs, that object's appropriate method is + * invoked. + * + * @see TestEvent + */ + private final class TestListener implements ApexEventListener { + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.service.engine.runtime.ApexEventListener#onApexEvent(org.onap.policy + * .apex.service.engine.event.ApexEvent) + */ + @Override + public synchronized void onApexEvent(final ApexEvent event) { + LOGGER.debug("result 1 is:" + event); + checkResult(event); + actionEventsReceived++; + + final Date testStartTime = new Date((Long) event.get("TestTimestamp")); + final Date testEndTime = new Date(); + + LOGGER.info("policy execution time: " + (testEndTime.getTime() - testStartTime.getTime()) + "ms"); + } + + /** + * Check result. + * + * @param result the result + */ + private void checkResult(final ApexEvent result) { + assertTrue(result.getName().startsWith("Event0004") || result.getName().startsWith("Event0104")); + + assertTrue(result.get("TestSlogan").equals("This is a test slogan")); + assertTrue(result.get("TestMatchCase").equals(new Byte((byte) 123))); + assertTrue(result.get("TestTemperature").equals(34.5445667)); + assertTrue(((byte) result.get("TestMatchCaseSelected")) >= 0 + && ((byte) result.get("TestMatchCaseSelected") <= 3)); + assertTrue(((byte) result.get("TestEstablishCaseSelected")) >= 0 + && ((byte) result.get("TestEstablishCaseSelected") <= 3)); + assertTrue(((byte) result.get("TestDecideCaseSelected")) >= 0 + && ((byte) result.get("TestDecideCaseSelected") <= 3)); + assertTrue(((byte) result.get("TestActCaseSelected")) >= 0 + && ((byte) result.get("TestActCaseSelected") <= 3)); + } + } +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/runtime/ApexServiceTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/runtime/ApexServiceTest.java new file mode 100644 index 000000000..e66d1b791 --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/runtime/ApexServiceTest.java @@ -0,0 +1,477 @@ +/*- + * ============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.testsuites.performance.benchmark.engine.runtime; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +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.policymodel.concepts.AxPolicyModel; +import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; +import org.onap.policy.apex.service.engine.event.ApexEvent; +import org.onap.policy.apex.service.engine.runtime.ApexEventListener; +import org.onap.policy.apex.service.engine.runtime.EngineService; +import org.onap.policy.apex.service.engine.runtime.EngineServiceEventInterface; +import org.onap.policy.apex.service.engine.runtime.impl.EngineServiceImpl; +import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters; +import org.onap.policy.apex.testsuites.integration.common.model.SampleDomainModelFactory; +import org.onap.policy.apex.testsuites.performance.benchmark.engine.utils.Utils; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class ApexServiceTest. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ApexServiceTest { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexServiceTest.class); + + private static final long MAX_STOP_WAIT = 5000; // 5 sec + private static final long MAX_START_WAIT = 5000; // 5 sec + private static final long MAX_RECV_WAIT = 5000; // 5 sec + + private static final AxArtifactKey engineServiceKey = new AxArtifactKey("Machine-1_process-1_engine-1", "0.0.0"); + private static final EngineServiceParameters parameters = new EngineServiceParameters(); + private static EngineService service = null; + private static TestListener listener = null; + private static AxPolicyModel apexPolicyModel = null; + private static int actionEventsReceived = 0; + + private static String apexModelString; + + private boolean waitFlag = true; + + /** + * Sets the up. + * + * @throws Exception the exception + */ + @BeforeClass + public static void setUp() throws Exception { + // create engine with 3 threads + parameters.setInstanceCount(3); + parameters.setName(engineServiceKey.getName()); + parameters.setVersion(engineServiceKey.getVersion()); + parameters.setId(100); + parameters.getEngineParameters().getExecutorParameterMap().put("MVEL", new MvelExecutorParameters()); + service = EngineServiceImpl.create(parameters); + + + LOGGER.debug("Running TestApexEngine. . ."); + + apexPolicyModel = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); + assertNotNull(apexPolicyModel); + + apexModelString = Utils.getModelString(apexPolicyModel); + + // create engine + listener = new TestListener(); + service.registerActionListener("Listener", listener); + } + + /** + * Update the engine then test the engine with 2 sample events. + * + * @throws ApexException if there is a problem + */ + @Test + public void testExecutionSet1() throws ApexException { + service.updateModel(parameters.getEngineKey(), apexModelString, true); + // Start the service + service.startAll(); + final long starttime = System.currentTimeMillis(); + for (final AxArtifactKey engineKey : service.getEngineKeys()) { + LOGGER.info("{}", service.getStatus(engineKey)); + } + while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { + ThreadUtilities.sleep(200); + } + if (!service.isStarted()) { + fail("Apex Service " + service.getKey() + " failed to start after " + MAX_START_WAIT + " ms"); + } + + final EngineServiceEventInterface engineServiceEventInterface = service.getEngineServiceEventInterface(); + + // Send some events + final Date testStartTime = new Date(); + final Map eventDataMap = new HashMap(); + eventDataMap.put("TestSlogan", "This is a test slogan"); + eventDataMap.put("TestMatchCase", (byte) 123); + eventDataMap.put("TestTimestamp", testStartTime.getTime()); + eventDataMap.put("TestTemperature", 34.5445667); + + final ApexEvent event = + new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + event.setExecutionId(System.nanoTime()); + event.putAll(eventDataMap); + engineServiceEventInterface.sendEvent(event); + + final ApexEvent event2 = + new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + event2.setExecutionId(System.nanoTime()); + event2.putAll(eventDataMap); + engineServiceEventInterface.sendEvent(event2); + + // Wait for results + final long recvtime = System.currentTimeMillis(); + while (actionEventsReceived < 2 && System.currentTimeMillis() - recvtime < MAX_RECV_WAIT) { + ThreadUtilities.sleep(100); + } + ThreadUtilities.sleep(500); + assertEquals(2, actionEventsReceived); + actionEventsReceived = 0; + + + // Stop all engines on this engine service + final long stoptime = System.currentTimeMillis(); + service.stop(); + while (!service.isStopped() && System.currentTimeMillis() - stoptime < MAX_STOP_WAIT) { + ThreadUtilities.sleep(200); + } + if (!service.isStopped()) { + fail("Apex Service " + service.getKey() + " failed to stop after " + MAX_STOP_WAIT + " ms"); + } + } + + /** + * Update the engine then test the engine with 2 sample events. + * + * @throws ApexException if there is a problem + */ + @Test + public void testExecutionSet1Sync() throws ApexException { + service.updateModel(parameters.getEngineKey(), apexModelString, true); + // Start the service + service.startAll(); + final long starttime = System.currentTimeMillis(); + for (final AxArtifactKey engineKey : service.getEngineKeys()) { + LOGGER.info("{}", service.getStatus(engineKey)); + } + while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { + ThreadUtilities.sleep(200); + } + if (!service.isStarted()) { + fail("Apex Service " + service.getKey() + " failed to start after " + MAX_START_WAIT + " ms"); + } + + // Send some events + final Date testStartTime = new Date(); + final Map eventDataMap = new HashMap(); + eventDataMap.put("TestSlogan", "This is a test slogan"); + eventDataMap.put("TestMatchCase", (byte) 123); + eventDataMap.put("TestTimestamp", testStartTime.getTime()); + eventDataMap.put("TestTemperature", 34.5445667); + + final ApexEvent event1 = + new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + event1.putAll(eventDataMap); + event1.setExecutionId(System.nanoTime()); + + final ApexEventListener myEventListener1 = new ApexEventListener() { + @Override + public void onApexEvent(final ApexEvent responseEvent) { + assertNotNull("Synchronous sendEventWait failed", responseEvent); + assertEquals(event1.getExecutionId(), responseEvent.getExecutionId()); + waitFlag = false; + } + }; + + waitFlag = true; + service.registerActionListener("Listener1", myEventListener1); + service.getEngineServiceEventInterface().sendEvent(event1); + + while (waitFlag) { + ThreadUtilities.sleep(100); + } + + final ApexEvent event2 = + new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + event2.setExecutionId(System.nanoTime()); + event2.putAll(eventDataMap); + + final ApexEventListener myEventListener2 = new ApexEventListener() { + @Override + public void onApexEvent(final ApexEvent responseEvent) { + assertNotNull("Synchronous sendEventWait failed", responseEvent); + assertEquals(event2.getExecutionId(), responseEvent.getExecutionId()); + assertEquals(2, actionEventsReceived); + waitFlag = false; + } + }; + + waitFlag = true; + service.deregisterActionListener("Listener1"); + service.registerActionListener("Listener2", myEventListener2); + service.getEngineServiceEventInterface().sendEvent(event2); + + while (waitFlag) { + ThreadUtilities.sleep(100); + } + service.deregisterActionListener("Listener2"); + + actionEventsReceived = 0; + + // Stop all engines on this engine service + final long stoptime = System.currentTimeMillis(); + service.stop(); + while (!service.isStopped() && System.currentTimeMillis() - stoptime < MAX_STOP_WAIT) { + ThreadUtilities.sleep(200); + } + if (!service.isStopped()) { + fail("Apex Service " + service.getKey() + " failed to stop after " + MAX_STOP_WAIT + " ms"); + } + } + + /** + * Update the engine then test the engine with 2 sample events - again. + * + * @throws ApexException if there is a problem + */ + @Test + public void testExecutionSet2() throws ApexException { + service.updateModel(parameters.getEngineKey(), apexModelString, true); + // Start the service + service.startAll(); + final long starttime = System.currentTimeMillis(); + for (final AxArtifactKey engineKey : service.getEngineKeys()) { + LOGGER.info("{}", service.getStatus(engineKey)); + } + while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { + ThreadUtilities.sleep(200); + } + if (!service.isStarted()) { + fail("Apex Service " + service.getKey() + " failed to start after " + MAX_START_WAIT + " ms"); + } + + final EngineServiceEventInterface engineServiceEventInterface = service.getEngineServiceEventInterface(); + + // Send some events + final Date testStartTime = new Date(); + final Map eventDataMap = new HashMap(); + eventDataMap.put("TestSlogan", "This is a test slogan"); + eventDataMap.put("TestMatchCase", (byte) 123); + eventDataMap.put("TestTimestamp", testStartTime.getTime()); + eventDataMap.put("TestTemperature", 34.5445667); + + final ApexEvent event = + new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + event.setExecutionId(System.nanoTime()); + event.putAll(eventDataMap); + engineServiceEventInterface.sendEvent(event); + + final ApexEvent event2 = + new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + event2.setExecutionId(System.nanoTime()); + event2.putAll(eventDataMap); + engineServiceEventInterface.sendEvent(event2); + + // Wait for results + final long recvtime = System.currentTimeMillis(); + while (actionEventsReceived < 2 && System.currentTimeMillis() - recvtime < MAX_RECV_WAIT) { + ThreadUtilities.sleep(100); + } + ThreadUtilities.sleep(500); + assertEquals(2, actionEventsReceived); + actionEventsReceived = 0; + + // Stop all engines on this engine service + final long stoptime = System.currentTimeMillis(); + service.stop(); + while (!service.isStopped() && System.currentTimeMillis() - stoptime < MAX_STOP_WAIT) { + ThreadUtilities.sleep(200); + } + if (!service.isStopped()) { + fail("Apex Service " + service.getKey() + " failed to stop after " + MAX_STOP_WAIT + " ms"); + } + } + + /** + * Update the engine then test the engine with 2 sample events - again. + * + * @throws ApexException if there is a problem + */ + @Test + public void testExecutionSet2Sync() throws ApexException { + service.updateModel(parameters.getEngineKey(), apexModelString, true); + // Start the service + service.startAll(); + final long starttime = System.currentTimeMillis(); + for (final AxArtifactKey engineKey : service.getEngineKeys()) { + LOGGER.info("{}", service.getStatus(engineKey)); + } + while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { + ThreadUtilities.sleep(200); + } + if (!service.isStarted()) { + fail("Apex Service " + service.getKey() + " failed to start after " + MAX_START_WAIT + " ms"); + } + + // Send some events + final Date testStartTime = new Date(); + final Map eventDataMap = new HashMap(); + eventDataMap.put("TestSlogan", "This is a test slogan"); + eventDataMap.put("TestMatchCase", (byte) 123); + eventDataMap.put("TestTimestamp", testStartTime.getTime()); + eventDataMap.put("TestTemperature", 34.5445667); + + final ApexEvent event1 = + new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + event1.putAll(eventDataMap); + + final ApexEventListener myEventListener1 = new ApexEventListener() { + @Override + public void onApexEvent(final ApexEvent responseEvent) { + assertNotNull("Synchronous sendEventWait failed", responseEvent); + assertEquals(event1.getExecutionId(), responseEvent.getExecutionId()); + waitFlag = false; + } + }; + + waitFlag = true; + service.registerActionListener("Listener1", myEventListener1); + service.getEngineServiceEventInterface().sendEvent(event1); + + while (waitFlag) { + ThreadUtilities.sleep(100); + } + + final ApexEvent event2 = + new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + event2.putAll(eventDataMap); + + final ApexEventListener myEventListener2 = new ApexEventListener() { + @Override + public void onApexEvent(final ApexEvent responseEvent) { + assertNotNull("Synchronous sendEventWait failed", responseEvent); + assertEquals(event2.getExecutionId(), responseEvent.getExecutionId()); + waitFlag = false; + } + }; + + waitFlag = true; + service.registerActionListener("Listener2", myEventListener2); + service.deregisterActionListener("Listener1"); + service.getEngineServiceEventInterface().sendEvent(event2); + + while (waitFlag) { + ThreadUtilities.sleep(100); + } + + service.deregisterActionListener("Listener2"); + + assertEquals(2, actionEventsReceived); + + actionEventsReceived = 0; + + // Stop all engines on this engine service + final long stoptime = System.currentTimeMillis(); + service.stop(); + while (!service.isStopped() && System.currentTimeMillis() - stoptime < MAX_STOP_WAIT) { + ThreadUtilities.sleep(200); + } + if (!service.isStopped()) { + fail("Apex Service " + service.getKey() + " failed to stop after " + MAX_STOP_WAIT + " ms"); + } + } + + /** + * Tear down the the test infrastructure. + * + * @throws ApexException if there is an error + */ + @AfterClass + public static void tearDown() throws Exception { + // Stop all engines on this engine service + final long stoptime = System.currentTimeMillis(); + service.stop(); + while (!service.isStopped() && System.currentTimeMillis() - stoptime < MAX_STOP_WAIT) { + ThreadUtilities.sleep(200); + } + if (!service.isStopped()) { + fail("Apex Service " + service.getKey() + " failed to stop after " + MAX_STOP_WAIT + " ms"); + } + service = null; + } + + /** + * The listener interface for receiving test events. The class that is interested in processing + * a test event implements this interface, and the object created with that class is registered + * with a component using the component's addTestListener method. When the test + * event occurs, that object's appropriate method is invoked. + * + * @see TestEvent + */ + private static final class TestListener implements ApexEventListener { + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.service.engine.runtime.ApexEventListener#onApexEvent(org.onap.policy + * .apex.service.engine.event.ApexEvent) + */ + @Override + public synchronized void onApexEvent(final ApexEvent event) { + LOGGER.debug("result 1 is:" + event); + checkResult(event); + actionEventsReceived++; + + final Date testStartTime = new Date((Long) event.get("TestTimestamp")); + final Date testEndTime = new Date(); + + LOGGER.info("policy execution time: " + (testEndTime.getTime() - testStartTime.getTime()) + "ms"); + } + + /** + * Check result. + * + * @param result the result + */ + private void checkResult(final ApexEvent result) { + assertTrue(result.getName().startsWith("Event0004") || result.getName().startsWith("Event0104")); + + assertTrue(result.get("TestSlogan").equals("This is a test slogan")); + assertTrue(result.get("TestMatchCase").equals(new Byte((byte) 123))); + assertTrue(result.get("TestTemperature").equals(34.5445667)); + assertTrue(((byte) result.get("TestMatchCaseSelected")) >= 0 + && ((byte) result.get("TestMatchCaseSelected") <= 3)); + assertTrue(((byte) result.get("TestEstablishCaseSelected")) >= 0 + && ((byte) result.get("TestEstablishCaseSelected") <= 3)); + assertTrue(((byte) result.get("TestDecideCaseSelected")) >= 0 + && ((byte) result.get("TestDecideCaseSelected") <= 3)); + assertTrue( + ((byte) result.get("TestActCaseSelected")) >= 0 && ((byte) result.get("TestActCaseSelected") <= 3)); + } + } +} diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/utils/Utils.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/utils/Utils.java new file mode 100644 index 000000000..0d239a8ef --- /dev/null +++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/engine/utils/Utils.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.testsuites.performance.benchmark.engine.utils; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelWriter; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; + +/** + * The Class Utils. + */ +public class Utils { + + /** + * Instantiates a new utils. + */ + private Utils() {} + + /** + * Gets the model string. + * + * @param ecaPolicyModel the eca policy model + * @return the model string + * @throws ApexModelException the apex model exception + * @throws IOException Signals that an I/O exception has occurred. + */ + public static String getModelString(final AxPolicyModel ecaPolicyModel) throws ApexModelException, IOException { + try (final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream()) { + new ApexModelWriter(AxPolicyModel.class).write(ecaPolicyModel, baOutputStream); + return baOutputStream.toString(); + } + } + +} diff --git a/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetrics.java b/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetrics.java deleted file mode 100644 index 3d257f89a..000000000 --- a/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/ConcurrentContextMetrics.java +++ /dev/null @@ -1,322 +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 static org.onap.policy.apex.context.parameters.DistributorParameters.DEFAULT_DISTRIBUTOR_PLUGIN_CLASS; -import static org.onap.policy.apex.context.parameters.LockManagerParameters.DEFAULT_LOCK_MANAGER_PLUGIN_CLASS; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.Map; -import java.util.Map.Entry; - -import org.onap.policy.apex.context.parameters.ContextParameters; -import org.onap.policy.apex.context.parameters.DistributorParameters; -import org.onap.policy.apex.context.test.concepts.TestContextLongItem; -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.ZooKeeperServerServiceProvider; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; -import org.onap.policy.apex.plugins.context.distribution.hazelcast.HazelcastContextDistributor; -import org.onap.policy.apex.plugins.context.distribution.infinispan.InfinispanContextDistributor; -import org.onap.policy.apex.plugins.context.distribution.infinispan.InfinispanDistributorParameters; -import org.onap.policy.apex.plugins.context.locking.curator.CuratorLockManager; -import org.onap.policy.apex.plugins.context.locking.curator.CuratorLockManagerParameters; -import org.onap.policy.apex.plugins.context.locking.hazelcast.HazelcastLockManager; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class concurrentContextMetrics tests concurrent use of context. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ConcurrentContextMetrics { - private static final int NUM_ARGS = 9; - private static final int ARG_LABEL = 0; - private static final int ARG_JVM_COUNT = 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 ARG_ZOOKEEPER_ADDRESS = 6; - private static final int ARG_ZOOKEEPER_PORT = 7; - private static final int ARG_ZOOKEEPER_DIRECTORY = 8; - - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ConcurrentContextMetrics.class); - - private String zookeeperAddress = null; - private final ConfigrationProvider configrationProvider; - private final File zookeeperDirectory; - private final int zookeeperPort; - - /** - * The main method. - * - * @param args the args - * @throws Exception the exception - */ - public static void main(final String[] args) throws Exception { - if (args.length != NUM_ARGS) { - System.err.println("Args: " + Arrays.toString(args)); - System.err.println( - "usage: testLabel jvmCount threadCount threadLoops longArraySize lockType zookeeperAddress zookeeperPort zookeeperDirectory"); - return; - } - - final ConfigrationProvider configrationProvider = - new ConfigrationProviderImpl(args[ARG_LABEL], Integer.valueOf(args[ARG_JVM_COUNT]), - Integer.valueOf(args[ARG_THREAD_COUNT]), Integer.valueOf(args[ARG_ITERATIONS]), - Integer.valueOf(args[ARG_ARRAY_SIZE]), Integer.valueOf(args[ARG_LOCK_TYPE])); - - final ConcurrentContextMetrics concurrentContextMetrics = new ConcurrentContextMetrics(configrationProvider, - args[ARG_ZOOKEEPER_ADDRESS], Integer.valueOf(args[ARG_ZOOKEEPER_PORT]), args[ARG_ZOOKEEPER_DIRECTORY]); - - concurrentContextMetrics.concurrentContextMetricsJVMLocal(); - concurrentContextMetrics.concurrentContextMetricsCurator(); - concurrentContextMetrics.concurrentContextMetricsHazelcast(); - concurrentContextMetrics.concurrentContextMetricsHazelcastMultiJVMHazelcastLock(); - concurrentContextMetrics.concurrentContextMetricsInfinispanMultiJVMHazelcastlock(); - concurrentContextMetrics.concurrentContextMetricsInfinispanMultiJVMCuratorLock(); - concurrentContextMetrics.concurrentContextMetricsHazelcastMultiJVMCuratorLock(); - } - - /** - * The Constructor. - * - * @param configrationProvider - * @param zookeeperAddress - * @param zookeeperPort - * @param zookeeperDirectory - */ - public ConcurrentContextMetrics(final ConfigrationProvider configrationProvider, final String zookeeperAddress, - final int zookeeperPort, final String zookeeperDirectory) { - this.configrationProvider = configrationProvider; - this.zookeeperAddress = zookeeperAddress; - this.zookeeperPort = zookeeperPort; - this.zookeeperDirectory = new File(zookeeperDirectory); - } - - /** - * Concurrent context metrics JVM local. - * - * @throws ApexModelException the apex model exception - * @throws IOException the IO exception - * @throws ApexException the apex exception - */ - private void concurrentContextMetricsJVMLocal() throws ApexModelException, IOException, ApexException { - if (configrationProvider.getJvmCount() != 1) { - return; - } - - LOGGER.debug("Running concurrentContextMetricsJVMLocalVarSet metrics . . ."); - - final ContextParameters contextParameters = new ContextParameters(); - contextParameters.getDistributorParameters().setPluginClass(DEFAULT_DISTRIBUTOR_PLUGIN_CLASS); - contextParameters.getLockManagerParameters().setPluginClass(DEFAULT_LOCK_MANAGER_PLUGIN_CLASS); - runConcurrentContextMetrics("JVMLocal"); - - LOGGER.debug("Ran concurrentContextMetricsJVMLocalVarSet metrics"); - } - - /** - * Concurrent context metrics hazelcast. - * - * @throws IOException the IO exception - * @throws ApexException the apex exception - */ - private void concurrentContextMetricsHazelcast() throws IOException, ApexException { - if (configrationProvider.getJvmCount() != 1) { - return; - } - - LOGGER.debug("Running concurrentContextMetricsHazelcast metrics . . ."); - - final ContextParameters contextParameters = new ContextParameters(); - contextParameters.getDistributorParameters().setPluginClass(DEFAULT_DISTRIBUTOR_PLUGIN_CLASS); - contextParameters.getLockManagerParameters().setPluginClass(HazelcastLockManager.class.getCanonicalName()); - runConcurrentContextMetrics("Hazelcast"); - - LOGGER.debug("Ran concurrentContextMetricsHazelcast metrics"); - } - - /** - * Concurrent context metrics curator. - * - * @throws IOException the IO exception - * @throws ApexException the apex exception - */ - private void concurrentContextMetricsCurator() throws IOException, ApexException { - if (configrationProvider.getJvmCount() != 1) { - return; - } - - LOGGER.debug("Running concurrentContextMetricsCurator metrics . . ."); - - final ContextParameters contextParameters = new ContextParameters(); - contextParameters.getDistributorParameters().setPluginClass(DEFAULT_DISTRIBUTOR_PLUGIN_CLASS); - - final CuratorLockManagerParameters curatorParameters = new CuratorLockManagerParameters(); - curatorParameters.setPluginClass(CuratorLockManager.class.getCanonicalName()); - contextParameters.setLockManagerParameters(curatorParameters); - curatorParameters.setZookeeperAddress(zookeeperAddress); - - runConcurrentContextMetrics("Curator"); - - LOGGER.debug("Ran concurrentContextMetricsCurator metrics"); - } - - /** - * Concurrent context metrics hazelcast multi JVM hazelcast lock. - * - * @throws IOException the IO exception - * @throws ApexException the apex exception - */ - private void concurrentContextMetricsHazelcastMultiJVMHazelcastLock() throws IOException, ApexException { - LOGGER.debug("Running concurrentContextMetricsHazelcastMultiJVMHazelcastLock metrics . . ."); - - final ContextParameters contextParameters = new ContextParameters(); - final DistributorParameters distributorParameters = contextParameters.getDistributorParameters(); - distributorParameters.setPluginClass(HazelcastContextDistributor.class.getCanonicalName()); - contextParameters.getLockManagerParameters().setPluginClass(HazelcastLockManager.class.getCanonicalName()); - runConcurrentContextMetrics("HazelcastMultiJVMHazelcastLock"); - - LOGGER.debug("Ran concurrentContextMetricsHazelcastMultiJVMHazelcastLock metrics"); - } - - /** - * Concurrent context metrics infinispan multi JVM hazelcastlock. - * - * @throws IOException the IO exception - * @throws ApexException the apex exception - */ - private void concurrentContextMetricsInfinispanMultiJVMHazelcastlock() throws IOException, ApexException { - LOGGER.debug("Running concurrentContextMetricsInfinispanMultiJVMHazelcastlock metrics . . ."); - - final ContextParameters contextParameters = new ContextParameters(); - final DistributorParameters distributorParameters = contextParameters.getDistributorParameters(); - distributorParameters.setPluginClass(InfinispanContextDistributor.class.getCanonicalName()); - contextParameters.getLockManagerParameters().setPluginClass(HazelcastLockManager.class.getCanonicalName()); - - final InfinispanDistributorParameters infinispanParameters = new InfinispanDistributorParameters(); - contextParameters.setDistributorParameters(infinispanParameters); - - runConcurrentContextMetrics("InfinispanMultiJVMHazelcastlock"); - - LOGGER.debug("Ran concurrentContextMetricsInfinispanMultiJVMHazelcastlock metrics"); - } - - /** - * Concurrent context metrics infinispan multi JVM curator lock. - * - * @throws IOException the IO exception - * @throws ApexException the apex exception - * @throws InterruptedException - */ - private void concurrentContextMetricsInfinispanMultiJVMCuratorLock() - throws IOException, ApexException, InterruptedException { - - LOGGER.debug("Running concurrentContextMetricsInfinispanMultiJVMCuratorLock metrics . . ."); - - final ZooKeeperServerServiceProvider zooKeeperServerServiceProvider = - new ZooKeeperServerServiceProvider(zookeeperDirectory, zookeeperAddress, zookeeperPort); - try { - zooKeeperServerServiceProvider.startZookeeperServer(); - final ContextParameters contextParameters = new ContextParameters(); - final DistributorParameters distributorParameters = contextParameters.getDistributorParameters(); - distributorParameters.setPluginClass(InfinispanContextDistributor.class.getCanonicalName()); - - final CuratorLockManagerParameters curatorParameters = new CuratorLockManagerParameters(); - curatorParameters.setPluginClass(CuratorLockManager.class.getCanonicalName()); - contextParameters.setLockManagerParameters(curatorParameters); - curatorParameters.setZookeeperAddress(zookeeperAddress); - - final InfinispanDistributorParameters infinispanParameters = new InfinispanDistributorParameters(); - contextParameters.setDistributorParameters(infinispanParameters); - - runConcurrentContextMetrics("InfinispanMultiJVMCuratorLock"); - } finally { - zooKeeperServerServiceProvider.stopZookeeperServer(); - } - LOGGER.debug("Ran concurrentContextMetricsInfinispanMultiJVMCuratorLock metrics"); - } - - /** - * Concurrent context metrics hazelcast multi JVM curator lock. - * - * @throws IOException the IO exception - * @throws ApexException the apex exception - * @throws InterruptedException - */ - private void concurrentContextMetricsHazelcastMultiJVMCuratorLock() - throws IOException, ApexException, InterruptedException { - LOGGER.debug("Running concurrentContextMetricsHazelcastMultiJVMCuratorLock metrics . . ."); - - final ZooKeeperServerServiceProvider zooKeeperServerServiceProvider = - new ZooKeeperServerServiceProvider(zookeeperDirectory, zookeeperAddress, zookeeperPort); - - try { - zooKeeperServerServiceProvider.startZookeeperServer(); - final ContextParameters contextParameters = new ContextParameters(); - final DistributorParameters distributorParameters = contextParameters.getDistributorParameters(); - distributorParameters.setPluginClass(HazelcastContextDistributor.class.getCanonicalName()); - - final CuratorLockManagerParameters curatorParameters = new CuratorLockManagerParameters(); - curatorParameters.setPluginClass(CuratorLockManager.class.getCanonicalName()); - contextParameters.setLockManagerParameters(curatorParameters); - curatorParameters.setZookeeperAddress(zookeeperAddress); - - runConcurrentContextMetrics("HazelcastMultiJVMCuratorLock"); - } finally { - zooKeeperServerServiceProvider.stopZookeeperServer(); - } - LOGGER.debug("Ran concurrentContextMetricsHazelcastMultiJVMCuratorLock metrics"); - } - - /** - * Run concurrent context metrics. - * - * @param testName the test name - * @throws IOException the IO exception - * @throws ApexException the apex exception - */ - private void runConcurrentContextMetrics(final String testName) throws IOException, ApexException { - final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); - - LOGGER.info("Running {} ...", testName); - final Map result = concurrentContext.testConcurrentContext(); - - 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); - - LOGGER.info("Completed {} ...", testName); - } - - -} diff --git a/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/package-info.java b/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/package-info.java deleted file mode 100644 index 5e916b6db..000000000 --- a/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/plugins/context/metrics/package-info.java +++ /dev/null @@ -1,27 +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========================================================= - */ - -/** - * Used to get metrics on the performance of Context Album performance for various types of - * distribution and locking mechanisms in APEX. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -package org.onap.policy.apex.plugins.context.metrics; diff --git a/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/testsuites/performance/context/metrics/ConcurrentContextMetrics.java b/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/testsuites/performance/context/metrics/ConcurrentContextMetrics.java new file mode 100644 index 000000000..c4e4de480 --- /dev/null +++ b/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/testsuites/performance/context/metrics/ConcurrentContextMetrics.java @@ -0,0 +1,323 @@ +/*- + * ============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.testsuites.performance.context.metrics; + +import static org.onap.policy.apex.context.parameters.DistributorParameters.DEFAULT_DISTRIBUTOR_PLUGIN_CLASS; +import static org.onap.policy.apex.context.parameters.LockManagerParameters.DEFAULT_LOCK_MANAGER_PLUGIN_CLASS; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Map; +import java.util.Map.Entry; + +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.parameters.DistributorParameters; +import org.onap.policy.apex.context.test.concepts.TestContextLongItem; +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.ZooKeeperServerServiceProvider; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; +import org.onap.policy.apex.plugins.context.distribution.hazelcast.HazelcastContextDistributor; +import org.onap.policy.apex.plugins.context.distribution.infinispan.InfinispanContextDistributor; +import org.onap.policy.apex.plugins.context.distribution.infinispan.InfinispanDistributorParameters; +import org.onap.policy.apex.plugins.context.locking.curator.CuratorLockManager; +import org.onap.policy.apex.plugins.context.locking.curator.CuratorLockManagerParameters; +import org.onap.policy.apex.plugins.context.locking.hazelcast.HazelcastLockManager; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class concurrentContextMetrics tests concurrent use of context. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ConcurrentContextMetrics { + private static final int NUM_ARGS = 9; + private static final int ARG_LABEL = 0; + private static final int ARG_JVM_COUNT = 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 ARG_ZOOKEEPER_ADDRESS = 6; + private static final int ARG_ZOOKEEPER_PORT = 7; + private static final int ARG_ZOOKEEPER_DIRECTORY = 8; + + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(ConcurrentContextMetrics.class); + + private String zookeeperAddress = null; + private final ConfigrationProvider configrationProvider; + private final File zookeeperDirectory; + private final int zookeeperPort; + + /** + * The main method. + * + * @param args the args + * @throws Exception the exception + */ + public static void main(final String[] args) throws Exception { + if (args.length != NUM_ARGS) { + String errorMessage = "Args: " + Arrays.toString(args) + + "\nusage: testLabel jvmCount threadCount threadLoops longArraySize lockType " + + "zookeeperAddress zookeeperPort zookeeperDirectory"; + LOGGER.info(errorMessage); + return; + } + + final ConfigrationProvider configrationProvider = new ConfigrationProviderImpl(args[ARG_LABEL], + Integer.valueOf(args[ARG_JVM_COUNT]), Integer.valueOf(args[ARG_THREAD_COUNT]), + Integer.valueOf(args[ARG_ITERATIONS]), Integer.valueOf(args[ARG_ARRAY_SIZE]), + Integer.valueOf(args[ARG_LOCK_TYPE])); + + final ConcurrentContextMetrics concurrentContextMetrics = new ConcurrentContextMetrics(configrationProvider, + args[ARG_ZOOKEEPER_ADDRESS], Integer.valueOf(args[ARG_ZOOKEEPER_PORT]), + args[ARG_ZOOKEEPER_DIRECTORY]); + + concurrentContextMetrics.concurrentContextMetricsJvmLocal(); + concurrentContextMetrics.concurrentContextMetricsCurator(); + concurrentContextMetrics.concurrentContextMetricsHazelcast(); + concurrentContextMetrics.concurrentContextMetricsHazelcastMultiJvmHazelcastLock(); + concurrentContextMetrics.concurrentContextMetricsInfinispanMultiJvmHazelcastlock(); + concurrentContextMetrics.concurrentContextMetricsInfinispanMultiJvmCuratorLock(); + concurrentContextMetrics.concurrentContextMetricsHazelcastMultiJvmCuratorLock(); + } + + /** + * Construct a concurrent context object. + * + * @param configrationProvider Configuration for the context metrics + * @param zookeeperAddress Zookeeper address + * @param zookeeperPort Zookeeper port + * @param zookeeperDirectory Zookeeper directory + */ + public ConcurrentContextMetrics(final ConfigrationProvider configrationProvider, final String zookeeperAddress, + final int zookeeperPort, final String zookeeperDirectory) { + this.configrationProvider = configrationProvider; + this.zookeeperAddress = zookeeperAddress; + this.zookeeperPort = zookeeperPort; + this.zookeeperDirectory = new File(zookeeperDirectory); + } + + /** + * Concurrent context metrics JVM local. + * + * @throws ApexModelException the apex model exception + * @throws IOException the IO exception + * @throws ApexException the apex exception + */ + private void concurrentContextMetricsJvmLocal() throws IOException, ApexException { + if (configrationProvider.getJvmCount() != 1) { + return; + } + + LOGGER.debug("Running concurrentContextMetricsJVMLocalVarSet metrics . . ."); + + final ContextParameters contextParameters = new ContextParameters(); + contextParameters.getDistributorParameters().setPluginClass(DEFAULT_DISTRIBUTOR_PLUGIN_CLASS); + contextParameters.getLockManagerParameters().setPluginClass(DEFAULT_LOCK_MANAGER_PLUGIN_CLASS); + runConcurrentContextMetrics("JVMLocal"); + + LOGGER.debug("Ran concurrentContextMetricsJVMLocalVarSet metrics"); + } + + /** + * Concurrent context metrics hazelcast. + * + * @throws IOException the IO exception + * @throws ApexException the apex exception + */ + private void concurrentContextMetricsHazelcast() throws IOException, ApexException { + if (configrationProvider.getJvmCount() != 1) { + return; + } + + LOGGER.debug("Running concurrentContextMetricsHazelcast metrics . . ."); + + final ContextParameters contextParameters = new ContextParameters(); + contextParameters.getDistributorParameters().setPluginClass(DEFAULT_DISTRIBUTOR_PLUGIN_CLASS); + contextParameters.getLockManagerParameters().setPluginClass(HazelcastLockManager.class.getCanonicalName()); + runConcurrentContextMetrics("Hazelcast"); + + LOGGER.debug("Ran concurrentContextMetricsHazelcast metrics"); + } + + /** + * Concurrent context metrics curator. + * + * @throws IOException the IO exception + * @throws ApexException the apex exception + */ + private void concurrentContextMetricsCurator() throws IOException, ApexException { + if (configrationProvider.getJvmCount() != 1) { + return; + } + + LOGGER.debug("Running concurrentContextMetricsCurator metrics . . ."); + + final ContextParameters contextParameters = new ContextParameters(); + contextParameters.getDistributorParameters().setPluginClass(DEFAULT_DISTRIBUTOR_PLUGIN_CLASS); + + final CuratorLockManagerParameters curatorParameters = new CuratorLockManagerParameters(); + curatorParameters.setPluginClass(CuratorLockManager.class.getCanonicalName()); + contextParameters.setLockManagerParameters(curatorParameters); + curatorParameters.setZookeeperAddress(zookeeperAddress); + + runConcurrentContextMetrics("Curator"); + + LOGGER.debug("Ran concurrentContextMetricsCurator metrics"); + } + + /** + * Concurrent context metrics hazelcast multi JVM hazelcast lock. + * + * @throws IOException the IO exception + * @throws ApexException the apex exception + */ + private void concurrentContextMetricsHazelcastMultiJvmHazelcastLock() throws IOException, ApexException { + LOGGER.debug("Running concurrentContextMetricsHazelcastMultiJVMHazelcastLock metrics . . ."); + + final ContextParameters contextParameters = new ContextParameters(); + final DistributorParameters distributorParameters = contextParameters.getDistributorParameters(); + distributorParameters.setPluginClass(HazelcastContextDistributor.class.getCanonicalName()); + contextParameters.getLockManagerParameters().setPluginClass(HazelcastLockManager.class.getCanonicalName()); + runConcurrentContextMetrics("HazelcastMultiJVMHazelcastLock"); + + LOGGER.debug("Ran concurrentContextMetricsHazelcastMultiJVMHazelcastLock metrics"); + } + + /** + * Concurrent context metrics infinispan multi JVM hazelcastlock. + * + * @throws IOException the IO exception + * @throws ApexException the apex exception + */ + private void concurrentContextMetricsInfinispanMultiJvmHazelcastlock() throws IOException, ApexException { + LOGGER.debug("Running concurrentContextMetricsInfinispanMultiJVMHazelcastlock metrics . . ."); + + final ContextParameters contextParameters = new ContextParameters(); + final DistributorParameters distributorParameters = contextParameters.getDistributorParameters(); + distributorParameters.setPluginClass(InfinispanContextDistributor.class.getCanonicalName()); + contextParameters.getLockManagerParameters().setPluginClass(HazelcastLockManager.class.getCanonicalName()); + + final InfinispanDistributorParameters infinispanParameters = new InfinispanDistributorParameters(); + contextParameters.setDistributorParameters(infinispanParameters); + + runConcurrentContextMetrics("InfinispanMultiJVMHazelcastlock"); + + LOGGER.debug("Ran concurrentContextMetricsInfinispanMultiJVMHazelcastlock metrics"); + } + + /** + * Concurrent context metrics infinispan multi JVM curator lock. + * + * @throws IOException the IO exception + * @throws ApexException the apex exception + * @throws InterruptedException on interrupts + */ + private void concurrentContextMetricsInfinispanMultiJvmCuratorLock() + throws IOException, ApexException, InterruptedException { + + LOGGER.debug("Running concurrentContextMetricsInfinispanMultiJVMCuratorLock metrics . . ."); + + final ZooKeeperServerServiceProvider zooKeeperServerServiceProvider = new ZooKeeperServerServiceProvider( + zookeeperDirectory, zookeeperAddress, zookeeperPort); + try { + zooKeeperServerServiceProvider.startZookeeperServer(); + final ContextParameters contextParameters = new ContextParameters(); + final DistributorParameters distributorParameters = contextParameters.getDistributorParameters(); + distributorParameters.setPluginClass(InfinispanContextDistributor.class.getCanonicalName()); + + final CuratorLockManagerParameters curatorParameters = new CuratorLockManagerParameters(); + curatorParameters.setPluginClass(CuratorLockManager.class.getCanonicalName()); + contextParameters.setLockManagerParameters(curatorParameters); + curatorParameters.setZookeeperAddress(zookeeperAddress); + + final InfinispanDistributorParameters infinispanParameters = new InfinispanDistributorParameters(); + contextParameters.setDistributorParameters(infinispanParameters); + + runConcurrentContextMetrics("InfinispanMultiJVMCuratorLock"); + } finally { + zooKeeperServerServiceProvider.stopZookeeperServer(); + } + LOGGER.debug("Ran concurrentContextMetricsInfinispanMultiJVMCuratorLock metrics"); + } + + /** + * Concurrent context metrics hazelcast multi JVM curator lock. + * + * @throws IOException the IO exception + * @throws ApexException the apex exception + * @throws InterruptedException on interrupts + */ + private void concurrentContextMetricsHazelcastMultiJvmCuratorLock() + throws IOException, ApexException, InterruptedException { + LOGGER.debug("Running concurrentContextMetricsHazelcastMultiJVMCuratorLock metrics . . ."); + + final ZooKeeperServerServiceProvider zooKeeperServerServiceProvider = new ZooKeeperServerServiceProvider( + zookeeperDirectory, zookeeperAddress, zookeeperPort); + + try { + zooKeeperServerServiceProvider.startZookeeperServer(); + final ContextParameters contextParameters = new ContextParameters(); + final DistributorParameters distributorParameters = contextParameters.getDistributorParameters(); + distributorParameters.setPluginClass(HazelcastContextDistributor.class.getCanonicalName()); + + final CuratorLockManagerParameters curatorParameters = new CuratorLockManagerParameters(); + curatorParameters.setPluginClass(CuratorLockManager.class.getCanonicalName()); + contextParameters.setLockManagerParameters(curatorParameters); + curatorParameters.setZookeeperAddress(zookeeperAddress); + + runConcurrentContextMetrics("HazelcastMultiJVMCuratorLock"); + } finally { + zooKeeperServerServiceProvider.stopZookeeperServer(); + } + LOGGER.debug("Ran concurrentContextMetricsHazelcastMultiJVMCuratorLock metrics"); + } + + /** + * Run concurrent context metrics. + * + * @param testName the test name + * @throws IOException the IO exception + * @throws ApexException the apex exception + */ + private void runConcurrentContextMetrics(final String testName) throws IOException, ApexException { + final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); + + LOGGER.info("Running {} ...", testName); + final Map result = concurrentContext.testConcurrentContext(); + + 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); + + LOGGER.info("Completed {} ...", testName); + } + +} diff --git a/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/testsuites/performance/context/metrics/package-info.java b/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/testsuites/performance/context/metrics/package-info.java new file mode 100644 index 000000000..9bb84d76b --- /dev/null +++ b/testsuites/performance/performance-context-metrics/src/main/java/org/onap/policy/apex/testsuites/performance/context/metrics/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============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========================================================= + */ + +/** + * Used to get metrics on the performance of Context Album performance for various types of + * distribution and locking mechanisms in APEX. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +package org.onap.policy.apex.testsuites.performance.context.metrics; 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 deleted file mode 100644 index 04b756417..000000000 --- a/testsuites/performance/performance-context-metrics/src/test/java/org/onap/policy/apex/plugins/context/metrics/TestMetrics.java +++ /dev/null @@ -1,80 +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 static org.junit.Assert.fail; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.TreeSet; - -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.common.utils.resources.ResourceUtils; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -public class TestMetrics { - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestMetrics.class); - 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"; - - @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()); - - } - - @Test - 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 exception) { - LOGGER.error("Unexpected error", exception); - fail("Metrics test failed"); - } - } -} diff --git a/testsuites/performance/performance-context-metrics/src/test/java/org/onap/policy/apex/testsuites/performance/context/metrics/TestMetrics.java b/testsuites/performance/performance-context-metrics/src/test/java/org/onap/policy/apex/testsuites/performance/context/metrics/TestMetrics.java new file mode 100644 index 000000000..6414fa81a --- /dev/null +++ b/testsuites/performance/performance-context-metrics/src/test/java/org/onap/policy/apex/testsuites/performance/context/metrics/TestMetrics.java @@ -0,0 +1,94 @@ +/*- + * ============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.testsuites.performance.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.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.testsuites.performance.context.metrics.ConcurrentContextMetrics; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class TestMetrics. + */ +public class TestMetrics { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestMetrics.class); + 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"; + + @Rule + public final TemporaryFolder folder = new TemporaryFolder(); + + /** + * Configure. + * + * @throws Exception the exception + */ + @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()); + + } + + /** + * Gets the single jvm metrics. + * + * @throws IOException Signals that an I/O exception has occurred. + */ + @Test + 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 exception) { + LOGGER.error("Unexpected error", exception); + fail("Metrics test failed"); + } + } +} -- cgit 1.2.3-korg