--- old/test/java/rmi/testlibrary/RMID.java 2016-09-27 02:08:12.941658999 -0700 +++ new/test/java/rmi/testlibrary/RMID.java 2016-09-27 02:08:12.736761495 -0700 @@ -22,6 +22,7 @@ */ import java.io.*; +import java.net.BindException; import java.rmi.*; import java.rmi.activation.*; import java.rmi.registry.*; @@ -42,7 +43,7 @@ private static final long TIMEOUT_SHUTDOWN_MS = 60_000L; private static final long TIMEOUT_DESTROY_MS = 10_000L; private static final long STARTTIME_MS = 15_000L; - private static final long POLLTIME_MS = 100L; + private static final long POLLTIME_MS = 2000L; private static final String SYSTEM_NAME = ActivationSystem.class.getName(); // "java.rmi.activation.ActivationSystem" @@ -145,8 +146,8 @@ * policy file. */ public static RMID createRMID() { - return createRMID(System.out, System.err, true, true, - TestLibrary.getUnusedRandomPort()); + return createRMID(System.out, System.err, true, true, + TestLibrary.getUnusedRandomPort()); } public static RMID createRMID(OutputStream out, OutputStream err, @@ -181,6 +182,13 @@ this.port = port; } + private void checkAddressInUser() throws BindException { + if (outputContains("Address already in use") + || outputContains("Port already in use")) { + throw new BindException("Address already in use at port: " + port); + } + } + /** * Removes rmid's log file directory. */ @@ -229,6 +237,23 @@ } } + public static RMID launch() throws IOException { + RMID rmid = null; + for (int i = 0; i < 20; i++) { + RMID.removeLog(); + rmid = RMID.createRMID(); + try { + rmid.start(); + break; + } catch (BindException ex) { + System.err.format("%ncatch BindException(%s), " + + "continue to launch rmid again...%n%n", ex.getMessage()); + continue; + } + } + return rmid; + } + /** * Starts rmid and waits up to the default timeout period * to confirm that it's running. @@ -270,6 +295,7 @@ } try { + checkAddressInUser(); int status = vm.exitValue(); TestLibrary.bomb("Rmid process exited with status " + status + " after " + (System.currentTimeMillis() - startTime) + "ms."); @@ -293,6 +319,7 @@ } if (System.currentTimeMillis() > deadline) { + checkAddressInUser(); TestLibrary.bomb("Failed to start rmid, giving up after " + (System.currentTimeMillis() - startTime) + "ms.", null); }