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 | |
parent | 42cd61abcc9cd27e72eaa34a746ee176dbf30750 (diff) |
Fix hanging timeout on Executor test
Issue-ID: POLICY-2106
Change-Id: I7bd44f8dfe349d73a4c8c4f978a30b455c45b2c7
Signed-off-by: liamfallon <liam.fallon@est.tech>
24 files changed, 190 insertions, 143 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()); diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java index 8708e97e6..2c1c900c8 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.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. @@ -92,7 +92,7 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable { * @param consumerParameters the consumer parameters for this specific unmarshaler */ public ApexEventUnmarshaller(final String name, final EngineServiceParameters engineServiceParameters, - final EventHandlerParameters consumerParameters) { + final EventHandlerParameters consumerParameters) { this.name = name; this.engineServiceParameters = engineServiceParameters; this.consumerParameters = consumerParameters; @@ -123,7 +123,7 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable { // Configure and start the event reception thread final String threadName = - engineServiceParameters.getEngineKey().getName() + ":" + this.getClass().getName() + ":" + name; + engineServiceParameters.getEngineKey().getName() + ":" + this.getClass().getName() + ":" + name; unmarshallerThread = new ApplicationThreadFactory(threadName).newThread(this); unmarshallerThread.setDaemon(true); unmarshallerThread.start(); @@ -168,7 +168,7 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable { // To connect a synchronous unmarshaler and marshaler, we create a synchronous event // cache on the consumer/producer pair new SynchronousEventCache(peeredMode, consumer, peeredMarshaller.getProducer(), - consumerParameters.getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS)); + consumerParameters.getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS)); return; case REQUESTOR: @@ -185,7 +185,7 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable { */ @Override public void receiveEvent(@NonNull final Properties executionProperties, final Object event) - throws ApexEventException { + throws ApexEventException { receiveEvent(0, executionProperties, event, true); } @@ -194,7 +194,7 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable { */ @Override public void receiveEvent(final long executionId, @NonNull final Properties executionProperties, final Object event) - throws ApexEventException { + throws ApexEventException { receiveEvent(executionId, executionProperties, event, false); } @@ -208,7 +208,7 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable { * @throws ApexEventException on unmarshaling errors on events */ private void receiveEvent(final long executionId, final Properties executionProperties, final Object event, - final boolean generateExecutionId) throws ApexEventException { + final boolean generateExecutionId) throws ApexEventException { // Push the event onto the queue if (LOGGER.isTraceEnabled()) { String eventString = "onMessage(): event received: " + event.toString(); @@ -234,19 +234,19 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable { apexEvent.setExecutionProperties(executionProperties); - // Enqueue the event - queue.add(apexEvent); - // Cache synchronized events that are sent if (consumerParameters.isPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS)) { final SynchronousEventCache synchronousEventCache = - (SynchronousEventCache) consumer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS); + (SynchronousEventCache) consumer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS); synchronousEventCache.cacheSynchronizedEventToApex(apexEvent.getExecutionId(), apexEvent); } + + // Enqueue the event + queue.add(apexEvent); } } catch (final ApexException e) { final String errorMessage = "Error while converting event into an ApexEvent for " + name + ": " - + e.getMessage() + ", Event=" + event; + + e.getMessage() + ", Event=" + event; LOGGER.warn(errorMessage, e); throw new ApexEventException(errorMessage, e); } @@ -261,11 +261,11 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable { // Check if we are filtering events on this unmarshaler, if so check the event name // against the filter if (consumerParameters.isSetEventNameFilter() - && !apexEvent.getName().matches(consumerParameters.getEventNameFilter())) { + && !apexEvent.getName().matches(consumerParameters.getEventNameFilter())) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("onMessage(): event {} not processed, filtered out by filter", apexEvent, - consumerParameters.getEventNameFilter()); + consumerParameters.getEventNameFilter()); } return true; @@ -330,7 +330,7 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable { // Order a stop on the synchronous cache if one exists if (consumerParameters != null && consumerParameters.isPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS) - && consumer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS) != null) { + && consumer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS) != null) { ((SynchronousEventCache) consumer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)).stop(); } diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJRuby.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJRuby.java index f344add45..8544e35dc 100644 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJRuby.java +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJRuby.java @@ -21,6 +21,8 @@ package org.onap.policy.apex.testsuites.integration.executor.engine; +import static org.assertj.core.api.Assertions.assertThatCode; + import java.io.IOException; import org.junit.After; @@ -96,7 +98,8 @@ public class TestApexEngineJRuby { */ @Test public void testApexEngineJRuby() throws ApexException, InterruptedException, IOException { - new TestApexEngine("JRUBY", engineParameters); - new TestApexEngine("JRUBY", engineParameters); + assertThatCode(() -> { + new TestApexEngine("JRUBY", engineParameters); + }).doesNotThrowAnyException(); } } 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 b9d3bb39b..1bbbbb78d 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,9 +51,7 @@ 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); + testFileEvents(apexArgs, "target/EventsOut.json", 48656); } /** @@ -67,7 +65,7 @@ public class TestFile2FileIgnore { * @throws IOException Signals that an I/O exception has occurred. */ private static void testFileEvents(final String[] args, final String outFilePath, final long expectedFileSize) - throws MessagingException, ApexException, IOException { + throws MessagingException, ApexException, IOException { final ApexMain apexMain = new ApexMain(args); final File outFile = new File(outFilePath); @@ -104,6 +102,6 @@ public class TestFile2FileIgnore { */ private static String stripVariableLengthText(final String outFile) throws IOException { return TextFileUtils.getTextFileAsString(outFile).replaceAll("\\s+", "").replaceAll(":\\d*\\.?\\d*,", ":0,") - .replaceAll(":\\d*}", ":0}").replaceAll("<value>\\d*\\.?\\d*</value>", "<value>0</value>"); + .replaceAll(":\\d*}", ":0}").replaceAll("<value>\\d*\\.?\\d*</value>", "<value>0</value>"); } } diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java index 3243cd772..39a5244db 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java @@ -24,12 +24,10 @@ package org.onap.policy.apex.testsuites.integration.uservice.adapt.restclient; import static org.junit.Assert.fail; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.IOException; import java.io.PrintStream; import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; @@ -75,7 +73,7 @@ public class TestRest2File { @Before public void setUp() throws Exception { server = HttpServletServerFactoryInstance.getServerFactory().build("TestRest2File", false, null, PORT, - "/TestRest2File", false, false); + "/TestRest2File", false, false); server.addServletClass(null, TestRestClientEndpoint.class.getName()); server.setSerializationProvider(GsonMessageBodyHandler.class.getName()); @@ -100,14 +98,6 @@ public class TestRest2File { } /** - * Delete temp files. - */ - @AfterClass - public static void deleteTempFiles() { - new File("src/test/resources/events/EventsOut.json").delete(); - } - - /** * Test rest events in. * * @throws MessagingException the messaging exception @@ -124,10 +114,10 @@ public class TestRest2File { apexMain.shutdown(); final String outputEventText = - TextFileUtils.getTextFileAsString("target/examples/events/SampleDomain/EventsOut.json"); + TextFileUtils.getTextFileAsString("target/examples/events/SampleDomain/EventsOut.json"); checkRequiredString(outputEventText, - "04\",\n" + " \"version\": \"0.0.1\",\n" + " \"nameSpace\": \"org.onap.policy.apex.sample.events\""); + "04\",\n" + " \"version\": \"0.0.1\",\n" + " \"nameSpace\": \"org.onap.policy.apex.sample.events\""); } /** @@ -153,8 +143,8 @@ public class TestRest2File { System.setOut(stdout); System.setErr(stderr); - checkRequiredString(outString, "received an empty event from URL " - + "\"http://localhost:32801/TestRest2File/apex/event/GetEmptyEvent\""); + checkRequiredString(outString, + "received an empty event from URL " + "\"http://localhost:32801/TestRest2File/apex/event/GetEmptyEvent\""); } /** @@ -207,7 +197,7 @@ public class TestRest2File { System.setErr(stderr); checkRequiredString(outString, "reception of event from URL " - + "\"http://localhost:32801/TestRest2File/apex/event/Bad\" failed with status code 404"); + + "\"http://localhost:32801/TestRest2File/apex/event/Bad\" failed with status code 404"); } /** @@ -234,7 +224,7 @@ public class TestRest2File { System.setErr(stderr); checkRequiredString(outString, "specified HTTP method of \"POST\" is invalid, " - + "only HTTP method \"GET\" is supported for event reception on REST client consumer"); + + "only HTTP method \"GET\" is supported for event reception on REST client consumer"); } /** @@ -261,9 +251,8 @@ public class TestRest2File { System.setErr(stderr); checkRequiredString(outString, - "reception of event from URL " - + "\"http://localhost:32801/TestRest2File/apex/event/GetEventBadResponse\" " - + "failed with status code 400 and message \""); + "reception of event from URL " + "\"http://localhost:32801/TestRest2File/apex/event/GetEventBadResponse\" " + + "failed with status code 400 and message \""); } /** diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java index 98eebf50e..4f6ef290a 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.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. @@ -21,19 +21,24 @@ package org.onap.policy.apex.testsuites.integration.uservice.adapt.restserver; +import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import com.google.gson.Gson; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.Map; import java.util.Random; +import java.util.concurrent.TimeUnit; + import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Entity; import javax.ws.rs.core.Response; + import org.junit.Before; import org.junit.Test; import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; @@ -79,8 +84,7 @@ public class TestRestServer { public void testRestServerPut() throws MessagingException, ApexException, IOException, InterruptedException { LOGGER.debug("testRestServerPut start"); - final String[] args = - { "-rfr", "target", "-c", "target/examples/config/SampleDomain/RESTServerJsonEvent.json" }; + final String[] args = {"-rfr", "target", "-c", "target/examples/config/SampleDomain/RESTServerJsonEvent.json"}; final ApexMain apexMain = new ApexMain(args); if (!NetworkUtil.isTcpPortOpen("localhost", 23324, 60, 500L)) { throw new IllegalStateException("cannot connect to Apex Rest Server"); @@ -92,7 +96,7 @@ public class TestRestServer { for (int i = 0; i < 20; i++) { response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json") - .put(Entity.json(getEvent())); + .put(Entity.json(getEvent())); if (Response.Status.OK.getStatusCode() != response.getStatus()) { break; @@ -105,6 +109,8 @@ public class TestRestServer { apexMain.shutdown(); + await().atMost(10L, TimeUnit.SECONDS).until(() -> !apexMain.isAlive()); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace")); assertEquals("Test slogan for External Event0", jsonMap.get("TestSlogan")); @@ -123,8 +129,7 @@ public class TestRestServer { @Test public void testRestServerPost() throws MessagingException, ApexException, IOException, InterruptedException { LOGGER.debug("testRestServerPost start"); - final String[] args = - { "-rfr", "target", "-c", "target/examples/config/SampleDomain/RESTServerJsonEvent.json" }; + final String[] args = {"-rfr", "target", "-c", "target/examples/config/SampleDomain/RESTServerJsonEvent.json"}; final ApexMain apexMain = new ApexMain(args); if (!NetworkUtil.isTcpPortOpen("localhost", 23324, 60, 500L)) { throw new IllegalStateException("cannot connect to Apex Rest Server"); @@ -136,7 +141,7 @@ public class TestRestServer { for (int i = 0; i < 20; i++) { response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json") - .post(Entity.json(getEvent())); + .post(Entity.json(getEvent())); if (Response.Status.OK.getStatusCode() != response.getStatus()) { break; @@ -149,6 +154,8 @@ public class TestRestServer { apexMain.shutdown(); + await().atMost(10L, TimeUnit.SECONDS).until(() -> !apexMain.isAlive()); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace")); assertEquals("Test slogan for External Event0", jsonMap.get("TestSlogan")); @@ -166,8 +173,7 @@ public class TestRestServer { @Test public void testRestServerGetStatus() throws MessagingException, ApexException, IOException, InterruptedException { LOGGER.debug("testRestServerGetStatus start"); - final String[] args = - { "-rfr", "target", "-c", "target/examples/config/SampleDomain/RESTServerJsonEvent.json" }; + final String[] args = {"-rfr", "target", "-c", "target/examples/config/SampleDomain/RESTServerJsonEvent.json"}; final ApexMain apexMain = new ApexMain(args); if (!NetworkUtil.isTcpPortOpen("localhost", 23324, 60, 500L)) { throw new IllegalStateException("cannot connect to Apex Rest Server"); @@ -180,25 +186,27 @@ public class TestRestServer { // trigger 10 POST & PUT events for (int i = 0; i < 10; i++) { postResponse = client.target("http://localhost:23324/apex/FirstConsumer/EventIn") - .request("application/json").post(Entity.json(getEvent())); + .request("application/json").post(Entity.json(getEvent())); if (Response.Status.OK.getStatusCode() != postResponse.getStatus()) { break; } putResponse = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json") - .put(Entity.json(getEvent())); + .put(Entity.json(getEvent())); if (Response.Status.OK.getStatusCode() != putResponse.getStatus()) { break; } } - final Response statResponse = client.target("http://localhost:23324/apex/FirstConsumer/Status") - .request("application/json").get(); + final Response statResponse = + client.target("http://localhost:23324/apex/FirstConsumer/Status").request("application/json").get(); final String responseString = statResponse.readEntity(String.class); apexMain.shutdown(); + await().atMost(10L, TimeUnit.SECONDS).until(() -> !apexMain.isAlive()); + assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus()); assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus()); assertEquals(Response.Status.OK.getStatusCode(), statResponse.getStatus()); @@ -226,7 +234,7 @@ public class TestRestServer { throws MessagingException, ApexException, IOException, InterruptedException { LOGGER.debug("testRestServerMultiInputs start"); final String[] args = - { "-rfr", "target", "-c", "target/examples/config/SampleDomain/RESTServerJsonEventMultiIn.json" }; + {"-rfr", "target", "-c", "target/examples/config/SampleDomain/RESTServerJsonEventMultiIn.json"}; final ApexMain apexMain = new ApexMain(args); if (!NetworkUtil.isTcpPortOpen("localhost", 23324, 60, 500L)) { throw new IllegalStateException("cannot connect to Apex Rest Server"); @@ -241,7 +249,7 @@ public class TestRestServer { for (int i = 0; i < 20; i++) { firstResponse = client.target("http://localhost:23324/apex/FirstConsumer/EventIn") - .request("application/json").post(Entity.json(getEvent())); + .request("application/json").post(Entity.json(getEvent())); if (Response.Status.OK.getStatusCode() != firstResponse.getStatus()) { break; @@ -252,7 +260,7 @@ public class TestRestServer { firstJsonMap = new Gson().fromJson(firstResponseString, Map.class); secondResponse = client.target("http://localhost:23325/apex/SecondConsumer/EventIn") - .request("application/json").post(Entity.json(getEvent())); + .request("application/json").post(Entity.json(getEvent())); if (Response.Status.OK.getStatusCode() != secondResponse.getStatus()) { break; @@ -265,6 +273,8 @@ public class TestRestServer { apexMain.shutdown(); + await().atMost(10L, TimeUnit.SECONDS).until(() -> !apexMain.isAlive()); + assertEquals(Response.Status.OK.getStatusCode(), firstResponse.getStatus()); assertEquals("org.onap.policy.apex.sample.events", firstJsonMap.get("nameSpace")); assertEquals("Test slogan for External Event0", firstJsonMap.get("TestSlogan")); @@ -290,20 +300,21 @@ public class TestRestServer { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = - { "src/test/resources/prodcons/RESTServerJsonEventProducerStandalone.json" }; + final String[] args = {"src/test/resources/prodcons/RESTServerJsonEventProducerStandalone.json"}; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(200); apexMain.shutdown(); + await().atMost(10L, TimeUnit.SECONDS).until(() -> !apexMain.isAlive()); + final String outString = outContent.toString(); System.setOut(stdout); System.setErr(stderr); - assertTrue(outString.contains( - "the parameters \"host\", \"port\", and \"standalone\" are illegal on REST Server producer")); + assertTrue(outString + .contains("the parameters \"host\", \"port\", and \"standalone\" are illegal on REST Server producer")); LOGGER.debug("testRestServerProducerStandalone end"); } @@ -322,13 +333,14 @@ public class TestRestServer { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = - { "src/test/resources/prodcons/RESTServerJsonEventProducerHost.json" }; + final String[] args = {"src/test/resources/prodcons/RESTServerJsonEventProducerHost.json"}; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(200); apexMain.shutdown(); + await().atMost(10L, TimeUnit.SECONDS).until(() -> !apexMain.isAlive()); + final String outString = outContent.toString(); System.setOut(stdout); @@ -353,13 +365,14 @@ public class TestRestServer { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = - { "src/test/resources/prodcons/RESTServerJsonEventProducerPort.json" }; + final String[] args = {"src/test/resources/prodcons/RESTServerJsonEventProducerPort.json"}; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(200); apexMain.shutdown(); + await().atMost(10L, TimeUnit.SECONDS).until(() -> !apexMain.isAlive()); + final String outString = outContent.toString(); System.setOut(stdout); @@ -382,20 +395,21 @@ public class TestRestServer { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = - { "src/test/resources/prodcons/RESTServerJsonEventConsumerStandaloneNoHost.json" }; + final String[] args = {"src/test/resources/prodcons/RESTServerJsonEventConsumerStandaloneNoHost.json"}; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(200); apexMain.shutdown(); + await().atMost(10L, TimeUnit.SECONDS).until(() -> !apexMain.isAlive()); + final String outString = outContent.toString(); System.setOut(stdout); System.setErr(stderr); assertTrue(outString.contains("the parameters \"host\" and \"port\" must be defined for REST Server consumer " - + "(FirstConsumer) in standalone mode")); + + "(FirstConsumer) in standalone mode")); LOGGER.debug("testRestServerConsumerStandaloneNoHost end"); } @@ -412,20 +426,21 @@ public class TestRestServer { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = - { "src/test/resources/prodcons/RESTServerJsonEventConsumerStandaloneNoPort.json" }; + final String[] args = {"src/test/resources/prodcons/RESTServerJsonEventConsumerStandaloneNoPort.json"}; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(200); apexMain.shutdown(); + await().atMost(10L, TimeUnit.SECONDS).until(() -> !apexMain.isAlive()); + final String outString = outContent.toString(); System.setOut(stdout); System.setErr(stderr); assertTrue(outString.contains("the parameters \"host\" and \"port\" must be defined for REST Server consumer " - + "(FirstConsumer) in standalone mode")); + + "(FirstConsumer) in standalone mode")); LOGGER.debug("testRestServerConsumerStandaloneNoPort end"); } @@ -442,20 +457,21 @@ public class TestRestServer { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = - { "src/test/resources/prodcons/RESTServerJsonEventProducerNotSync.json" }; + final String[] args = {"src/test/resources/prodcons/RESTServerJsonEventProducerNotSync.json"}; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(200); apexMain.shutdown(); + await().atMost(10L, TimeUnit.SECONDS).until(() -> !apexMain.isAlive()); + final String outString = outContent.toString(); System.setOut(stdout); System.setErr(stderr); - assertTrue(outString.contains("REST Server producer (FirstProducer) must run in synchronous mode " - + "with a REST Server consumer")); + assertTrue(outString.contains( + "REST Server producer (FirstProducer) must run in synchronous mode " + "with a REST Server consumer")); LOGGER.debug("testRestServerProducerNotSync end"); } @@ -472,21 +488,22 @@ public class TestRestServer { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = - { "src/test/resources/prodcons/RESTServerJsonEventConsumerNotSync.json" }; + final String[] args = {"src/test/resources/prodcons/RESTServerJsonEventConsumerNotSync.json"}; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(200); apexMain.shutdown(); + await().atMost(10L, TimeUnit.SECONDS).until(() -> !apexMain.isAlive()); + final String outString = outContent.toString(); System.setOut(stdout); System.setErr(stderr); - assertTrue(outString - .contains("peer \"FirstConsumer for peered mode SYNCHRONOUS does not exist or is not defined " - + "with the same peered mode")); + assertTrue( + outString.contains("peer \"FirstConsumer for peered mode SYNCHRONOUS does not exist or is not defined " + + "with the same peered mode")); LOGGER.debug("testRestServerConsumerNotSync end"); } @@ -501,10 +518,10 @@ public class TestRestServer { final String nextEventName = "Event0" + rand.nextInt(2) + "00"; final String eventString = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.sample.events\",\n" + "\"name\": \"" - + nextEventName + "\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_" + eventsSent++ - + "\",\n" + "\"target\": \"apex\",\n" + "\"TestSlogan\": \"Test slogan for External Event0\",\n" - + "\"TestMatchCase\": " + nextMatchCase + ",\n" + "\"TestTimestamp\": " - + System.currentTimeMillis() + ",\n" + "\"TestTemperature\": 9080.866\n" + "}"; + + nextEventName + "\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_" + eventsSent++ + "\",\n" + + "\"target\": \"apex\",\n" + "\"TestSlogan\": \"Test slogan for External Event0\",\n" + + "\"TestMatchCase\": " + nextMatchCase + ",\n" + "\"TestTimestamp\": " + System.currentTimeMillis() + ",\n" + + "\"TestTemperature\": 9080.866\n" + "}"; return eventString; } diff --git a/testsuites/integration/integration-uservice-test/src/test/resources/logback-test.xml b/testsuites/integration/integration-uservice-test/src/test/resources/logback-test.xml new file mode 100644 index 000000000..fbe9ffc29 --- /dev/null +++ b/testsuites/integration/integration-uservice-test/src/test/resources/logback-test.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============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========================================================= +--> + +<configuration> + <contextName>Apex</contextName> + <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> + + <!-- USE FOR STD OUT ONLY --> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern> + </encoder> + </appender> + + <root level="INFO"> + <appender-ref ref="STDOUT" /> + </root> + +</configuration> diff --git a/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEmptyEvents.json b/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEmptyEvents.json index fae8987ac..338c98fa3 100644 --- a/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEmptyEvents.json +++ b/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEmptyEvents.json @@ -33,7 +33,7 @@ "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { - "fileName": "src/test/resources/events/EventsOut.json" + "fileName": "target/EventsOut.json" } }, "eventProtocolParameters": { diff --git a/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventBadHTTPMethod.json b/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventBadHTTPMethod.json index 8b779668d..90f6c5b7d 100644 --- a/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventBadHTTPMethod.json +++ b/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventBadHTTPMethod.json @@ -34,7 +34,7 @@ "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { - "fileName": "src/test/resources/events/EventsOut.json" + "fileName": "target/EventsOut.json" } }, "eventProtocolParameters": { diff --git a/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventBadResponse.json b/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventBadResponse.json index fb79d6536..fbe5d34b7 100644 --- a/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventBadResponse.json +++ b/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventBadResponse.json @@ -33,7 +33,7 @@ "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { - "fileName": "src/test/resources/events/EventsOut.json" + "fileName": "target/EventsOut.json" } }, "eventProtocolParameters": { diff --git a/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventBadURL.json b/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventBadURL.json index 8a188799c..d584762d6 100644 --- a/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventBadURL.json +++ b/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventBadURL.json @@ -33,7 +33,7 @@ "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { - "fileName": "src/test/resources/events/EventsOut.json" + "fileName": "target/EventsOut.json" } }, "eventProtocolParameters": { diff --git a/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventNoURL.json b/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventNoURL.json index 65ddb2583..ed6a1bb1e 100644 --- a/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventNoURL.json +++ b/testsuites/integration/integration-uservice-test/src/test/resources/prodcons/REST2FileJsonEventNoURL.json @@ -30,7 +30,7 @@ "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { - "fileName": "src/test/resources/events/EventsOut.json" + "fileName": "target/EventsOut.json" } }, "eventProtocolParameters": { diff --git a/testsuites/integration/integration-uservice-test/src/test/resources/testdata/executionproperties/RESTEventBadHttpCodeFilter.json b/testsuites/integration/integration-uservice-test/src/test/resources/testdata/executionproperties/RESTEventBadHttpCodeFilter.json index 5da96ae9c..253008b43 100644 --- a/testsuites/integration/integration-uservice-test/src/test/resources/testdata/executionproperties/RESTEventBadHttpCodeFilter.json +++ b/testsuites/integration/integration-uservice-test/src/test/resources/testdata/executionproperties/RESTEventBadHttpCodeFilter.json @@ -41,7 +41,7 @@ "carrierTechnologyParameters": { "carrierTechnology": "FILE", "parameters": { - "fileName": "src/test/resources/events/EventsOut.json" + "fileName": "target/EventsOut.json" } }, "eventProtocolParameters": { |