[java-idp-integration-tests] 01/07: Wait for server to stop by querying status page

Tom Zeller tzeller at dragonacea.biz
Fri Mar 23 19:36:25 EDT 2018


This is an automated email from the git hooks/post-receive script.

tzeller pushed a commit to branch master
in repository java-idp-integration-tests.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-integration-tests.git;a=commit;h=7b2215b6dad50fcbbaabaf001e7fbe71f360bd84

commit 7b2215b6dad50fcbbaabaf001e7fbe71f360bd84
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Fri Mar 23 17:00:48 2018 -0500

    Wait for server to stop by querying status page
---
 .../shibboleth/idp/test/AbstractServerProcess.java | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/src/test/java/net/shibboleth/idp/test/AbstractServerProcess.java b/src/test/java/net/shibboleth/idp/test/AbstractServerProcess.java
index 0b15b36..9ee531f 100644
--- a/src/test/java/net/shibboleth/idp/test/AbstractServerProcess.java
+++ b/src/test/java/net/shibboleth/idp/test/AbstractServerProcess.java
@@ -18,6 +18,7 @@
 package net.shibboleth.idp.test;
 
 import java.io.IOException;
+import java.net.ConnectException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -423,6 +424,7 @@ public class AbstractServerProcess extends AbstractInitializableComponent implem
     /** {@inheritDoc} */
     @Override
     public void stop() {
+        waitForServerToStop(10, 500); // wait 5s for server to stop
         if (process != null) {
             log.trace("Stopping process");
             process.destroy();
@@ -442,4 +444,40 @@ public class AbstractServerProcess extends AbstractInitializableComponent implem
         return isRunning;
     }
 
+    /**
+     * Wait for server to stop.
+     * 
+     * If server status page is available, wait until it is not available.
+     * 
+     * @param retries maximum number of times to retry
+     * @param millis length of time to sleep in milliseconds between retry attempts
+     */
+    public void waitForServerToStop(@Nonnull final int retries, @Nonnull final int millis) {
+        try {
+            log.debug("Waiting for server to stop ...");
+            if (getStatusPageText(1, 0) == null) {
+                log.debug("Server appears to be stopped.");
+                return;
+            }
+            int executionCount = 0;
+            while (executionCount < retries) {
+                log.debug("Server still running, waiting '{}'ms for server to stop ...", millis);
+                Thread.sleep(millis);
+                if (getStatusPageText(1, 0) == null) { // is server up ?
+                    log.debug("Server appears to be stopped.");
+                    return;
+                }
+            }
+            log.warn("Server did not stop.");
+        } catch (final ConnectException e) {
+            if (e.getMessage().endsWith("Connection refused (Connection refused)")) {
+                log.debug("Server appears to be stopped.");
+            } else {
+                log.warn("Server might be stopped", e);
+            }
+        } catch (final Exception e) {
+            log.warn("An error occurred waiting for server to stop", e);
+        }
+    }
+
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list