X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-interactions%2Fmodel-simulators%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fsimulators%2FUtil.java;h=d9fb52bd9798d537c4df9df7a5dfe67d7975c74e;hb=bd8bf6a10ae1669eace1aab6d4035a05696596de;hp=5cb518f4e6db130490a3856e2150cfffe88911bc;hpb=50b5f7233f63ff6f1f5703885d461d05b0ec3e67;p=policy%2Fmodels.git diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java index 5cb518f4e..d9fb52bd9 100644 --- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java +++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java @@ -21,6 +21,7 @@ package org.onap.policy.simulators; +import java.io.IOException; import java.util.Properties; import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; @@ -46,11 +47,12 @@ public class Util { public static final int VFCSIM_SERVER_PORT = 6668; public static final int GUARDSIM_SERVER_PORT = 6669; public static final int SDNCSIM_SERVER_PORT = 6670; + public static final int CDSSIM_SERVER_PORT = 6671; public static final int DMAAPSIM_SERVER_PORT = 3904; private static final String CANNOT_PROCESS_PARAMETERS = "cannot parse parameters "; private static final String CANNOT_CONNECT = "cannot connect to port "; - private static final String LOCALHOST = "localhost"; + public static final String LOCALHOST = "localhost"; private Util() { // Prevent instantiation of this class @@ -67,9 +69,21 @@ public class Util { .build(AAISIM_SERVER_NAME, LOCALHOST, AAISIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", AaiSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); - if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { - throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); - } + waitForServerToListen(testServer.getPort()); + return testServer; + } + + /** + * Build a CDS simulator. + * + * @return the simulator + * @throws InterruptedException if a thread is interrupted + * @throws IOException if an I/O error occurs + */ + public static CdsSimulator buildCdsSim() throws InterruptedException, IOException { + final CdsSimulator testServer = new CdsSimulator(LOCALHOST, CDSSIM_SERVER_PORT); + testServer.start(); + waitForServerToListen(testServer.getPort()); return testServer; } @@ -84,9 +98,7 @@ public class Util { .build(SDNCSIM_SERVER_NAME, LOCALHOST, SDNCSIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", SdncSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); - if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { - throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); - } + waitForServerToListen(testServer.getPort()); return testServer; } @@ -102,9 +114,7 @@ public class Util { .build(SOSIM_SERVER_NAME, LOCALHOST, SOSIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", SoSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); - if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { - throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); - } + waitForServerToListen(testServer.getPort()); return testServer; } @@ -119,9 +129,7 @@ public class Util { .build(VFCSIM_SERVER_NAME, LOCALHOST, VFCSIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", VfcSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); - if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { - throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); - } + waitForServerToListen(testServer.getPort()); return testServer; } @@ -136,9 +144,7 @@ public class Util { LOCALHOST, GUARDSIM_SERVER_PORT, "/", false, true); testServer.addServletClass("/*", GuardSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); - if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) { - throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); - } + waitForServerToListen(testServer.getPort()); return testServer; } @@ -170,9 +176,13 @@ public class Util { HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory().build(props).get(0); testServer.waitedStart(5000); - if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 50, 1000L)) { - throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort()); - } + waitForServerToListen(testServer.getPort()); return testServer; } + + private static void waitForServerToListen(int port) throws InterruptedException { + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, port, 200, 250L)) { + throw new IllegalStateException(CANNOT_CONNECT + port); + } + } }