aboutsummaryrefslogtreecommitdiffstats
path: root/testsuites/integration/integration-uservice-test/src/test/java
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-04-01 09:38:33 +0100
committerliamfallon <liam.fallon@est.tech>2020-04-02 16:33:47 +0100
commit30f94aa98ebc8931e224cdd2e5b8c25949379065 (patch)
treefe1391f867cd11726da9dfcf6b6089dd74f4c3ef /testsuites/integration/integration-uservice-test/src/test/java
parent42cd61abcc9cd27e72eaa34a746ee176dbf30750 (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 'testsuites/integration/integration-uservice-test/src/test/java')
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/file/TestFile2FileIgnore.java8
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java29
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java103
3 files changed, 72 insertions, 68 deletions
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;
}