changeset 25751:561ceea4b5e9

8049194: com/sun/tools/attach/StartManagementAgent.java start failing after JDK-8048193 Reviewed-by: dfuchs, egahlin, olagneau
author jbachorik
date Fri, 25 Jul 2014 15:07:49 +0200
parents 345f7cc9cf8f
children 8df7ddac1cb3
files jdk/test/com/sun/jdi/ExclusiveBind.java jdk/test/javax/management/monitor/StartStopTest.java jdk/test/lib/testlibrary/jdk/testlibrary/ProcessThread.java jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java jdk/test/lib/testlibrary/jdk/testlibrary/Utils.java
diffstat 5 files changed, 47 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/test/com/sun/jdi/ExclusiveBind.java	Fri Jul 25 17:11:03 2014 +0800
+++ b/jdk/test/com/sun/jdi/ExclusiveBind.java	Fri Jul 25 15:07:49 2014 +0200
@@ -108,7 +108,7 @@
                 "process1",
                 process1,
                 line -> line.equals("Listening for transport dt_socket at address: " + address),
-                Math.round(5000 * Utils.TIMEOUT_FACTOR),
+                Utils.adjustTimeout(5000),
                 TimeUnit.MILLISECONDS
         );
 
--- a/jdk/test/javax/management/monitor/StartStopTest.java	Fri Jul 25 17:11:03 2014 +0800
+++ b/jdk/test/javax/management/monitor/StartStopTest.java	Fri Jul 25 15:07:49 2014 +0200
@@ -213,6 +213,6 @@
     }
 
     private static void doSleep(long ms) throws Exception {
-        Thread.sleep(Math.round(ms * Utils.TIMEOUT_FACTOR));
+        Thread.sleep(Utils.adjustTimeout(ms));
     }
 }
--- a/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessThread.java	Fri Jul 25 17:11:03 2014 +0800
+++ b/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessThread.java	Fri Jul 25 15:07:49 2014 +0200
@@ -148,9 +148,7 @@
          */
         @Override
         public void xrun() throws Throwable {
-            this.process = ProcessTools.startProcess(
-                name, processBuilder, waitfor, -1, TimeUnit.SECONDS
-            );
+            this.process = ProcessTools.startProcess(name, processBuilder, waitfor);
             // Release when process is started
             latch.countDown();
 
--- a/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java	Fri Jul 25 17:11:03 2014 +0800
+++ b/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java	Fri Jul 25 15:07:49 2014 +0200
@@ -74,7 +74,7 @@
     public static Process startProcess(String name,
                                        ProcessBuilder processBuilder)
     throws IOException {
-        return startProcess(name, processBuilder, null);
+        return startProcess(name, processBuilder, (Consumer)null);
     }
 
     /**
@@ -124,7 +124,7 @@
      *                      Used to determine the moment the target app is
      *                      properly warmed-up.
      *                      It can be null - in that case the warmup is skipped.
-     * @param timeout The timeout for the warmup waiting
+     * @param timeout The timeout for the warmup waiting; -1 = no wait; 0 = wait forever
      * @param unit The timeout {@linkplain TimeUnit}
      * @return Returns the initialized {@linkplain Process}
      * @throws IOException
@@ -156,15 +156,20 @@
             };
             stdout.addPump(pump);
             stderr.addPump(pump);
+        } else {
+            latch.countDown();
         }
         Future<Void> stdoutTask = stdout.process();
         Future<Void> stderrTask = stderr.process();
 
         try {
             if (timeout > -1) {
-                long realTimeout = Math.round(timeout * Utils.TIMEOUT_FACTOR);
-                if (!latch.await(realTimeout, unit)) {
-                    throw new TimeoutException();
+                if (timeout == 0) {
+                    latch.await();
+                } else {
+                    if (!latch.await(Utils.adjustTimeout(timeout), unit)) {
+                        throw new TimeoutException();
+                    }
                 }
             }
         } catch (TimeoutException | InterruptedException e) {
@@ -181,6 +186,31 @@
     }
 
     /**
+     * <p>Starts a process from its builder.</p>
+     * <span>The default redirects of STDOUT and STDERR are started</span>
+     * <p>
+     * It is possible to wait for the process to get to a warmed-up state
+     * via {@linkplain Predicate} condition on the STDOUT
+     * </p>
+     * @param name The process name
+     * @param processBuilder The process builder
+     * @param linePredicate The {@linkplain Predicate} to use on the STDOUT
+     *                      Used to determine the moment the target app is
+     *                      properly warmed-up.
+     *                      It can be null - in that case the warmup is skipped.
+     * @return Returns the initialized {@linkplain Process}
+     * @throws IOException
+     * @throws InterruptedException
+     * @throws TimeoutException
+     */
+    public static Process startProcess(String name,
+                                       ProcessBuilder processBuilder,
+                                       final Predicate<String> linePredicate)
+    throws IOException, InterruptedException, TimeoutException {
+        return startProcess(name, processBuilder, linePredicate, 0, TimeUnit.SECONDS);
+    }
+
+    /**
      * Pumps stdout and stderr from running the process into a String.
      *
      * @param processBuilder
--- a/jdk/test/lib/testlibrary/jdk/testlibrary/Utils.java	Fri Jul 25 17:11:03 2014 +0800
+++ b/jdk/test/lib/testlibrary/jdk/testlibrary/Utils.java	Fri Jul 25 15:07:49 2014 +0200
@@ -280,4 +280,13 @@
         return output;
     }
 
+    /**
+     * Adjusts the provided timeout value for the TIMEOUT_FACTOR
+     * @param tOut the timeout value to be adjusted
+     * @return The timeout value adjusted for the value of "test.timeout.factor"
+     *         system property
+     */
+    public static long adjustTimeout(long tOut) {
+        return Math.round(tOut * Utils.TIMEOUT_FACTOR);
+    }
 }