From 2f57e38d9545f9f6915a530ec9a6845b43e22983 Mon Sep 17 00:00:00 2001 From: prappo Date: Tue, 17 Jun 2014 13:57:01 +0100 Subject: [PATCH] 8047062: Improve diagnostic output in com/sun/jndi/ldap/LdapTimeoutTest.java Reviewed-by: vinnie --- .../classes/com/sun/jndi/ldap/Connection.java | 3 ++- test/com/sun/jndi/ldap/LdapTimeoutTest.java | 26 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/share/classes/com/sun/jndi/ldap/Connection.java b/src/share/classes/com/sun/jndi/ldap/Connection.java index d41c94480..c5a957ce6 100644 --- a/src/share/classes/com/sun/jndi/ldap/Connection.java +++ b/src/share/classes/com/sun/jndi/ldap/Connection.java @@ -111,6 +111,7 @@ public final class Connection implements Runnable { private static final boolean debug = false; private static final int dump = 0; // > 0 r, > 1 rw + public static final long DEFAULT_READ_TIMEOUT_MILLIS = 15 * 1000; // 15 second timeout; final private Thread worker; // Initialized in constructor @@ -460,7 +461,7 @@ public final class Connection implements Runnable { // available ldr.wait(readTimeout); } else { - ldr.wait(15 * 1000); // 15 second timeout + ldr.wait(DEFAULT_READ_TIMEOUT_MILLIS); } waited = true; } else { diff --git a/test/com/sun/jndi/ldap/LdapTimeoutTest.java b/test/com/sun/jndi/ldap/LdapTimeoutTest.java index 392703744..c5705bc4b 100644 --- a/test/com/sun/jndi/ldap/LdapTimeoutTest.java +++ b/test/com/sun/jndi/ldap/LdapTimeoutTest.java @@ -27,6 +27,8 @@ * @summary Timeout tests for ldap */ +import com.sun.jndi.ldap.Connection; + import java.net.Socket; import java.net.ServerSocket; import java.net.SocketTimeoutException; @@ -38,7 +40,9 @@ import java.util.concurrent.Callable; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; + +import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static java.util.concurrent.TimeUnit.NANOSECONDS; public class LdapTimeoutTest { private static final ScheduledExecutorService pool = @@ -85,7 +89,7 @@ public class LdapTimeoutTest { void ldapReadTimeoutTest(Hashtable env, boolean ssl) { InitialContext ctx = null; if (ssl) env.put(Context.SECURITY_PROTOCOL, "ssl"); - ScheduledFuture killer = killSwitch(5000); + ScheduledFuture killer = killSwitch(5_000); long start = System.nanoTime(); try { ctx = new InitialDirContext(env); @@ -113,7 +117,7 @@ public class LdapTimeoutTest { void simpleAuthConnectTest(Hashtable env) { InitialContext ctx = null; - ScheduledFuture killer = killSwitch(5000); + ScheduledFuture killer = killSwitch(5_000); long start = System.nanoTime(); try { ctx = new InitialDirContext(env); @@ -123,7 +127,7 @@ public class LdapTimeoutTest { } catch (NamingException e) { long end = System.nanoTime(); if (e.getCause() instanceof SocketTimeoutException) { - if (TimeUnit.NANOSECONDS.toMillis(end - start) < 2900) { + if (NANOSECONDS.toMillis(end - start) < 2_900) { pass(); } else { System.err.println("Fail: Waited too long"); @@ -142,7 +146,7 @@ public class LdapTimeoutTest { void deadServerNoTimeout(Hashtable env) { InitialContext ctx = null; - ScheduledFuture killer = killSwitch(30000); + ScheduledFuture killer = killSwitch(30_000); long start = System.nanoTime(); try { ctx = new InitialDirContext(env); @@ -154,9 +158,13 @@ public class LdapTimeoutTest { fail(); } catch (NamingException e) { long end = System.nanoTime(); - if (TimeUnit.NANOSECONDS.toMillis(end - start) < 14000) { - System.err.println("fail: timeout should be at least 15 seconds, actual time: " - + TimeUnit.NANOSECONDS.toMillis(end - start)); + long elapsed = NANOSECONDS.toMillis(end - start); + if (elapsed < Connection.DEFAULT_READ_TIMEOUT_MILLIS) { + System.err.printf( + "fail: timeout should be at least %s ms, actual time is %s ms", + Connection.DEFAULT_READ_TIMEOUT_MILLIS, + elapsed); + e.printStackTrace(); fail(); } else { pass(); @@ -184,7 +192,7 @@ public class LdapTimeoutTest { System.exit(0); return null; } - }, ms, TimeUnit.MILLISECONDS); + }, ms, MILLISECONDS); } static class Server extends Thread { -- GitLab