aboutsummaryrefslogtreecommitdiffstats
path: root/testsuites/integration/integration-uservice-test
diff options
context:
space:
mode:
Diffstat (limited to 'testsuites/integration/integration-uservice-test')
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engdep/EngDepMessagingTest.java230
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engdep/EngineTestServer.java259
2 files changed, 0 insertions, 489 deletions
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engdep/EngDepMessagingTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engdep/EngDepMessagingTest.java
deleted file mode 100644
index 568961adb..000000000
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engdep/EngDepMessagingTest.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
- * ================================================================================
- * 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.integration.uservice.engdep;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-import java.net.URISyntaxException;
-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.context.impl.schema.java.JavaSchemaHelperParameters;
-import org.onap.policy.apex.context.parameters.ContextParameterConstants;
-import org.onap.policy.apex.context.parameters.ContextParameters;
-import org.onap.policy.apex.context.parameters.SchemaParameters;
-import org.onap.policy.apex.core.deployment.BatchDeployer;
-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.service.ModelService;
-import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
-import org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters;
-import org.onap.policy.apex.service.engine.event.ApexEvent;
-import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters;
-import org.onap.policy.apex.testsuites.integration.common.model.SampleDomainModelFactory;
-import org.onap.policy.common.parameters.ParameterService;
-import org.slf4j.ext.XLogger;
-import org.slf4j.ext.XLoggerFactory;
-
-// CHECKSTYLE:OFF: checkstyle:magicNumber
-
-/**
- * The Class EngDepMessagingTest.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-public class EngDepMessagingTest {
- // Logger for this class
- private static final XLogger LOGGER = XLoggerFactory.getXLogger(EngDepMessagingTest.class);
-
- private static final long MAX_START_WAIT = 10000; // 10 sec
-
- private SchemaParameters schemaParameters;
- private ContextParameters contextParameters;
- private EngineServiceParameters engineServiceParameters;
-
- /**
- * Clear relative file root environment variable.
- */
- @Before
- public void clearRelativeFileRoot() {
- System.clearProperty("APEX_RELATIVE_FILE_ROOT");
- }
-
- /**
- * Before test.
- */
- @Before
- public void beforeTest() {
- schemaParameters = new SchemaParameters();
-
- schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
- schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters());
-
- ParameterService.register(schemaParameters, true);
-
- contextParameters = new ContextParameters();
-
- contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME);
- contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
- contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME);
- contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
-
- ParameterService.register(contextParameters, true);
- ParameterService.register(contextParameters.getDistributorParameters(), true);
- ParameterService.register(contextParameters.getLockManagerParameters(), true);
- ParameterService.register(contextParameters.getPersistorParameters(), true);
-
- engineServiceParameters = new EngineServiceParameters();
- engineServiceParameters.setName("EngDepMessagingTest");
- engineServiceParameters.setVersion("0.0.1");
- engineServiceParameters.setDeploymentPort(58820);
- engineServiceParameters.setInstanceCount(3);
- engineServiceParameters.setId(100);
- engineServiceParameters.getEngineParameters().getExecutorParameterMap().put("JAVASCRIPT",
- new JavascriptExecutorParameters());
-
- ParameterService.register(engineServiceParameters, true);
- ParameterService.register(engineServiceParameters.getEngineParameters(), true);
- }
-
- /**
- * After test.
- */
- @After
- public void afterTest() {
- ParameterService.deregister(engineServiceParameters);
- ParameterService.deregister(engineServiceParameters.getEngineParameters());
-
- ParameterService.deregister(contextParameters.getDistributorParameters());
- ParameterService.deregister(contextParameters.getLockManagerParameters());
- ParameterService.deregister(contextParameters.getPersistorParameters());
- ParameterService.deregister(contextParameters);
-
- ParameterService.deregister(schemaParameters);
- }
-
- /**
- * Test EngDep messaging.
- *
- * @throws URISyntaxException the URI syntax exception
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws ApexException the apex exception
- */
- @Test
- public void testEngDepMessaging() throws URISyntaxException, IOException, ApexException {
- LOGGER.debug("engine<-->deployment messaging test starting . . .");
-
- ModelService.clear();
-
- final EngineTestServer server = new EngineTestServer(engineServiceParameters);
- assertNotNull(server);
-
- final Thread serverThread = new Thread(server);
- serverThread.start();
- final long starttime = System.currentTimeMillis();
- while (server.isStarting() && System.currentTimeMillis() - starttime < MAX_START_WAIT) {
- ThreadUtilities.sleep(100);
- }
- if (server.isStarting()) {
- fail("Test server failed to start after " + MAX_START_WAIT + " ms");
- }
-
- final AxPolicyModel apexPolicyModel = new SampleDomainModelFactory().getSamplePolicyModel("JAVASCRIPT");
-
- final BatchDeployer deployer1 = new BatchDeployer("localhost", 58820, System.out);
- assertNotNull(deployer1);
-
- deployer1.init();
- deployer1.deployModel(apexPolicyModel, false, false);
- deployer1.close();
-
- // Send events
- final Date testStartTime = new Date();
- final Map<String, Object> 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 event0 =
- new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", "apex", "test");
- event0.putAll(eventDataMap);
- server.sendEvent(event0);
-
- final ApexEvent event1 =
- new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", "apex", "test");
- event1.putAll(eventDataMap);
- server.sendEvent(event1);
-
- // Wait for results
- while (server.getTotalActionEventsReceived() < 2) {
- ThreadUtilities.sleep(100);
- }
- ThreadUtilities.sleep(500);
-
- assertEquals(2, server.getTotalActionEventsReceived());
-
- deployer1.init();
- deployer1.close();
-
- // Test re-initialization of model
- final BatchDeployer deployer2 = new BatchDeployer("localhost", 58820, System.out);
- assertNotNull(deployer2);
-
- deployer2.init();
- deployer2.deployModel(apexPolicyModel, true, true);
- deployer2.close();
-
- server.sendEvent(event0);
- server.sendEvent(event1);
-
- // Wait for results
- while (server.getTotalActionEventsReceived() < 4) {
- ThreadUtilities.sleep(100);
- }
- ThreadUtilities.sleep(500);
-
- assertEquals(4, server.getTotalActionEventsReceived());
-
- deployer2.init();
- deployer2.close();
-
- server.stopServer();
- LOGGER.debug("engine<-->deployment messaging test finished");
- }
-
- /**
- * Tear down.
- *
- * @throws Exception the exception
- */
- @After
- public void tearDown() throws Exception {
- ModelService.clear();
- }
-}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engdep/EngineTestServer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engdep/EngineTestServer.java
deleted file mode 100644
index 3971f0545..000000000
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engdep/EngineTestServer.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
- * ================================================================================
- * 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.integration.uservice.engdep;
-
-import java.util.Date;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
-import org.onap.policy.apex.service.engine.engdep.EngDepMessagingService;
-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.slf4j.ext.XLogger;
-import org.slf4j.ext.XLoggerFactory;
-
-/**
- * The Class EngineTestServer is a test Apex service used to test the performance of Apex engines.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-public class EngineTestServer implements Runnable, EngineServiceEventInterface {
- private static final XLogger LOGGER = XLoggerFactory.getXLogger(EngineTestServer.class);
-
- private static final int TEST_SERVER_WAIT_TIME = 200;
-
- // The engine service for sending events to the Apex engines and the EngDEp service for engine
- // administration
- private EngineService engineService = null;
- private EngDepMessagingService messageService = null;
-
- // The inner class used to receive and process events
- private TestApexListener testApexListener = null;
-
- // Status flags
- private boolean starting = true;
- private boolean interrupted = false;
-
- // Parameters for the test
- private final EngineServiceParameters parameters;
-
- // Apex performance statistics
- private Date statsStartDate = null;
- private long actionEventsReceivedCount = 0;
- private long accumulatedExecutionTime = 0;
- private long totalActionEventsReceivedCount = 0;
-
- private ApexEvent lastEventReceived = null;
-
- /**
- * Instantiates a new engine test server to test Apex performance.
- *
- * @param parameters the parameters
- */
- public EngineTestServer(final EngineServiceParameters parameters) {
- this.parameters = parameters;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void run() {
- LOGGER.debug("engine<-->deployment test server starting . . .");
-
- // Set the name of the test server thread
- Thread.currentThread().setName(EngineTestServer.class.getName());
-
- try {
- // Create the engine service and set the listener for events emitted by the Apex service
- engineService = EngineServiceImpl.create(parameters);
- testApexListener = new TestApexListener();
- engineService.registerActionListener("testApexListener", testApexListener);
-
- // Create the EngDep messaging service and start it
- messageService = new EngDepMessagingService(engineService, parameters.getDeploymentPort());
- messageService.start();
-
- // Record the start date for statistics
- statsStartDate = new Date();
- } catch (final Exception e) {
- LOGGER.error("engine<-->deployment test server exception", e);
- e.printStackTrace();
- return;
- }
- LOGGER.debug("engine<-->deployment test server started");
-
- starting = false;
-
- while (!interrupted) {
- if (!ThreadUtilities.sleep(TEST_SERVER_WAIT_TIME)) {
- interrupted = true;
- }
- }
- }
-
- /**
- * Stop the test server.
- */
- public void stopServer() {
- LOGGER.debug("engine<-->deployment test server stopping . . .");
-
- interrupted = true;
- messageService.stop();
-
- LOGGER.debug("engine<-->deployment test server stopped");
- }
-
- /**
- * Checks if the test server is interrupted.
- *
- * @return true, if is interrupted
- */
- public boolean isInterrupted() {
- return interrupted;
- }
-
- /**
- * Gets the total action events received.
- *
- * @return the total action events received
- */
- public long getTotalActionEventsReceived() {
- return totalActionEventsReceivedCount;
- }
-
- /**
- * Gets the last action events received.
- *
- * @return the last action event received
- */
- public ApexEvent getLastActionEvent() {
- return lastEventReceived;
- }
-
- /**
- * Gets the Apex statistics and resets them.
- *
- * @return the statistics
- */
- public long[] getAndResetStats() {
- // Check if we have statistics
- if (statsStartDate == null || actionEventsReceivedCount == 0) {
- return null;
- }
-
- // Calculate, save, and reset the statistics
- final long[] stats = new long[2];
- synchronized (statsStartDate) {
- final long averageExecutionTime = accumulatedExecutionTime / actionEventsReceivedCount;
- final long measuringTime = new Date().getTime() - statsStartDate.getTime();
- final long transactionsPerMillisecond = actionEventsReceivedCount / measuringTime;
- stats[0] = averageExecutionTime;
- stats[1] = transactionsPerMillisecond;
- statsStartDate = new Date();
-
- actionEventsReceivedCount = 0;
- accumulatedExecutionTime = 0;
- }
-
- // Return the statistics
- return stats;
- }
-
- /**
- * Checks if the test server is starting.
- *
- * @return true, if the server is starting
- */
- public boolean isStarting() {
- return starting;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public void sendEvent(final ApexEvent event) {
- // Send the event onto the service being tested
- engineService.getEngineServiceEventInterface().sendEvent(event);
- }
-
- /**
- * The listener interface for receiving testApex events. The class that is interested in processing a testApex event
- * implements this interface, and the object created with that class is registered with a component using the
- * component's {@code addTestApexListener} method. When the testApex event occurs, that object's appropriate method
- * is invoked.
- *
- * <p>This class listens for events from the Apex engine
- *
- * @see TestApexEvent
- */
- private final class TestApexListener implements ApexEventListener {
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public synchronized void onApexEvent(final ApexEvent apexEvent) {
- LOGGER.debug("result is:" + apexEvent);
-
- // Check the result event is correct
- checkResult(apexEvent);
-
- // Calculate the performance of the Apex engine service on this policy execution run and
- // accumulate the total statistics
- final Date testStartTime = new Date((Long) apexEvent.get("TestTimestamp"));
- final Date testEndTime = new Date();
- final long testTime = testEndTime.getTime() - testStartTime.getTime();
- LOGGER.debug("policy execution time: " + testTime + "ms");
- synchronized (statsStartDate) {
- actionEventsReceivedCount++;
- totalActionEventsReceivedCount++;
- accumulatedExecutionTime += testTime;
- }
- lastEventReceived = apexEvent;
- }
-
- /**
- * Check that a reply event from the Apex engine is valid.
- *
- * @param result the result event from the Apex engine
- */
- private void checkResult(final ApexEvent result) {
- assert result.getName().startsWith("Event0004") || result.getName().startsWith("Event0104");
-
- // CHECKSTYLE:OFF: checkstyle:magicNumber
- assert result.get("TestSlogan").equals("This is a test slogan");
- assert result.get("TestMatchCase").equals((byte) 123);
- assert result.get("TestTemperature").equals(34.5445667);
- assert ((byte) result.get("TestMatchCaseSelected") >= 0 && (byte) result.get("TestMatchCaseSelected") <= 3);
- assert ((byte) result.get("TestEstablishCaseSelected") >= 0
- && (byte) result.get("TestEstablishCaseSelected") <= 3);
- assert ((byte) result.get("TestDecideCaseSelected") >= 0
- && (byte) result.get("TestDecideCaseSelected") <= 3);
- assert ((byte) result.get("TestActCaseSelected") >= 0 && (byte) result.get("TestActCaseSelected") <= 3);
- // CHECKSTYLE:ON: checkstyle:magicNumber
- }
- }
-}