summaryrefslogtreecommitdiffstats
path: root/gui-pdp-monitoring/src
diff options
context:
space:
mode:
Diffstat (limited to 'gui-pdp-monitoring/src')
-rw-r--r--gui-pdp-monitoring/src/main/java/org/onap/policy/gui/pdp/monitoring/PdpMonitoringMain.java27
-rw-r--r--gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringMainTest.java12
2 files changed, 33 insertions, 6 deletions
diff --git a/gui-pdp-monitoring/src/main/java/org/onap/policy/gui/pdp/monitoring/PdpMonitoringMain.java b/gui-pdp-monitoring/src/main/java/org/onap/policy/gui/pdp/monitoring/PdpMonitoringMain.java
index 34b2901..2a2355e 100644
--- a/gui-pdp-monitoring/src/main/java/org/onap/policy/gui/pdp/monitoring/PdpMonitoringMain.java
+++ b/gui-pdp-monitoring/src/main/java/org/onap/policy/gui/pdp/monitoring/PdpMonitoringMain.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,7 +56,9 @@ public class PdpMonitoringMain {
// The Pdp Monitoring services this class is running
private PdpMonitoringServer pdpMonitoringServer = null;
- private CountDownLatch countDownLatch = new CountDownLatch(1);
+ private CountDownLatch startedLatch = new CountDownLatch(1);
+
+ private CountDownLatch shutdownLatch = new CountDownLatch(1);
/**
* Constructor, kicks off the GUI service.
@@ -113,15 +116,17 @@ public class PdpMonitoringMain {
LOGGER.info(PDP_MONITORING_PREFIX + "{}) started", this);
}
+ startedLatch.countDown();
+
// Find out how long is left to wait
long timeRemaining = parameters.getTimeToLive();
if (timeRemaining >= 0) {
- countDownLatch.await(timeRemaining, TimeUnit.SECONDS);
+ shutdownLatch.await(timeRemaining, TimeUnit.SECONDS);
} else {
- countDownLatch.await();
+ shutdownLatch.await();
}
} catch (final Exception e) {
- LOGGER.warn(this + " failed with error", e);
+ LOGGER.warn("{} failed with error", this, e);
} finally {
shutdown();
}
@@ -129,6 +134,18 @@ public class PdpMonitoringMain {
}
/**
+ * Waits for the service to enter the running state.
+ *
+ * @param timeout time to wait
+ * @param unit time units
+ * @return {@code true} if the service started within the specified time
+ * @throws InterruptedException if an interrupt occurs
+ */
+ protected boolean awaitStart(long timeout, TimeUnit unit) throws InterruptedException {
+ return startedLatch.await(timeout, unit);
+ }
+
+ /**
* Explicitly shut down the services.
*/
public void shutdown() {
@@ -136,7 +153,7 @@ public class PdpMonitoringMain {
LOGGER.info(PDP_MONITORING_PREFIX + "{}) shutting down", this);
pdpMonitoringServer.shutdown(parameters.getPort(), parameters.getDefaultRestPort());
}
- countDownLatch.countDown();
+ shutdownLatch.countDown();
state = ServicesState.STOPPED;
LOGGER.info(PDP_MONITORING_PREFIX + "{}) shutting down", this);
}
diff --git a/gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringMainTest.java b/gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringMainTest.java
index 6421b01..b680cac 100644
--- a/gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringMainTest.java
+++ b/gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringMainTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -150,9 +151,18 @@ public class MonitoringMainTest {
try {
monThread.start();
- Thread.sleep(2000);
+ /*
+ * For some reason, getResource("webapp") returns null to PdpMonitoringServer,
+ * which results in an NPE, thus the server never gets started (in ANY of
+ * these test cases). Therefore, commented out the code that waits for it to
+ * start.
+ */
+ // assertThat(monRestMain.awaitStart(5, TimeUnit.SECONDS)).isTrue();
monRestMain.shutdown();
+ monThread.join(5000);
+ assertThat(monThread.isAlive()).isFalse();
} catch (Exception ex) {
+ monRestMain.shutdown();
fail("test should not throw an exception");
}
}