diff options
Diffstat (limited to 'testsuites/integration/integration-uservice-test/src/test/java')
7 files changed, 52 insertions, 56 deletions
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileIgnore.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileIgnore.java index 6aa73fb07..b9d3bb39b 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileIgnore.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileIgnore.java @@ -51,6 +51,8 @@ public class TestFile2FileIgnore { public static void main(final String[] args) throws MessagingException, ApexException, IOException { final String[] apexArgs = {"-rfr", "target", "-c", "examples/config/SampleDomain/File2FileJsonEvent.json"}; + new File("src/test/resources/events/EventsOut.json").delete(); + testFileEvents(apexArgs, "src/test/resources/events/EventsOut.json", 48656); } diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java index 3baa14714..f785ab6f3 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-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. @@ -69,8 +69,8 @@ public class JmsEventProducer implements Runnable { * @throws JMSException the JMS exception */ public JmsEventProducer(final String topic, final ConnectionFactory connectionFactory, final String username, - final String password, final int eventCount, final boolean sendObjects, final long eventInterval) - throws JMSException { + final String password, final int eventCount, final boolean sendObjects, + final long eventInterval) throws JMSException { this.topic = topic; this.eventCount = eventCount; this.sendObjects = sendObjects; @@ -89,7 +89,7 @@ public class JmsEventProducer implements Runnable { public void run() { final Topic jmsTopic = new ActiveMQTopic(topic); try (final Session jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - final MessageProducer jmsProducer = jmsSession.createProducer(jmsTopic)) { + final MessageProducer jmsProducer = jmsSession.createProducer(jmsTopic)) { while (producerThread.isAlive() && !stopFlag) { ThreadUtilities.sleep(50); @@ -128,7 +128,9 @@ public class JmsEventProducer implements Runnable { Message jmsMessage = null; if (sendObjects) { - jmsMessage = jmsSession.createObjectMessage(new PingTestClass()); + final PingTestClass pingTestClass = new PingTestClass(); + pingTestClass.setId(i); + jmsMessage = jmsSession.createObjectMessage(pingTestClass); } else { jmsMessage = jmsSession.createTextMessage(EventGenerator.jsonEvent()); } diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java index 5140d71cd..bbbf21c6d 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-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. @@ -63,7 +63,7 @@ public class JmsEventSubscriber implements Runnable { * @throws JMSException the JMS exception */ public JmsEventSubscriber(final String topic, final ConnectionFactory connectionFactory, final String username, - final String password) throws JMSException { + final String password) throws JMSException { this.topic = topic; connection = connectionFactory.createConnection(username, password); connection.start(); @@ -79,7 +79,7 @@ public class JmsEventSubscriber implements Runnable { public void run() { final Topic jmsTopic = new ActiveMQTopic(topic); try (final Session jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - final MessageConsumer jmsConsumer = jmsSession.createConsumer(jmsTopic)) { + final MessageConsumer jmsConsumer = jmsSession.createConsumer(jmsTopic)) { while (subscriberThread.isAlive() && !subscriberThread.isInterrupted()) { try { @@ -95,11 +95,13 @@ public class JmsEventSubscriber implements Runnable { ((TextMessage) message).getText(); } else { throw new ApexEventException("unknowm message \"" + message + "\" of type \"" - + message.getClass().getName() + "\" received"); + + message.getClass().getName() + "\" received"); } eventsReceivedCount++; } catch (final Exception e) { - break; + if (!(e.getCause() instanceof InterruptedException)) { + throw new ApexEventRuntimeException("JMS message reception failed", e); + } } } @@ -107,7 +109,8 @@ public class JmsEventSubscriber implements Runnable { throw new ApexEventRuntimeException("JMS event consumption failed", e); } - LOGGER.debug("{} : event reception completed", this.getClass().getName()); + LOGGER.info("{} : event reception completed, {} events received", this.getClass().getName(), + eventsReceivedCount); } /** @@ -125,6 +128,8 @@ public class JmsEventSubscriber implements Runnable { * @throws JMSException the JMS exception */ public void shutdown() throws JMSException { + LOGGER.info("{} : stopping...", this.getClass().getName()); + subscriberThread.interrupt(); while (subscriberThread.isAlive()) { @@ -132,7 +137,7 @@ public class JmsEventSubscriber implements Runnable { } connection.close(); - LOGGER.debug("{} : stopped", this.getClass().getName()); + LOGGER.info("{} : stopped", this.getClass().getName()); } } diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestJms2Jms.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestJms2Jms.java index 60b9711c9..cc06ea039 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestJms2Jms.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/TestJms2Jms.java @@ -21,6 +21,7 @@ package org.onap.policy.apex.testsuites.integration.uservice.adapt.jms; +import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import java.io.IOException; @@ -28,6 +29,7 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.TimeUnit; import javax.jms.JMSException; @@ -39,9 +41,7 @@ import org.apache.activemq.security.SimpleAuthenticationPlugin; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; -import org.junit.Ignore; 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.service.engine.main.ApexMain; import org.slf4j.ext.XLogger; @@ -56,7 +56,6 @@ public class TestJms2Jms { public static final String JMS_TOPIC_APEX_IN = "jms/topic/apexIn"; public static final String JMS_TOPIC_APEX_OUT = "jms/topic/apexOut"; - private static final int SLEEP_TIME = 1500; private static final String GROUP_ROLE = "guests"; private static final String PACKAGE_NAME = "org.onap.policy.apex.testsuites.integration.common.testclasses"; private static final String USERNAME = "guest"; @@ -67,7 +66,6 @@ public class TestJms2Jms { private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestJms2Jms.class); - private static final long MAX_TEST_LENGTH = 10000; private static final int EVENT_COUNT = 100; private static final int EVENT_INTERVAL = 20; @@ -143,7 +141,6 @@ public class TestJms2Jms { * @throws JMSException the JMS exception */ @Test - @Ignore public void testJmsObjectEvents() throws ApexException, JMSException { final String[] args = {"-rfr", "target", "-c", "target/examples/config/JMS/JMS2JMSObjectEvent.json"}; testJmsEvents(args, true); @@ -172,38 +169,24 @@ public class TestJms2Jms { private void testJmsEvents(final String[] args, final Boolean sendObjects) throws ApexException, JMSException { final JmsEventSubscriber subscriber = new JmsEventSubscriber(JMS_TOPIC_APEX_OUT, connectionFactory, USERNAME, PASSWORD); + final JmsEventProducer producer = new JmsEventProducer(JMS_TOPIC_APEX_IN, connectionFactory, USERNAME, PASSWORD, EVENT_COUNT, sendObjects, EVENT_INTERVAL); final ApexMain apexMain = new ApexMain(args); - ThreadUtilities.sleep(3000); + + await().atMost(3L, TimeUnit.SECONDS).until(() -> apexMain.isAlive()); producer.sendEvents(); - final long testStartTime = System.currentTimeMillis(); + await().atMost(10L, TimeUnit.SECONDS).until(() -> producer.getEventsSentCount() >= EVENT_COUNT - 1); + await().atMost(10L, TimeUnit.SECONDS).until(() -> subscriber.getEventsReceivedCount() >= EVENT_COUNT - 1); - while (isTimedOut(testStartTime) && subscriber.getEventsReceivedCount() < EVENT_COUNT) { - ThreadUtilities.sleep(EVENT_INTERVAL); - } - - ThreadUtilities.sleep(SLEEP_TIME); apexMain.shutdown(); subscriber.shutdown(); producer.shutdown(); - ThreadUtilities.sleep(SLEEP_TIME); assertEquals(EVENT_COUNT, producer.getEventsSentCount()); assertEquals(producer.getEventsSentCount(), subscriber.getEventsReceivedCount()); - - } - - /** - * Checks if is timed out. - * - * @param testStartTime the test start time - * @return true, if is timed out - */ - private boolean isTimedOut(final long testStartTime) { - return System.currentTimeMillis() < testStartTime + MAX_TEST_LENGTH; } } 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 index d3a6d76d4..09b0143eb 100644 --- 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 @@ -1,19 +1,20 @@ /*- * ============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========================================================= */ @@ -106,7 +107,7 @@ public class EngDepMessagingTest { engineServiceParameters.setInstanceCount(3); engineServiceParameters.setId(100); engineServiceParameters.getEngineParameters().getExecutorParameterMap().put("JAVASCRIPT", - new JavascriptExecutorParameters()); + new JavascriptExecutorParameters()); ParameterService.register(engineServiceParameters, true); ParameterService.register(engineServiceParameters.getEngineParameters(), true); @@ -171,13 +172,13 @@ public class EngDepMessagingTest { 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"); + 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"); + final ApexEvent event1 = + new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", "apex", "test"); event1.putAll(eventDataMap); server.sendEvent(event1); @@ -225,5 +226,6 @@ public class EngDepMessagingTest { */ @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/engine/ApexServiceTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceTest.java index 052f6a2af..7b25da803 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceTest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceTest.java @@ -50,6 +50,7 @@ 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.handling.ApexModelException; import org.onap.policy.apex.model.basicmodel.handling.ApexModelWriter; +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.plugins.executor.mvel.MvelExecutorParameters; @@ -89,13 +90,8 @@ public class ApexServiceTest { private boolean waitFlag = true; - /** - * Sets the up. - * - * @throws Exception the exception - */ @BeforeClass - public static void setUp() throws Exception { + public static void beforeSetUp() throws Exception { // create engine with 3 threads parameters.setInstanceCount(3); parameters.setName(engineServiceKey.getName()); @@ -116,6 +112,11 @@ public class ApexServiceTest { service.registerActionListener("Listener", listener); } + @AfterClass + public static void afterCleardown() throws Exception { + ModelService.clear(); + } + /** * Set up parameters. */ diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/executionproperties/TestExecutionProperties.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/executionproperties/TestExecutionProperties.java index 9327748b8..ec1bd4113 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/executionproperties/TestExecutionProperties.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/executionproperties/TestExecutionProperties.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-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. @@ -110,7 +110,8 @@ public class TestExecutionProperties { File compiledPolicyFile = new File("target/ExecutionPropertiesTestPolicyModel.json"); assertTrue(compiledPolicyFile.exists()); - new File("target/" + testName + "_out.properties").delete(); + File outFile = new File("target/" + testName + "_out.properties"); + outFile.deleteOnExit(); // @formatter:off final String[] args = { @@ -122,9 +123,9 @@ public class TestExecutionProperties { // @formatter:on final ApexMain apexMain = new ApexMain(args); - // TODO: Set back to 10 seconds - await().atMost(10000, TimeUnit.SECONDS) - .until(() -> new File("target/" + testName + "_out.properties").exists()); + await().atMost(1, TimeUnit.SECONDS).until(() -> apexMain.isAlive()); + await().atMost(10, TimeUnit.SECONDS).until(() -> outFile.exists()); + await().atMost(1, TimeUnit.SECONDS).until(() -> outFile.length() > 0); apexMain.shutdown(); @@ -133,7 +134,7 @@ public class TestExecutionProperties { new File("src/test/resources/testdata/executionproperties/" + testName + "_out_expected.properties"))); Properties actualProperties = new Properties(); - actualProperties.load(new FileInputStream(new File("target/" + testName + "_out.properties"))); + actualProperties.load(new FileInputStream(outFile)); assertEquals(expectedProperties, actualProperties); } |