changeset 12289:515aada65cf2

8080138: sun/management/jmxremote/startstop/JMXStartStopTest.java failed with java.lang.Error intermittently Reviewed-by: sla
author jbachorik
date Mon, 22 Jun 2015 12:13:56 +0200
parents e8ea2a3147f9
children 296c6eee7830
files test/sun/management/jmxremote/startstop/JMXStartStopTest.java
diffstat 1 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/test/sun/management/jmxremote/startstop/JMXStartStopTest.java	Mon Jun 22 12:13:39 2015 +0200
+++ b/test/sun/management/jmxremote/startstop/JMXStartStopTest.java	Mon Jun 22 12:13:56 2015 +0200
@@ -21,6 +21,7 @@
  * questions.
  */
 
+import java.io.EOFException;
 import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
@@ -36,7 +37,6 @@
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -45,6 +45,7 @@
 import javax.net.ssl.SSLHandshakeException;
 
 import jdk.testlibrary.ProcessTools;
+import jdk.testlibrary.Utils;
 import sun.management.Agent;
 import sun.management.AgentConfigurationError;
 
@@ -155,7 +156,28 @@
     }
 
     private static void testConnect(int port, int rmiPort) throws Exception {
+        EOFException lastException = null;
+        // factor adjusted timeout (5 seconds) for the RMI to become available
+        long timeout = System.currentTimeMillis() + Utils.adjustTimeout(5000);
+        do {
+            try {
+                doTestConnect(port, rmiPort);
+                lastException = null;
+            } catch (EOFException e) {
+                lastException = e;
+                System.out.println("Error establishing RMI connection. Retrying in 500ms.");
+                Thread.sleep(500);
+            }
+        } while (lastException != null && System.currentTimeMillis() < timeout);
 
+        if (lastException != null) {
+            // didn't manage to get the RMI running in time
+            // rethrow the exception
+            throw lastException;
+        }
+    }
+
+    private static void doTestConnect(int port, int rmiPort) throws Exception {
         dbg_print("RmiRegistry lookup...");
 
         dbg_print("Using port: " + port);