diff options
author | liamfallon <liam.fallon@est.tech> | 2020-04-01 09:38:33 +0100 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2020-04-02 16:33:47 +0100 |
commit | 30f94aa98ebc8931e224cdd2e5b8c25949379065 (patch) | |
tree | fe1391f867cd11726da9dfcf6b6089dd74f4c3ef /plugins | |
parent | 42cd61abcc9cd27e72eaa34a746ee176dbf30750 (diff) |
Fix hanging timeout on Executor test
Issue-ID: POLICY-2106
Change-Id: I7bd44f8dfe349d73a4c8c4f978a30b455c45b2c7
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'plugins')
12 files changed, 54 insertions, 52 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java index 55baf3cf7..326be511c 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java @@ -25,14 +25,16 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import com.google.gson.Gson; + import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.IOException; import java.io.PrintStream; import java.util.Map; + import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.core.Response; + import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -66,8 +68,8 @@ public class RestRequestorTest { */ @BeforeClass public static void setUp() throws Exception { - server = HttpServletServerFactoryInstance.getServerFactory().build( - null, false, null, PORT, "/TestRESTRequestor", false, false); + server = HttpServletServerFactoryInstance.getServerFactory().build(null, false, null, PORT, + "/TestRESTRequestor", false, false); server.addServletClass(null, SupportRestRequestorEndpoint.class.getName()); server.setSerializationProvider(GsonMessageBodyHandler.class.getName()); @@ -89,10 +91,6 @@ public class RestRequestorTest { if (server != null) { server.stop(); } - - new File("src/test/resources/events/EventsOut.json").delete(); - new File("src/test/resources/events/EventsOutMulti0.json").delete(); - new File("src/test/resources/events/EventsOutMulti1.json").delete(); } /** @@ -114,8 +112,7 @@ public class RestRequestorTest { public void testRestRequestorGet() throws MessagingException, ApexException, IOException { final Client client = ClientBuilder.newClient(); - final String[] args = - { "src/test/resources/prodcons/File2RESTRequest2FileGet.json" }; + final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGet.json"}; final ApexMain apexMain = new ApexMain(args); Response response = null; @@ -126,7 +123,7 @@ public class RestRequestorTest { ThreadUtilities.sleep(100); response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") - .request("application/json").get(); + .request("application/json").get(); if (Response.Status.OK.getStatusCode() != response.getStatus()) { break; @@ -162,8 +159,7 @@ public class RestRequestorTest { public void testRestRequestorGetEmpty() throws MessagingException, ApexException, IOException { final Client client = ClientBuilder.newClient(); - final String[] args = - { "src/test/resources/prodcons/File2RESTRequest2FileGetEmpty.json" }; + final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGetEmpty.json"}; final ApexMain apexMain = new ApexMain(args); Response response = null; @@ -174,7 +170,7 @@ public class RestRequestorTest { ThreadUtilities.sleep(100); response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") - .request("application/json").get(); + .request("application/json").get(); if (Response.Status.OK.getStatusCode() != response.getStatus()) { break; @@ -208,8 +204,7 @@ public class RestRequestorTest { public void testRestRequestorPut() throws MessagingException, ApexException, IOException { final Client client = ClientBuilder.newClient(); - final String[] args = - { "src/test/resources/prodcons/File2RESTRequest2FilePut.json" }; + final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FilePut.json"}; final ApexMain apexMain = new ApexMain(args); // Wait for the required amount of events to be received or for 10 seconds @@ -220,7 +215,7 @@ public class RestRequestorTest { ThreadUtilities.sleep(100); response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") - .request("application/json").get(); + .request("application/json").get(); if (Response.Status.OK.getStatusCode() != response.getStatus()) { break; @@ -255,8 +250,7 @@ public class RestRequestorTest { public void testRestRequestorPost() throws MessagingException, ApexException, IOException { final Client client = ClientBuilder.newClient(); - final String[] args = - { "src/test/resources/prodcons/File2RESTRequest2FilePost.json" }; + final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FilePost.json"}; final ApexMain apexMain = new ApexMain(args); // Wait for the required amount of events to be received or for 10 seconds @@ -265,7 +259,7 @@ public class RestRequestorTest { ThreadUtilities.sleep(100); final Response response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") - .request("application/json").get(); + .request("application/json").get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); final String responseString = response.readEntity(String.class); @@ -296,8 +290,7 @@ public class RestRequestorTest { public void testRestRequestorDelete() throws MessagingException, ApexException, IOException { final Client client = ClientBuilder.newClient(); - final String[] args = - { "src/test/resources/prodcons/File2RESTRequest2FileDelete.json" }; + final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileDelete.json"}; final ApexMain apexMain = new ApexMain(args); // Wait for the required amount of events to be received or for 10 seconds @@ -306,7 +299,7 @@ public class RestRequestorTest { ThreadUtilities.sleep(100); final Response response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") - .request("application/json").get(); + .request("application/json").get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); final String responseString = response.readEntity(String.class); @@ -337,8 +330,7 @@ public class RestRequestorTest { public void testRestRequestorMultiInputs() throws MessagingException, ApexException, IOException { final Client client = ClientBuilder.newClient(); - final String[] args = - { "src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json" }; + final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json"}; final ApexMain apexMain = new ApexMain(args); // Wait for the required amount of events to be received or for 10 seconds @@ -347,7 +339,7 @@ public class RestRequestorTest { ThreadUtilities.sleep(100); final Response response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") - .request("application/json").get(); + .request("application/json").get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); final String responseString = response.readEntity(String.class); @@ -379,8 +371,7 @@ public class RestRequestorTest { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = - { "src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json" }; + final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json"}; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(200); @@ -392,7 +383,7 @@ public class RestRequestorTest { System.setErr(stderr); assertTrue(outString.contains("REST Requestor producer (RestRequestorProducer) " - + "must run in peered requestor mode with a REST Requestor consumer")); + + "must run in peered requestor mode with a REST Requestor consumer")); } /** @@ -407,8 +398,7 @@ public class RestRequestorTest { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = - { "src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json" }; + final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json"}; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(200); @@ -420,6 +410,6 @@ public class RestRequestorTest { System.setErr(stderr); assertTrue(outString.contains("peer \"RestRequestorProducer for peered mode REQUESTOR " - + "does not exist or is not defined with the same peered mode")); + + "does not exist or is not defined with the same peered mode")); } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileDelete.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileDelete.json index 3a27a48ee..d6234cafc 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileDelete.json +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileDelete.json @@ -62,7 +62,7 @@ "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { - "fileName": "src/test/resources/events/EventsOut.json" + "fileName": "target/EventsOut.json" } }, "eventProtocolParameters": { diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGet.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGet.json index aaf14e5af..4b36b5046 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGet.json +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGet.json @@ -62,7 +62,7 @@ "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { - "fileName": "src/test/resources/events/EventsOut.json" + "fileName": "target/EventsOut.json" } }, "eventProtocolParameters": { diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json index 145d3838f..9374d9b85 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json @@ -58,7 +58,7 @@ "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { - "fileName": "src/test/resources/events/EventsOut.json" + "fileName": "target/EventsOut.json" } }, "eventProtocolParameters": { diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetEmpty.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetEmpty.json index ebf9d0581..21e25f0f3 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetEmpty.json +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetEmpty.json @@ -62,7 +62,7 @@ "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { - "fileName": "src/test/resources/events/EventsOut.json" + "fileName": "target/EventsOut.json" } }, "eventProtocolParameters": { diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json index 5b4344be8..d476a2268 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json @@ -90,7 +90,7 @@ "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { - "fileName": "src/test/resources/events/EventsOutMulti0.json" + "fileName": "target/EventsOutMulti0.json" } }, "eventProtocolParameters": { @@ -115,7 +115,7 @@ "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { - "fileName": "src/test/resources/events/EventsOutMulti1.json" + "fileName": "target/EventsOutMulti1.json" } }, "eventProtocolParameters": { diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json index b50b8bd20..f4614d5cd 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json @@ -42,7 +42,7 @@ "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { - "fileName": "src/test/resources/events/EventsOut.json" + "fileName": "target/EventsOut.json" } }, "eventProtocolParameters": { diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePost.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePost.json index abe50d7e7..2edc2c667 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePost.json +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePost.json @@ -62,7 +62,7 @@ "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { - "fileName": "src/test/resources/events/EventsOut.json" + "fileName": "target/EventsOut.json" } }, "eventProtocolParameters": { diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePut.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePut.json index fa4e4e3dc..0b53dc686 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePut.json +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePut.json @@ -66,7 +66,7 @@ "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { - "fileName": "src/test/resources/events/EventsOut.json" + "fileName": "target/EventsOut.json" } }, "eventProtocolParameters": { diff --git a/plugins/plugins-executor/plugins-executor-javascript/pom.xml b/plugins/plugins-executor/plugins-executor-javascript/pom.xml index 007a03ae2..80fe06c79 100644 --- a/plugins/plugins-executor/plugins-executor-javascript/pom.xml +++ b/plugins/plugins-executor/plugins-executor-javascript/pom.xml @@ -59,7 +59,6 @@ <artifactId>awaitility</artifactId> <scope>test</scope> </dependency> - </dependencies> <profiles> 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 a33a129af..489489ff0 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 @@ -50,8 +50,12 @@ public class JavascriptExecutor implements Runnable { public static final int DEFAULT_OPTIMIZATION_LEVEL = 9; + // Token passed to executor thread to stop execution + private static final Object STOP_EXECUTION_TOKEN = "*** STOP EXECUTION ***"; + // Recurring string constants private static final String WITH_MESSAGE = " with message: "; + private static final String JAVASCRIPT_EXECUTOR = "JavascriptExecutor "; @Setter(AccessLevel.PROTECTED) private static TimeUnit timeunit4Latches = TimeUnit.SECONDS; @@ -120,7 +124,7 @@ public class JavascriptExecutor implements Runnable { try { if (!intializationLatch.await(intializationLatchTimeout, timeunit4Latches)) { executorThread.interrupt(); - throw new StateMachineException("JavascriptExecutor " + subjectKey.getId() + throw new StateMachineException(JAVASCRIPT_EXECUTOR + subjectKey.getId() + " initiation timed out after " + intializationLatchTimeout + " " + timeunit4Latches); } } catch (InterruptedException e) { @@ -160,7 +164,7 @@ public class JavascriptExecutor implements Runnable { executorThread.interrupt(); Thread.currentThread().interrupt(); throw new StateMachineException( - "JavascriptExecutor " + subjectKey.getId() + "interrupted on execution result wait", e); + JAVASCRIPT_EXECUTOR + subjectKey.getId() + "interrupted on execution result wait", e); } checkAndThrowExecutorException(); @@ -179,11 +183,11 @@ public class JavascriptExecutor implements Runnable { } if (executorThread.isAlive()) { - executorThread.interrupt(); + executionQueue.add(STOP_EXECUTION_TOKEN); try { if (!cleanupLatch.await(cleanupLatchTimeout, timeunit4Latches)) { - executorException.set(new StateMachineException("JavascriptExecutor " + subjectKey.getId() + executorException.set(new StateMachineException(JAVASCRIPT_EXECUTOR + subjectKey.getId() + " cleanup timed out after " + cleanupLatchTimeout + " " + timeunit4Latches)); } } catch (InterruptedException e) { @@ -221,12 +225,14 @@ public class JavascriptExecutor implements Runnable { while (!Thread.currentThread().isInterrupted()) { try { Object contextObject = executionQueue.take(); - - boolean result = executeScript(contextObject); - resultQueue.add(result); + if (STOP_EXECUTION_TOKEN.equals(contextObject)) { + LOGGER.debug("execution close was ordered for " + subjectKey.getId()); + break; + } + resultQueue.add(executeScript(contextObject)); } catch (final InterruptedException e) { LOGGER.debug("execution was interruped for " + subjectKey.getId() + WITH_MESSAGE + e.getMessage(), e); - resultQueue.add(false); + executionQueue.add(STOP_EXECUTION_TOKEN); Thread.currentThread().interrupt(); } catch (StateMachineException sme) { executorException.set(sme); @@ -234,6 +240,8 @@ public class JavascriptExecutor implements Runnable { } } + resultQueue.add(false); + try { Context.exit(); } catch (final Exception e) { 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 index 53781e870..6ea15fc35 100644 --- 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 @@ -267,7 +267,7 @@ public class JavascriptExecutorTest { }).doesNotThrowAnyException(); assertThatCode(() -> { - executor.init("while (true) { x = 1; }; true;"); + executor.init("var x = 0; while (x < 100) { x++; }; true;"); }).doesNotThrowAnyException(); concurrentResult.set(true); @@ -276,13 +276,18 @@ public class JavascriptExecutorTest { (new Thread() { public void run() { try { - concurrentResult.set(executor.execute("hello")); + while (executor.execute("hello")) { + // Loop until interrupted + } + concurrentResult.set(false); } catch (StateMachineException e) { - e.printStackTrace(); + // Do nothing } } }).start(); + await().atMost(1000, TimeUnit.MILLISECONDS).until(() -> executor.getExecutorThread().isAlive()); + executor.getExecutorThread().interrupt(); await().atMost(1000, TimeUnit.MILLISECONDS).until(() -> !concurrentResult.get()); |