--- old/test/java/rmi/testlibrary/TestLibrary.java 2014-12-23 17:01:30.000000000 -0800 +++ new/test/java/rmi/testlibrary/TestLibrary.java 2014-12-23 17:01:30.000000000 -0800 @@ -135,7 +135,8 @@ */ public static boolean checkIfRegistryRunning(int port, int msTimeout) { - long stopTime = System.currentTimeMillis() + msTimeout; + final long POLLTIME_MS = 100L; + long stopTime = computeDeadline(System.currentTimeMillis(), msTimeout); do { try { Registry r = LocateRegistry.getRegistry(port); @@ -145,12 +146,12 @@ } catch (RemoteException e) { // problem - not ready ? Try again try { - Thread.sleep(500); + Thread.sleep(POLLTIME_MS); } catch (InterruptedException ie) { // not expected } } - } while (stopTime > System.currentTimeMillis()); + } while (System.currentTimeMillis() < stopTime); return false; } @@ -169,6 +170,31 @@ } } + public static double getTimeoutFactor() { + String prop = getProperty("test.timeout.factor", "1.0"); + double timeoutFactor = 1.0; + + try { + timeoutFactor = Double.parseDouble(prop); + } catch (NumberFormatException ignore) { } + + return timeoutFactor; + } + + /** + * Computes a deadline from a timestamp and a timeout value. + * Maximum timeout (before multipliers are applied) is one hour. + */ + public static long computeDeadline(long timestamp, long timeout) { + final long MAX_TIMEOUT_MS = 3_600_000L; + + if (timeout < 0L || timeout > MAX_TIMEOUT_MS) { + throw new IllegalArgumentException("timeout " + timeout + "ms out of range"); + } + + return timestamp + (long)(timeout * getTimeoutFactor()); + } + /** * Property mutators */