diff --git a/test/jdk/java/security/cert/CertPathValidator/OCSP/GetAndPostTests.java b/test/jdk/java/security/cert/CertPathValidator/OCSP/GetAndPostTests.java index 1dc8cba5cc5..f8e1ae751b6 100644 --- a/test/jdk/java/security/cert/CertPathValidator/OCSP/GetAndPostTests.java +++ b/test/jdk/java/security/cert/CertPathValidator/OCSP/GetAndPostTests.java @@ -62,16 +62,14 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; -import sun.security.testlibrary.SimpleOCSPServer; -import sun.security.testlibrary.SimpleOCSPServer; import sun.security.testlibrary.SimpleOCSPServer; import sun.security.util.DerOutputStream; import sun.security.util.DerValue; import sun.security.util.ObjectIdentifier; -import sun.security.testlibrary.SimpleOCSPServer; public class GetAndPostTests { private static final String PASS = "passphrase"; + private static final int SERVER_WAIT_SECS = 60; private static CertificateFactory certFac; public static void main(String args[]) throws Exception { @@ -114,13 +112,8 @@ public class GetAndPostTests { endEntCert.getSerialNumber(), new SimpleOCSPServer.CertStatusInfo( SimpleOCSPServer.CertStatus.CERT_STATUS_GOOD))); - ocspResponder.start(); - // Wait 5 seconds for server ready - boolean readyStatus = - ocspResponder.awaitServerReady(5, TimeUnit.SECONDS); - if (!readyStatus) { - throw new RuntimeException("Server not ready"); - } + + startOcspServer(ocspResponder); int ocspPort = ocspResponder.getPort(); URI ocspURI = new URI("http://localhost:" + ocspPort); @@ -169,6 +162,14 @@ public class GetAndPostTests { } } + private static void startOcspServer(SimpleOCSPServer ocspResponder) throws InterruptedException, IOException { + ocspResponder.start(); + if (!ocspResponder.awaitServerReady(SERVER_WAIT_SECS, TimeUnit.SECONDS)) { + throw new RuntimeException("Server not ready after " + SERVER_WAIT_SECS + + " seconds."); + } + } + /** * Create an X509Certificate object from its PEM encoding * diff --git a/test/jdk/java/security/testlibrary/SimpleOCSPServer.java b/test/jdk/java/security/testlibrary/SimpleOCSPServer.java index aad98336ed9..e4b06a26504 100644 --- a/test/jdk/java/security/testlibrary/SimpleOCSPServer.java +++ b/test/jdk/java/security/testlibrary/SimpleOCSPServer.java @@ -288,10 +288,18 @@ public class SimpleOCSPServer { public synchronized void stop() { if (started) { receivedShutdown = true; + started = false; log("Received shutdown notification"); } } + public synchronized void shutdownNow() { + stop(); + if (threadPool != null) { + threadPool.shutdownNow(); + } + } + /** * Print {@code SimpleOCSPServer} operating parameters. * @@ -577,7 +585,7 @@ public class SimpleOCSPServer { * @param message the message to log */ private static synchronized void err(String message) { - System.out.println("[" + Thread.currentThread().getName() + "]: " + + System.err.println("[" + Thread.currentThread().getName() + "]: " + message); }