Merge "Fix hanging tests in JavascritExecutor"
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutor.java b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutor.java
index f7bafdd..a33a129 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutor.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutor.java
@@ -26,6 +26,11 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.NonNull;
+import lombok.Setter;
+
import org.apache.commons.lang3.StringUtils;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Script;
@@ -48,6 +53,13 @@
// Recurring string constants
private static final String WITH_MESSAGE = " with message: ";
+ @Setter(AccessLevel.PROTECTED)
+ private static TimeUnit timeunit4Latches = TimeUnit.SECONDS;
+ @Setter(AccessLevel.PROTECTED)
+ private static int intializationLatchTimeout = 60;
+ @Setter(AccessLevel.PROTECTED)
+ private static int cleanupLatchTimeout = 60;
+
// The key of the subject that wants to execute Javascript code
final AxKey subjectKey;
@@ -58,9 +70,10 @@
private final BlockingQueue<Object> executionQueue = new LinkedBlockingQueue<>();
private final BlockingQueue<Boolean> resultQueue = new LinkedBlockingQueue<>();
- private final Thread executorThread;
- private CountDownLatch intializationLatch = new CountDownLatch(1);
- private CountDownLatch shutdownLatch = new CountDownLatch(1);
+ @Getter(AccessLevel.PROTECTED)
+ private Thread executorThread;
+ private CountDownLatch intializationLatch;
+ private CountDownLatch cleanupLatch;
private AtomicReference<StateMachineException> executorException = new AtomicReference<>(null);
/**
@@ -70,9 +83,6 @@
*/
public JavascriptExecutor(final AxKey subjectKey) {
this.subjectKey = subjectKey;
-
- executorThread = new Thread(this);
- executorThread.setName(this.getClass().getSimpleName() + ":" + subjectKey.getId());
}
/**
@@ -81,39 +91,44 @@
* @param javascriptCode the Javascript code to execute
* @throws StateMachineException thrown when instantiation of the executor fails
*/
- public void init(final String javascriptCode) throws StateMachineException {
+ public synchronized void init(@NonNull final String javascriptCode) throws StateMachineException {
LOGGER.debug("JavascriptExecutor {} starting ... ", subjectKey.getId());
- if (executorThread.isAlive()) {
- throw new StateMachineException(
- "initiation failed, executor " + subjectKey.getId() + " is already running");
+ if (executorThread != null) {
+ throw new StateMachineException("initiation failed, executor " + subjectKey.getId()
+ + " already initialized, run cleanUp to clear executor");
}
- if (StringUtils.isEmpty(javascriptCode)) {
- throw new StateMachineException("no logic specified for " + subjectKey.getId());
+ if (StringUtils.isBlank(javascriptCode)) {
+ throw new StateMachineException("initiation failed, no logic specified for executor " + subjectKey.getId());
}
this.javascriptCode = javascriptCode;
+ executorThread = new Thread(this);
+ executorThread.setName(this.getClass().getSimpleName() + ":" + subjectKey.getId());
+ intializationLatch = new CountDownLatch(1);
+ cleanupLatch = new CountDownLatch(1);
+
try {
executorThread.start();
- } catch (Exception e) {
+ } catch (IllegalThreadStateException e) {
throw new StateMachineException("initiation failed, executor " + subjectKey.getId() + " failed to start",
e);
}
try {
- if (!intializationLatch.await(60, TimeUnit.SECONDS)) {
- LOGGER.warn("JavascriptExecutor {}, initiation timed out", subjectKey.getId());
+ if (!intializationLatch.await(intializationLatchTimeout, timeunit4Latches)) {
+ executorThread.interrupt();
+ throw new StateMachineException("JavascriptExecutor " + subjectKey.getId()
+ + " initiation timed out after " + intializationLatchTimeout + " " + timeunit4Latches);
}
} catch (InterruptedException e) {
LOGGER.debug("JavascriptExecutor {} interrupted on execution thread startup", subjectKey.getId(), e);
Thread.currentThread().interrupt();
}
- if (executorException.get() != null) {
- clearAndThrowExecutorException();
- }
+ checkAndThrowExecutorException();
LOGGER.debug("JavascriptExecutor {} started ... ", subjectKey.getId());
}
@@ -125,9 +140,14 @@
* @return true if execution was successful, false otherwise
* @throws StateMachineException on execution errors
*/
- public boolean execute(final Object executionContext) throws StateMachineException {
+ public synchronized boolean execute(final Object executionContext) throws StateMachineException {
+ if (executorThread == null) {
+ throw new StateMachineException("execution failed, executor " + subjectKey.getId() + " is not initialized");
+ }
+
if (!executorThread.isAlive()) {
- throw new StateMachineException("execution failed, executor " + subjectKey.getId() + " is not running");
+ throw new StateMachineException("execution failed, executor " + subjectKey.getId()
+ + " is not running, run cleanUp to clear executor and init to restart executor");
}
executionQueue.add(executionContext);
@@ -137,13 +157,13 @@
try {
result = resultQueue.take();
} catch (final InterruptedException e) {
- LOGGER.debug("JavascriptExecutor {} interrupted on execution result wait", subjectKey.getId(), e);
+ executorThread.interrupt();
Thread.currentThread().interrupt();
+ throw new StateMachineException(
+ "JavascriptExecutor " + subjectKey.getId() + "interrupted on execution result wait", e);
}
- if (executorException.get() != null) {
- clearAndThrowExecutorException();
- }
+ checkAndThrowExecutorException();
return result;
}
@@ -153,25 +173,30 @@
*
* @throws StateMachineException thrown when cleanup of the executor fails
*/
- public void cleanUp() throws StateMachineException {
- if (!executorThread.isAlive()) {
- throw new StateMachineException("cleanup failed, executor " + subjectKey.getId() + " is not running");
+ public synchronized void cleanUp() throws StateMachineException {
+ if (executorThread == null) {
+ throw new StateMachineException("cleanup failed, executor " + subjectKey.getId() + " is not initialized");
}
- executorThread.interrupt();
+ if (executorThread.isAlive()) {
+ executorThread.interrupt();
- try {
- if (!shutdownLatch.await(60, TimeUnit.SECONDS)) {
- LOGGER.warn("JavascriptExecutor {}, shutdown timed out", subjectKey.getId());
+ try {
+ if (!cleanupLatch.await(cleanupLatchTimeout, timeunit4Latches)) {
+ executorException.set(new StateMachineException("JavascriptExecutor " + subjectKey.getId()
+ + " cleanup timed out after " + cleanupLatchTimeout + " " + timeunit4Latches));
+ }
+ } catch (InterruptedException e) {
+ LOGGER.debug("JavascriptExecutor {} interrupted on execution cleanup wait", subjectKey.getId(), e);
+ Thread.currentThread().interrupt();
}
- } catch (InterruptedException e) {
- LOGGER.debug("JavascriptExecutor {} interrupted on execution clkeanup wait", subjectKey.getId(), e);
- Thread.currentThread().interrupt();
}
- if (executorException.get() != null) {
- clearAndThrowExecutorException();
- }
+ executorThread = null;
+ executionQueue.clear();
+ resultQueue.clear();
+
+ checkAndThrowExecutorException();
}
@Override
@@ -181,9 +206,10 @@
try {
initExecutor();
} catch (StateMachineException sme) {
- LOGGER.warn("JavascriptExecutor {} initialization failed", sme);
+ LOGGER.warn("JavascriptExecutor {} initialization failed", subjectKey.getId(), sme);
executorException.set(sme);
intializationLatch.countDown();
+ cleanupLatch.countDown();
return;
}
@@ -192,14 +218,12 @@
LOGGER.debug("JavascriptExecutor {} executing ... ", subjectKey.getId());
// Take jobs from the execution queue of the worker and execute them
- while (!executorThread.isInterrupted()) {
+ while (!Thread.currentThread().isInterrupted()) {
try {
Object contextObject = executionQueue.take();
- if (contextObject == null) {
- break;
- }
- resultQueue.add(executeScript(contextObject));
+ boolean result = executeScript(contextObject);
+ resultQueue.add(result);
} catch (final InterruptedException e) {
LOGGER.debug("execution was interruped for " + subjectKey.getId() + WITH_MESSAGE + e.getMessage(), e);
resultQueue.add(false);
@@ -217,7 +241,7 @@
"executor close failed to close for " + subjectKey.getId() + WITH_MESSAGE + e.getMessage(), e));
}
- shutdownLatch.countDown();
+ cleanupLatch.countDown();
LOGGER.debug("JavascriptExecutor {} completed processing", subjectKey.getId());
}
@@ -262,14 +286,10 @@
return (boolean) returnObject;
}
- private void clearAndThrowExecutorException() throws StateMachineException {
+ private void checkAndThrowExecutorException() throws StateMachineException {
StateMachineException exceptionToThrow = executorException.getAndSet(null);
if (exceptionToThrow != null) {
throw exceptionToThrow;
}
}
-
- protected Thread getExecutorThread() {
- return executorThread;
- }
}
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorFullApexTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorFullApexTest.java
index 9a6b8c7..5078c97 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorFullApexTest.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorFullApexTest.java
@@ -28,7 +28,6 @@
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
-import org.junit.Ignore;
import org.junit.Test;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.service.engine.main.ApexMain;
@@ -36,7 +35,6 @@
public class JavascriptExecutorFullApexTest {
- @Ignore
@Test
public void testFullApexPolicy() throws ApexException {
final String[] args = {"src/test/resources/prodcons/File2File.json"};
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorTest.java
new file mode 100644
index 0000000..53781e8
--- /dev/null
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorTest.java
@@ -0,0 +1,335 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * 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.plugins.executor.javascript;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.awaitility.Awaitility.await;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+
+public class JavascriptExecutorTest {
+ private AtomicBoolean concurrentResult = new AtomicBoolean();
+
+ @Before
+ public void beforeSetTimeouts() {
+ JavascriptExecutor.setTimeunit4Latches(TimeUnit.SECONDS);
+ JavascriptExecutor.setIntializationLatchTimeout(60);
+ JavascriptExecutor.setCleanupLatchTimeout(10);
+ }
+
+ @Test
+ public void testJavescriptExecutorConcurrencyNormal() throws StateMachineException, IOException {
+ JavascriptExecutor.setTimeunit4Latches(TimeUnit.SECONDS);
+ JavascriptExecutor.setIntializationLatchTimeout(60);
+ JavascriptExecutor.setCleanupLatchTimeout(10);
+
+ JavascriptExecutor executor = new JavascriptExecutor(new AxArtifactKey("executor:0.0.1"));
+
+ assertThatThrownBy(() -> {
+ executor.init(null);
+ }).hasMessageMatching("^javascriptCode is marked .*on.*ull but is null$");
+
+ assertThatThrownBy(() -> {
+ executor.init(" ");
+ }).hasMessage("initiation failed, no logic specified for executor executor:0.0.1");
+
+ assertThatCode(() -> {
+ executor.init("var x = 1;");
+ }).doesNotThrowAnyException();
+
+ assertThatThrownBy(() -> {
+ executor.init("var x = 1;");
+ }).hasMessage("initiation failed, executor executor:0.0.1 already initialized, run cleanUp to clear executor");
+
+ assertThatCode(() -> {
+ executor.cleanUp();
+ }).doesNotThrowAnyException();
+
+ assertThatThrownBy(() -> {
+ executor.cleanUp();
+ }).hasMessage("cleanup failed, executor executor:0.0.1 is not initialized");
+
+ assertThatThrownBy(() -> {
+ executor.execute("Hello");
+ }).hasMessage("execution failed, executor executor:0.0.1 is not initialized");
+
+ assertThatCode(() -> {
+ executor.init("var x = 1;");
+ }).doesNotThrowAnyException();
+
+ assertThatThrownBy(() -> {
+ executor.execute("Hello");
+ }).hasMessage(
+ "execute: logic for executor:0.0.1 returned a non-boolean value org.mozilla.javascript.Undefined@0");
+
+ assertThatThrownBy(() -> {
+ executor.execute("Hello");
+ }).hasMessage(
+ "execute: logic for executor:0.0.1 returned a non-boolean value org.mozilla.javascript.Undefined@0");
+
+ assertThatThrownBy(() -> {
+ executor.execute("Hello");
+ }).hasMessage(
+ "execute: logic for executor:0.0.1 returned a non-boolean value org.mozilla.javascript.Undefined@0");
+
+ assertThatThrownBy(() -> {
+ executor.execute("Hello");
+ }).hasMessage(
+ "execute: logic for executor:0.0.1 returned a non-boolean value org.mozilla.javascript.Undefined@0");
+
+ assertThatCode(() -> {
+ executor.cleanUp();
+ }).doesNotThrowAnyException();
+
+ assertThatThrownBy(() -> {
+ executor.cleanUp();
+ }).hasMessage("cleanup failed, executor executor:0.0.1 is not initialized");
+
+ assertThatThrownBy(() -> {
+ executor.execute("hello");
+ }).hasMessage("execution failed, executor executor:0.0.1 is not initialized");
+ }
+
+ @Test
+ public void testJavescriptExecutorConcurrencyLatchTimeout() throws StateMachineException, IOException {
+ JavascriptExecutor.setTimeunit4Latches(TimeUnit.MICROSECONDS);
+ JavascriptExecutor.setIntializationLatchTimeout(1);
+ JavascriptExecutor.setCleanupLatchTimeout(10000000);
+
+ JavascriptExecutor executor = new JavascriptExecutor(new AxArtifactKey("executor:0.0.1"));
+
+ assertThatThrownBy(() -> {
+ executor.init("var x = 1;");
+ }).hasMessage("JavascriptExecutor executor:0.0.1 initiation timed out after 1 MICROSECONDS");
+
+ assertThatCode(() -> {
+ executor.cleanUp();
+ }).doesNotThrowAnyException();
+
+ JavascriptExecutor.setTimeunit4Latches(TimeUnit.SECONDS);
+ JavascriptExecutor.setIntializationLatchTimeout(60);
+
+ assertThatCode(() -> {
+ executor.init("var x = 1;");
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ executor.cleanUp();
+ }).doesNotThrowAnyException();
+
+ JavascriptExecutor.setTimeunit4Latches(TimeUnit.MICROSECONDS);
+ JavascriptExecutor.setIntializationLatchTimeout(60000000);
+ JavascriptExecutor.setCleanupLatchTimeout(1);
+
+ assertThatCode(() -> {
+ executor.init("var x = 1;");
+ }).doesNotThrowAnyException();
+
+ assertThatThrownBy(() -> {
+ executor.cleanUp();
+ }).hasMessage("JavascriptExecutor executor:0.0.1 cleanup timed out after 1 MICROSECONDS");
+
+ JavascriptExecutor.setCleanupLatchTimeout(10000000);
+ assertThatThrownBy(() -> {
+ executor.cleanUp();
+ }).hasMessage("cleanup failed, executor executor:0.0.1 is not initialized");
+
+ assertThatCode(() -> {
+ executor.init("var x = 1;");
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ executor.cleanUp();
+ }).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testJavescriptExecutorBadStates() throws StateMachineException, IOException {
+ JavascriptExecutor executor = new JavascriptExecutor(new AxArtifactKey("executor:0.0.1"));
+
+ assertThatThrownBy(() -> {
+ executor.execute("hello");
+ }).hasMessage("execution failed, executor executor:0.0.1 is not initialized");
+
+ assertThatThrownBy(() -> {
+ executor.cleanUp();
+ }).hasMessage("cleanup failed, executor executor:0.0.1 is not initialized");
+
+ assertThatCode(() -> {
+ executor.init("var x = 1;");
+ }).doesNotThrowAnyException();
+
+ executor.getExecutorThread().interrupt();
+ await().atMost(10, TimeUnit.SECONDS).until(() -> !executor.getExecutorThread().isAlive());
+
+ assertThatThrownBy(() -> {
+ executor.execute("hello");
+ }).hasMessage("execution failed, executor executor:0.0.1 is not running, "
+ + "run cleanUp to clear executor and init to restart executor");
+
+ assertThatThrownBy(() -> {
+ executor.execute("hello");
+ }).hasMessage("execution failed, executor executor:0.0.1 is not running, "
+ + "run cleanUp to clear executor and init to restart executor");
+
+ assertThatCode(() -> {
+ executor.cleanUp();
+ }).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testJavescriptExecutorExecution() throws StateMachineException, IOException {
+ JavascriptExecutor executor = new JavascriptExecutor(new AxArtifactKey("executor:0.0.1"));
+
+ assertThatCode(() -> {
+ executor.init("true;");
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ assertTrue(executor.execute("hello"));
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ executor.cleanUp();
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ executor.init("false;");
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ assertFalse(executor.execute("hello"));
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ executor.cleanUp();
+ }).doesNotThrowAnyException();
+
+ assertThatThrownBy(() -> {
+ executor.init("aaaaa = \"sss");
+ }).hasMessage(
+ "logic failed to compile for executor:0.0.1 with message: unterminated string literal (executor:0.0.1#1)");
+
+ assertThatCode(() -> {
+ executor.cleanUp();
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ executor.init("true;");
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ assertTrue(executor.execute("hello"));
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ executor.cleanUp();
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ executor.init("throw \"this is an error\";");
+ }).doesNotThrowAnyException();
+
+ assertThatThrownBy(() -> {
+ assertTrue(executor.execute("hello"));
+ }).hasMessage("logic failed to run for executor:0.0.1 with message: this is an error (executor:0.0.1#1)");
+
+ assertThatCode(() -> {
+ executor.cleanUp();
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ executor.init("while (true) { x = 1; }; true;");
+ }).doesNotThrowAnyException();
+
+ concurrentResult.set(true);
+
+ // Execute an infinite loop in Javascript
+ (new Thread() {
+ public void run() {
+ try {
+ concurrentResult.set(executor.execute("hello"));
+ } catch (StateMachineException e) {
+ e.printStackTrace();
+ }
+ }
+ }).start();
+
+ executor.getExecutorThread().interrupt();
+
+ await().atMost(1000, TimeUnit.MILLISECONDS).until(() -> !concurrentResult.get());
+
+ assertThatCode(() -> {
+ executor.cleanUp();
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ executor.init("true;");
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ assertTrue(executor.execute("hello"));
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ executor.cleanUp();
+ }).doesNotThrowAnyException();
+
+ assertThatCode(() -> {
+ executor.init("x = 1; true;");
+ }).doesNotThrowAnyException();
+
+ concurrentResult.set(true);
+
+ // Execute an infinite loop in Javascript
+ Thread executionThread = new Thread() {
+ public void run() {
+ try {
+ while (executor.execute("hello")) {
+ ;
+ }
+ } catch (StateMachineException e) {
+ ;
+ }
+ }
+ };
+ executionThread.start();
+
+ executionThread.interrupt();
+
+ await().atMost(300, TimeUnit.MILLISECONDS).until(() -> !executionThread.isAlive());
+ await().atMost(300, TimeUnit.MILLISECONDS).until(() -> !executor.getExecutorThread().isAlive());
+
+ assertThatCode(() -> {
+ executor.cleanUp();
+ }).doesNotThrowAnyException();
+ }
+}
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java
index 6247179..243a1d9 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java
@@ -31,7 +31,6 @@
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.DistributorParameters;
@@ -77,7 +76,6 @@
ParameterService.deregister(EngineParameterConstants.MAIN_GROUP_NAME);
}
- @Ignore
@Test
public void testJavaStateFinalizerExecutor() throws Exception {
JavascriptStateFinalizerExecutor jsfe = new JavascriptStateFinalizerExecutor();
@@ -104,15 +102,17 @@
Map<String, Object> incomingParameters1 = new HashMap<>();
assertThatThrownBy(() -> {
jsfe.execute(-1, new Properties(), incomingParameters1);
- }).hasMessage("execution failed, executor NULL:0.0.0:NULL:NULL is not running");
+ }).hasMessage("execution failed, executor NULL:0.0.0:NULL:NULL is not running, "
+ + "run cleanUp to clear executor and init to restart executor");
assertThatThrownBy(() -> {
jsfe.prepare();
- }).hasMessage("initiation failed, executor NULL:0.0.0:NULL:NULL failed to start");
+ }).hasMessage(
+ "initiation failed, executor NULL:0.0.0:NULL:NULL already initialized, run cleanUp to clear executor");
- assertThatThrownBy(() -> {
+ assertThatCode(() -> {
jsfe.cleanUp();
- }).hasMessage("cleanup failed, executor NULL:0.0.0:NULL:NULL is not running");
+ }).doesNotThrowAnyException();
JavascriptStateFinalizerExecutor jsfe1 = new JavascriptStateFinalizerExecutor();
stateFinalizerLogic.setLogic("java.lang.String");
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java
index fe71d3c..4fc7507 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java
@@ -32,7 +32,6 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.onap.policy.apex.context.ContextAlbum;
import org.onap.policy.apex.context.ContextException;
@@ -98,7 +97,6 @@
ParameterService.clear();
}
- @Ignore
@Test
public void testJavascriptTaskExecutor() throws Exception {
assertThatThrownBy(() -> {
@@ -129,7 +127,7 @@
assertThatThrownBy(() -> {
jte.prepare();
- }).hasMessage("initiation failed, executor TestTask:0.0.1 is already running");
+ }).hasMessage("initiation failed, executor TestTask:0.0.1 already initialized, run cleanUp to clear executor");
assertThatThrownBy(() -> {
jte.execute(-1, new Properties(), null);
@@ -166,7 +164,6 @@
}).doesNotThrowAnyException();
}
- @Ignore
@Test
public void testJavascriptTaskExecutorLogic() throws Exception {
JavascriptTaskExecutor jte = new JavascriptTaskExecutor();
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java
index de5df57..fa494ce 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java
@@ -30,7 +30,6 @@
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.DistributorParameters;
@@ -69,7 +68,6 @@
ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
}
- @Ignore
@Test
public void testJavascriptTaskSelectExecutor() throws Exception {
JavascriptTaskSelectExecutor jtse = new JavascriptTaskSelectExecutor();
@@ -86,14 +84,18 @@
assertThatThrownBy(() -> {
jtse.prepare();
- }).hasMessage("no logic specified for NULL:0.0.0:NULL:NULL");
+ }).hasMessage("initiation failed, no logic specified for executor NULL:0.0.0:NULL:NULL");
AxEvent axEvent1 = new AxEvent(new AxArtifactKey("Event", "0.0.1"));
EnEvent event1 = new EnEvent(axEvent1);
assertThatThrownBy(() -> {
jtse.execute(-1, new Properties(), event1);
- }).hasMessage("execution failed, executor NULL:0.0.0:NULL:NULL is not running");
+ }).hasMessage("execution failed, executor NULL:0.0.0:NULL:NULL is not initialized");
+
+ assertThatThrownBy(() -> {
+ jtse.cleanUp();
+ }).hasMessage("cleanup failed, executor NULL:0.0.0:NULL:NULL is not initialized");
state.getTaskSelectionLogic().setLogic("java.lang.String");
jtse.prepare();
@@ -119,7 +121,8 @@
assertThatThrownBy(() -> {
jtse.prepare();
- }).hasMessage("initiation failed, executor NULL:0.0.0:NULL:NULL is already running");
+ }).hasMessage(
+ "initiation failed, executor NULL:0.0.0:NULL:NULL already initialized, run cleanUp to clear executor");
assertThatCode(() -> {
jtse.cleanUp();