summaryrefslogtreecommitdiffstats
path: root/testsuites/integration/integration-common/src/main
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-03-05 10:50:48 +0000
committerliamfallon <liam.fallon@est.tech>2020-03-09 18:30:13 +0000
commit6bda5d7e4e80d1aefb4f19203361b7199448e70f (patch)
treeb28a68625cec91c57f0383d185f73fdf165ab558 /testsuites/integration/integration-common/src/main
parentf876b34ec297495df20394c248b899d610e1bcce (diff)
Use Rhino javascript executor in apex-pdp
Integation unit tests resultd in StackOverflowException errors in the Graal Javascript interpreter. Following extensive testing and trouobleshooting, it proved very difficult to fix these issues in Graal as the stck overflow errors were occurring in native class instantiation methods being invoked by Grall on the JVM. The alternative Rhino Javascript engine is developed by mozilla, and was incorporated into the Java 6 JVM and evolved into Nashorn in the Java 8 JVM. Oracle dropped Nashorn in Java 11. However, in parallel, Rhino development has continued. This review brings in the Rhino javascript engine into apex-pdp as the replacement for Nashorn and instead of Graal. Graal seems to be pretty unstable as yet so we may bring it in in future releases but for now Rhino is a more stable and reliable alternative. Issue-ID: POLICY-2106 Change-Id: I0edeff3b0bee404b38e3ebe22001a6e3375a44dc Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'testsuites/integration/integration-common/src/main')
-rw-r--r--testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/java/DefaultTaskLogic.java39
-rw-r--r--testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/testclasses/PingTestClass.java97
-rw-r--r--testsuites/integration/integration-common/src/main/resources/examples/models/JMS/JMSTestModel.json2
-rw-r--r--testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/DefaultStateLogic.javascript13
-rw-r--r--testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/DefaultTaskLogic.javascript17
-rw-r--r--testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/EvalStateLogic.javascript11
-rw-r--r--testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/EvalTaskLogic.javascript14
7 files changed, 55 insertions, 138 deletions
diff --git a/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/java/DefaultTaskLogic.java b/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/java/DefaultTaskLogic.java
index c1c656490..3730bba47 100644
--- a/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/java/DefaultTaskLogic.java
+++ b/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/java/DefaultTaskLogic.java
@@ -21,8 +21,7 @@
package org.onap.policy.apex.testsuites.integration.common.model.java;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
+import java.util.Random;
import org.onap.policy.apex.core.engine.executor.context.TaskExecutionContext;
@@ -36,7 +35,7 @@ public class DefaultTaskLogic {
* Gets the event.
*
* @param executor the executor
- * @return true , if the event exists
+ * @return the event
*/
public boolean getEvent(final TaskExecutionContext executor) {
String idString = executor.subject.getId();
@@ -47,26 +46,20 @@ public class DefaultTaskLogic {
String inFieldsString = executor.inFields.toString();
executor.logger.debug(inFieldsString);
-
- try {
- SecureRandom rand = SecureRandom.getInstanceStrong();
- if (executor.inFields.containsKey("TestDecideCaseSelected")) {
- executor.outFields.put("TestActCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
- executor.outFields.put("TestActStateTime", System.nanoTime());
- } else if (executor.inFields.containsKey("TestEstablishCaseSelected")) {
- executor.outFields.put("TestDecideCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
- executor.outFields.put("TestDecideStateTime", System.nanoTime());
- } else if (executor.inFields.containsKey("TestMatchCaseSelected")) {
- executor.outFields.put("TestEstablishCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
- executor.outFields.put("TestEstablishStateTime", System.nanoTime());
- } else {
- executor.outFields.put("TestMatchCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
- executor.outFields.put("TestMatchStateTime", System.nanoTime());
- }
- } catch (NoSuchAlgorithmException e) {
- executor.logger.error("Exception during Random number generation ", e);
- return false;
+ final Random rand = new Random();
+ if (executor.inFields.containsKey("TestDecideCaseSelected")) {
+ executor.outFields.put("TestActCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
+ executor.outFields.put("TestActStateTime", System.nanoTime());
+ } else if (executor.inFields.containsKey("TestEstablishCaseSelected")) {
+ executor.outFields.put("TestDecideCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
+ executor.outFields.put("TestDecideStateTime", System.nanoTime());
+ } else if (executor.inFields.containsKey("TestMatchCaseSelected")) {
+ executor.outFields.put("TestEstablishCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
+ executor.outFields.put("TestEstablishStateTime", System.nanoTime());
+ } else {
+ executor.outFields.put("TestMatchCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
+ executor.outFields.put("TestMatchStateTime", System.nanoTime());
}
- return true;
+ return true;
}
}
diff --git a/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/testclasses/PingTestClass.java b/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/testclasses/PingTestClass.java
index b64f76b93..1ed5d20f5 100644
--- a/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/testclasses/PingTestClass.java
+++ b/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/testclasses/PingTestClass.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=========================================================
*/
@@ -22,6 +23,8 @@ package org.onap.policy.apex.testsuites.integration.common.testclasses;
import java.io.Serializable;
+import lombok.Data;
+
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
/**
@@ -29,96 +32,17 @@ import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
+@Data
public class PingTestClass implements Serializable {
private static final long serialVersionUID = -3400711508992955886L;
+ private int id = 0;
private String name = "Rose";
private String description = "A rose by any other name would smell as sweet";
private long pingTime = System.currentTimeMillis();
private long pongTime = -1;
/**
- * Gets the name.
- *
- * @return the name
- */
- public String getName() {
- return name;
- }
-
- /**
- * Sets the name.
- *
- * @param name the new name
- */
- public void setName(final String name) {
- this.name = name;
- }
-
- /**
- * Gets the description.
- *
- * @return the description
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * Sets the description.
- *
- * @param description the new description
- */
- public void setDescription(final String description) {
- this.description = description;
- }
-
- /**
- * Gets the ping time.
- *
- * @return the ping time
- */
- public long getPingTime() {
- return pingTime;
- }
-
- /**
- * Sets the ping time.
- *
- * @param pingTime the new ping time
- */
- public void setPingTime(final long pingTime) {
- this.pingTime = pingTime;
- }
-
- /**
- * Gets the pong time.
- *
- * @return the pong time
- */
- public long getPongTime() {
- return pongTime;
- }
-
- /**
- * Sets the pong time.
- *
- * @param pongTime the new pong time
- */
- public void setPongTime(final long pongTime) {
- this.pongTime = pongTime;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public String toString() {
- return "TestPing [name=" + name + ", description=" + description + ", pingTime=" + pingTime + ", pongTime="
- + pongTime + "]";
- }
-
- /**
* Verify the class.
*
* @throws ApexException the apex event exception
@@ -140,8 +64,9 @@ public class PingTestClass implements Serializable {
throw new ApexException("TestPing is not valid, description is incorrect");
}
- if (pongTime <= pingTime) {
- throw new ApexException("TestPing is not valid, pong time is not greater than ping time");
+ if (pongTime < pingTime) {
+ throw new ApexException(
+ "TestPing is not valid, pong time " + pongTime + " is less than ping time " + pingTime);
}
}
}
diff --git a/testsuites/integration/integration-common/src/main/resources/examples/models/JMS/JMSTestModel.json b/testsuites/integration/integration-common/src/main/resources/examples/models/JMS/JMSTestModel.json
index 78c8110b9..67fdcbfe5 100644
--- a/testsuites/integration/integration-common/src/main/resources/examples/models/JMS/JMSTestModel.json
+++ b/testsuites/integration/integration-common/src/main/resources/examples/models/JMS/JMSTestModel.json
@@ -342,7 +342,7 @@
"taskLogic": {
"key": "TaskLogic",
"logicFlavour": "JAVASCRIPT",
- "logic": "var outFieldType = Java.type(\"org.onap.policy.apex.testsuites.integration.common.testclasses.PingTestClass\");\nvar outValue = new outFieldType();\n\nvar inValue = executor.inFields.get(\"PingTestClass\");\n\nexecutor.logger.info(inValue.toString());\n\noutValue.setPingTime(inValue.getPingTime());\noutValue.setPongTime(new Date().getTime());\noutValue.setName(inValue.getName() + \"_out\");\n\noutValue.setDescription(\ninValue.getDescription() +\n\". So Romeo would, were he not Romeo call'd,\" +\n\" retain that dear perfection which he owes, without that title.\");\n\nexecutor.logger.info(outValue.toString();\nexecutor.outFields.put(\"PingTestClass\", outValue)\n\nvar returnValueType = Java.type(\"java.lang.Boolean\");\nvar returnValue = new returnValueType(true);"
+ "logic": "var outFieldType = org.onap.policy.apex.testsuites.integration.common.testclasses.PingTestClass;\nvar outValue = new outFieldType();\n\nvar inValue = executor.inFields.get(\"PingTestClass\");\n\nexecutor.logger.debug(inValue.toString());\n\noutValue.setPingTime(inValue.getPingTime());\noutValue.setPongTime(new Date().getTime());\noutValue.setName(inValue.getName() + \"_out\");\n\noutValue.setDescription(\ninValue.getDescription() +\n\". So Romeo would, were he not Romeo call'd,\" +\n\" retain that dear perfection which he owes, without that title.\");\n\nexecutor.logger.debug(outValue.toString());\nexecutor.outFields.put(\"PingTestClass\", outValue)\n\ntrue;"
}
}
}
diff --git a/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/DefaultStateLogic.javascript b/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/DefaultStateLogic.javascript
index a3f1525d0..6d94ab1ab 100644
--- a/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/DefaultStateLogic.javascript
+++ b/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/DefaultStateLogic.javascript
@@ -6,23 +6,22 @@
* 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=========================================================
*/
-executor.logger.debug(executor.subject.getId());
+executor.logger.debug(executor.getSubject().getId());
var gc = executor.getContextAlbum("GlobalContextAlbum");
executor.logger.debug(gc.getName());
-executor.getSubject().getDefaultTaskKey().copyTo(executor.selectedTask);
-
-var returnValue = executor.isTrue;
+executor.getSubject().getDefaultTaskKey().copyTo(executor.selectedTask)
+true; \ No newline at end of file
diff --git a/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/DefaultTaskLogic.javascript b/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/DefaultTaskLogic.javascript
index 36fd2c4a2..563572057 100644
--- a/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/DefaultTaskLogic.javascript
+++ b/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/DefaultTaskLogic.javascript
@@ -6,28 +6,29 @@
* 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=========================================================
*/
-executor.logger.debug(executor.subject.getId());
+executor.logger.debug(executor.getSubject().getId());
+executor.logger.debug(executor.getInFields());
+
var gc = executor.getContextAlbum("GlobalContextAlbum");
executor.logger.debug(gc.getName());
-executor.logger.debug(executor.inFields.get("TestSlogan"));
-var caseSelectedType = Java.type("java.lang.Byte");
+var caseSelectedType = java.lang.Byte;
executor.outFields.put("Test<STATE_NAME>CaseSelected", new caseSelectedType(<RANDOM_BYTE_VALUE>));
executor.outFields.put("Test<STATE_NAME>StateTime", java.lang.System.nanoTime());
-executor.logger.debug(executor.inFields.get("TestSlogan"));
+executor.logger.debug(executor.getOutFields());
-var returnValue = executor.isTrue;
+true;
diff --git a/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/EvalStateLogic.javascript b/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/EvalStateLogic.javascript
index 5ee2a0448..4fcfda1c1 100644
--- a/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/EvalStateLogic.javascript
+++ b/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/EvalStateLogic.javascript
@@ -6,21 +6,20 @@
* 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=========================================================
*/
-executor.logger.debug(executor.subject.getId());
+executor.logger.debug(executor.getSubject().getId());
executor.subject.defaultTaskKey.copyTo(executor.selectedTask);
-var returnValue = executor.isTrue;
-
+true;
diff --git a/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/EvalTaskLogic.javascript b/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/EvalTaskLogic.javascript
index b29e96fcf..17d3d8a93 100644
--- a/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/EvalTaskLogic.javascript
+++ b/testsuites/integration/integration-common/src/main/resources/org/onap/policy/apex/testsuites/integration/common/model/javascript/EvalTaskLogic.javascript
@@ -6,23 +6,23 @@
* 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=========================================================
*/
-executor.logger.debug(executor.subject.getId());
-executor.logger.debug(executor.inFields.get("name"));
+executor.logger.debug(executor.getSubject().getId());
+executor.logger.debug(executor.getInFields());
executor.outFields.put("State<STATE_NUMBER>Timestamp", java.lang.System.nanoTime());
-executor.logger.debug(executor.outFields.get("name"));
+executor.logger.debug(executor.getOutFields());
-var returnValue = executor.isTrue;
+true; \ No newline at end of file