8143121: javax/management/remote/mandatory/loading/MethodResultTest.java fails intermittently
authorakulyakh
Thu, 26 Nov 2015 15:12:32 +0300
changeset 34375 f90d70204e85
parent 34374 b45db1cff661
child 34376 e90592286aa0
8143121: javax/management/remote/mandatory/loading/MethodResultTest.java fails intermittently Summary: Changing the test to retry if the connection fails Reviewed-by: jbachorik
jdk/test/javax/management/remote/mandatory/loading/MethodResultTest.java
--- a/jdk/test/javax/management/remote/mandatory/loading/MethodResultTest.java	Tue Nov 24 12:18:25 2015 +0100
+++ b/jdk/test/javax/management/remote/mandatory/loading/MethodResultTest.java	Thu Nov 26 15:12:32 2015 +0300
@@ -27,6 +27,7 @@
  * @summary Tests client default class loader used before JSR 160 loader
  * @author Eamonn McManus
  * @modules java.management
+ * @library /lib/testlibrary
  * @run clean MethodResultTest
  * @run build MethodResultTest
  * @run main MethodResultTest
@@ -38,6 +39,7 @@
 import java.util.*;
 import javax.management.*;
 import javax.management.remote.*;
+import jdk.testlibrary.Utils;
 
 /*
    This test checks that the class loader that is used to deserialize
@@ -124,7 +126,7 @@
         }
         cs.start();
         JMXServiceURL addr = cs.getAddress();
-        JMXConnector client = JMXConnectorFactory.connect(addr);
+        JMXConnector client = connect(addr);
         MBeanServerConnection mbsc = client.getMBeanServerConnection();
         Object getAttributeExotic = mbsc.getAttribute(on, "Exotic");
         AttributeList getAttrs =
@@ -187,6 +189,32 @@
         return ok;
     }
 
+    private static JMXConnector connect(JMXServiceURL addr) {
+        final long timeout = Utils.adjustTimeout(100);
+
+        JMXConnector connector = null;
+        while (connector == null) {
+            try {
+                connector = JMXConnectorFactory.connect(addr);
+            } catch (IOException e) {
+                System.out.println("Connection error. Retrying after delay...");
+                delay(timeout);
+            } catch (Exception otherException) {
+                System.out.println("Unexpected exception while connecting " + otherException);
+                throw new RuntimeException(otherException);
+            }
+        }
+        return connector;
+    }
+
+    private static void delay(long ms) {
+        try {
+            Thread.sleep(ms);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     private static Exception noException(String what) {
         final String msg =
             "Operation " + what + " returned when exception expected";