changeset 60531:f5588781b2e2

8251189: com/sun/jndi/ldap/LdapDnsProviderTest.java failed due to timeout Reviewed-by: dfuchs, vtewari
author aefimov
date Wed, 12 Aug 2020 12:01:52 +0100
parents 63b1fe3160fd
children 299d4c38c8b5
files test/jdk/com/sun/jndi/ldap/LdapDnsProviderTest.java
diffstat 1 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/com/sun/jndi/ldap/LdapDnsProviderTest.java	Wed Aug 12 11:45:18 2020 +0100
+++ b/test/jdk/com/sun/jndi/ldap/LdapDnsProviderTest.java	Wed Aug 12 12:01:52 2020 +0100
@@ -111,6 +111,13 @@
             env.put(Context.PROVIDER_URL, url);
         }
 
+        // Set JNDI LDAP connect timeout property. It helps to prevent
+        // initial bind operation from blocking in case of a local process
+        // listening on the port specified in the URL. With the property set,
+        // the bind operation will fail with timeout exception, and then it
+        // could be retried with another port number.
+        env.put("com.sun.jndi.ldap.connect.timeout", "1000");
+
         try {
             ctx = new InitialDirContext(env);
             SearchControls scl = new SearchControls();
@@ -119,8 +126,13 @@
                     "ou=People,o=Test", "(objectClass=*)", scl);
             throw new RuntimeException("Search should not complete");
         } catch (NamingException e) {
-            e.printStackTrace();
             passed = e.toString().contains(expected);
+            System.err.println((passed ? "Expected" : "Unexpected") +
+                    " NamingException observed: " + e.toString());
+            // Print stack trace only for unexpected exceptions
+            if (!passed) {
+                e.printStackTrace();
+            }
         } finally {
             shutItDown(ctx);
         }
@@ -243,7 +255,8 @@
             // Construct text expected to be present in Exception message
             String expected = "localhost:" + port;
 
-            System.err.printf("Iteration %d: Testing: %s, %s%n", attempt, url, expected);
+            System.err.printf("Iteration %d: Testing: url='%s', expected content='%s'%n",
+                    attempt, url, expected);
 
             FutureTask<Boolean> future = new FutureTask<>(
                     new ProviderTest(url, expected));
@@ -278,7 +291,7 @@
                     new ProviderTest(url, expected));
         new Thread(future).start();
 
-        System.err.println("Testing: " + url + ", " + expected);
+        System.err.printf("Testing: url='%s', expected content='%s'%n", url, expected);
         while (!future.isDone()) {
             try {
                 if (!future.get()) {