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;
*/
@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());
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();
}
/**
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;
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;
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;
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;
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
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;
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
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);
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
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);
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
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);
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);
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"));
}
/**
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);
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"));
}
}
"carrierTechnologyParameters": {
"carrierTechnology": "FILE",
"parameters": {
- "fileName": "src/test/resources/events/EventsOut.json"
+ "fileName": "target/EventsOut.json"
}
},
"eventProtocolParameters": {
"carrierTechnologyParameters": {
"carrierTechnology": "FILE",
"parameters": {
- "fileName": "src/test/resources/events/EventsOut.json"
+ "fileName": "target/EventsOut.json"
}
},
"eventProtocolParameters": {
"carrierTechnologyParameters": {
"carrierTechnology": "FILE",
"parameters": {
- "fileName": "src/test/resources/events/EventsOut.json"
+ "fileName": "target/EventsOut.json"
}
},
"eventProtocolParameters": {
"carrierTechnologyParameters": {
"carrierTechnology": "FILE",
"parameters": {
- "fileName": "src/test/resources/events/EventsOut.json"
+ "fileName": "target/EventsOut.json"
}
},
"eventProtocolParameters": {
"carrierTechnologyParameters": {
"carrierTechnology": "FILE",
"parameters": {
- "fileName": "src/test/resources/events/EventsOutMulti0.json"
+ "fileName": "target/EventsOutMulti0.json"
}
},
"eventProtocolParameters": {
"carrierTechnologyParameters": {
"carrierTechnology": "FILE",
"parameters": {
- "fileName": "src/test/resources/events/EventsOutMulti1.json"
+ "fileName": "target/EventsOutMulti1.json"
}
},
"eventProtocolParameters": {
"carrierTechnologyParameters": {
"carrierTechnology": "FILE",
"parameters": {
- "fileName": "src/test/resources/events/EventsOut.json"
+ "fileName": "target/EventsOut.json"
}
},
"eventProtocolParameters": {
"carrierTechnologyParameters": {
"carrierTechnology": "FILE",
"parameters": {
- "fileName": "src/test/resources/events/EventsOut.json"
+ "fileName": "target/EventsOut.json"
}
},
"eventProtocolParameters": {
"carrierTechnologyParameters": {
"carrierTechnology": "FILE",
"parameters": {
- "fileName": "src/test/resources/events/EventsOut.json"
+ "fileName": "target/EventsOut.json"
}
},
"eventProtocolParameters": {
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
-
</dependencies>
<profiles>
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;
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) {
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();
}
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) {
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);
}
}
+ resultQueue.add(false);
+
try {
Context.exit();
} catch (final Exception e) {
}).doesNotThrowAnyException();
assertThatCode(() -> {
- executor.init("while (true) { x = 1; }; true;");
+ executor.init("var x = 0; while (x < 100) { x++; }; true;");
}).doesNotThrowAnyException();
concurrentResult.set(true);
(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());
/*-
* ============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.
* @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;
// 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();
// 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:
*/
@Override
public void receiveEvent(@NonNull final Properties executionProperties, final Object event)
- throws ApexEventException {
+ throws ApexEventException {
receiveEvent(0, executionProperties, event, true);
}
*/
@Override
public void receiveEvent(final long executionId, @NonNull final Properties executionProperties, final Object event)
- throws ApexEventException {
+ throws ApexEventException {
receiveEvent(executionId, executionProperties, event, false);
}
* @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();
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);
}
// 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;
// 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();
}
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;
*/
@Test
public void testApexEngineJRuby() throws ApexException, InterruptedException, IOException {
- new TestApexEngine("JRUBY", engineParameters);
- new TestApexEngine("JRUBY", engineParameters);
+ assertThatCode(() -> {
+ new TestApexEngine("JRUBY", engineParameters);
+ }).doesNotThrowAnyException();
}
}
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);
}
/**
* @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);
*/
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>");
}
}
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;
@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());
}
}
- /**
- * Delete temp files.
- */
- @AfterClass
- public static void deleteTempFiles() {
- new File("src/test/resources/events/EventsOut.json").delete();
- }
-
/**
* Test rest events in.
*
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\"");
}
/**
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\"");
}
/**
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");
}
/**
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");
}
/**
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 \"");
}
/**
/*-
* ============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.
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;
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");
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;
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"));
@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");
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;
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"));
@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");
// 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());
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");
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;
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;
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"));
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");
}
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);
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);
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");
}
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");
}
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");
}
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");
}
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;
}
--- /dev/null
+<?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>
"carrierTechnologyParameters": {
"carrierTechnology": "FILE",
"parameters": {
- "fileName": "src/test/resources/events/EventsOut.json"
+ "fileName": "target/EventsOut.json"
}
},
"eventProtocolParameters": {
"carrierTechnologyParameters": {
"carrierTechnology": "FILE",
"parameters": {
- "fileName": "src/test/resources/events/EventsOut.json"
+ "fileName": "target/EventsOut.json"
}
},
"eventProtocolParameters": {
"carrierTechnologyParameters": {
"carrierTechnology": "FILE",
"parameters": {
- "fileName": "src/test/resources/events/EventsOut.json"
+ "fileName": "target/EventsOut.json"
}
},
"eventProtocolParameters": {
"carrierTechnologyParameters": {
"carrierTechnology": "FILE",
"parameters": {
- "fileName": "src/test/resources/events/EventsOut.json"
+ "fileName": "target/EventsOut.json"
}
},
"eventProtocolParameters": {
"carrierTechnologyParameters": {
"carrierTechnology": "FILE",
"parameters": {
- "fileName": "src/test/resources/events/EventsOut.json"
+ "fileName": "target/EventsOut.json"
}
},
"eventProtocolParameters": {
"carrierTechnologyParameters": {
"carrierTechnology": "FILE",
"parameters": {
- "fileName": "src/test/resources/events/EventsOut.json"
+ "fileName": "target/EventsOut.json"
}
},
"eventProtocolParameters": {