# HG changeset patch # User smarks # Date 1417748077 28800 # Node ID 9089cd529a79434b88fc92126ce1e02d61ef3798 # Parent 3107be2ba9c6e208a0b86bc7100a141abbc5b5fb 8035001: TEST_BUG: the retry logic in RMID.start() should check that the subprocess hasn't terminated Reviewed-by: lancea diff -r 3107be2ba9c6 -r 9089cd529a79 jdk/test/java/rmi/testlibrary/JavaVM.java --- a/jdk/test/java/rmi/testlibrary/JavaVM.java Wed Jul 05 20:10:08 2017 +0200 +++ b/jdk/test/java/rmi/testlibrary/JavaVM.java Thu Dec 04 18:54:37 2014 -0800 @@ -34,6 +34,8 @@ */ public class JavaVM { + public static final long POLLTIME_MS = 100L; + protected Process vm = null; private String classname = ""; @@ -192,23 +194,21 @@ throws InterruptedException, TimeoutException { if (vm == null) throw new IllegalStateException("can't wait for JavaVM that isn't running"); - long startTime = System.currentTimeMillis(); - long rem = timeout; + long deadline = System.currentTimeMillis() + timeout; - do { + while (true) { try { int status = vm.exitValue(); outPipe.join(); errPipe.join(); return status; - } catch (IllegalThreadStateException ex) { - if (rem > 0) { - Thread.sleep(Math.min(rem, 100)); - } - } - rem = timeout - (System.currentTimeMillis() - startTime); - } while (rem > 0); - throw new TimeoutException(); + } catch (IllegalThreadStateException ignore) { } + + if (System.currentTimeMillis() > deadline) + throw new TimeoutException(); + + Thread.sleep(POLLTIME_MS); + } } /** diff -r 3107be2ba9c6 -r 9089cd529a79 jdk/test/java/rmi/testlibrary/RMID.java --- a/jdk/test/java/rmi/testlibrary/RMID.java Wed Jul 05 20:10:08 2017 +0200 +++ b/jdk/test/java/rmi/testlibrary/RMID.java Thu Dec 04 18:54:37 2014 -0800 @@ -256,19 +256,28 @@ } catch (NumberFormatException ignore) {} waitTime = waitTime * slopFactor; - // We check several times, for a maximum of waitTime, until we have - // verified that rmid is running. - do { + long startTime = System.currentTimeMillis(); + long deadline = startTime + waitTime; + + while (true) { try { - Thread.sleep(Math.min(waitTime, POLLTIME_MS)); + Thread.sleep(POLLTIME_MS); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); - mesg("Interrupted while starting activation system, giving up."); + mesg("Starting rmid interrupted, giving up at " + + (System.currentTimeMillis() - startTime) + "ms."); return; } - waitTime -= POLLTIME_MS; - // Checking if rmid is present + try { + int status = vm.exitValue(); + TestLibrary.bomb("Rmid process exited with status " + status + " after " + + (System.currentTimeMillis() - startTime) + "ms."); + } catch (IllegalThreadStateException ignore) { } + + // The rmid process is alive; check to see whether + // it responds to a remote call. + if (lookupSystem(port) != null) { /* * We need to set the java.rmi.activation.port value as the @@ -278,15 +287,16 @@ * incorrect value. */ System.setProperty("java.rmi.activation.port", Integer.toString(port)); - mesg("Started successfully."); + mesg("Started successfully after " + + (System.currentTimeMillis() - startTime) + "ms."); return; - } else { - if (waitTime > 0) { - mesg("rmid not started, will retry for " + waitTime + "ms"); - } } - } while (waitTime > 0); - TestLibrary.bomb("Failed to start rmid, giving up.", null); + + if (System.currentTimeMillis() > deadline) { + TestLibrary.bomb("Failed to start rmid, giving up after " + + (System.currentTimeMillis() - startTime) + "ms.", null); + } + } } /** @@ -309,9 +319,11 @@ */ private boolean shutdown() throws InterruptedException { mesg("shutdown()"); + long startTime = System.currentTimeMillis(); ActivationSystem system = lookupSystem(port); if (system == null) { - mesg("lookupSystem() returned null"); + mesg("lookupSystem() returned null after " + + (System.currentTimeMillis() - startTime) + "ms."); return false; } @@ -325,10 +337,12 @@ try { waitFor(TIMEOUT_SHUTDOWN_MS); - mesg("Shutdown successful."); + mesg("Shutdown successful after " + + (System.currentTimeMillis() - startTime) + "ms."); return true; } catch (TimeoutException ex) { - mesg("Shutdown timed out:"); + mesg("Shutdown timed out after " + + (System.currentTimeMillis() - startTime) + "ms:"); ex.printStackTrace(); return false; } @@ -344,6 +358,8 @@ throw new IllegalStateException("can't wait for RMID that isn't running"); } + long startTime = System.currentTimeMillis(); + // First, attempt graceful shutdown of the activation system. try { if (! shutdown()) { @@ -352,14 +368,17 @@ vm.destroy(); try { waitFor(TIMEOUT_DESTROY_MS); - mesg("Destroy successful."); + mesg("Destroy successful after " + + (System.currentTimeMillis() - startTime) + "ms."); } catch (TimeoutException ex) { - mesg("Destroy timed out, giving up."); + mesg("Destroy timed out, giving up after " + + (System.currentTimeMillis() - startTime) + "ms:"); ex.printStackTrace(); } } } catch (InterruptedException ie) { - mesg("Shutdown/destroy interrupted, giving up."); + mesg("Shutdown/destroy interrupted, giving up at " + + (System.currentTimeMillis() - startTime) + "ms."); ie.printStackTrace(); Thread.currentThread().interrupt(); return;