提交 2f57e38d 编写于 作者: P prappo

8047062: Improve diagnostic output in com/sun/jndi/ldap/LdapTimeoutTest.java

Reviewed-by: vinnie
上级 16bf7c27
...@@ -111,6 +111,7 @@ public final class Connection implements Runnable { ...@@ -111,6 +111,7 @@ public final class Connection implements Runnable {
private static final boolean debug = false; private static final boolean debug = false;
private static final int dump = 0; // > 0 r, > 1 rw 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 final private Thread worker; // Initialized in constructor
...@@ -460,7 +461,7 @@ public final class Connection implements Runnable { ...@@ -460,7 +461,7 @@ public final class Connection implements Runnable {
// available // available
ldr.wait(readTimeout); ldr.wait(readTimeout);
} else { } else {
ldr.wait(15 * 1000); // 15 second timeout ldr.wait(DEFAULT_READ_TIMEOUT_MILLIS);
} }
waited = true; waited = true;
} else { } else {
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
* @summary Timeout tests for ldap * @summary Timeout tests for ldap
*/ */
import com.sun.jndi.ldap.Connection;
import java.net.Socket; import java.net.Socket;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
...@@ -38,7 +40,9 @@ import java.util.concurrent.Callable; ...@@ -38,7 +40,9 @@ import java.util.concurrent.Callable;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture; 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 { public class LdapTimeoutTest {
private static final ScheduledExecutorService pool = private static final ScheduledExecutorService pool =
...@@ -85,7 +89,7 @@ public class LdapTimeoutTest { ...@@ -85,7 +89,7 @@ public class LdapTimeoutTest {
void ldapReadTimeoutTest(Hashtable env, boolean ssl) { void ldapReadTimeoutTest(Hashtable env, boolean ssl) {
InitialContext ctx = null; InitialContext ctx = null;
if (ssl) env.put(Context.SECURITY_PROTOCOL, "ssl"); if (ssl) env.put(Context.SECURITY_PROTOCOL, "ssl");
ScheduledFuture killer = killSwitch(5000); ScheduledFuture killer = killSwitch(5_000);
long start = System.nanoTime(); long start = System.nanoTime();
try { try {
ctx = new InitialDirContext(env); ctx = new InitialDirContext(env);
...@@ -113,7 +117,7 @@ public class LdapTimeoutTest { ...@@ -113,7 +117,7 @@ public class LdapTimeoutTest {
void simpleAuthConnectTest(Hashtable env) { void simpleAuthConnectTest(Hashtable env) {
InitialContext ctx = null; InitialContext ctx = null;
ScheduledFuture killer = killSwitch(5000); ScheduledFuture killer = killSwitch(5_000);
long start = System.nanoTime(); long start = System.nanoTime();
try { try {
ctx = new InitialDirContext(env); ctx = new InitialDirContext(env);
...@@ -123,7 +127,7 @@ public class LdapTimeoutTest { ...@@ -123,7 +127,7 @@ public class LdapTimeoutTest {
} catch (NamingException e) { } catch (NamingException e) {
long end = System.nanoTime(); long end = System.nanoTime();
if (e.getCause() instanceof SocketTimeoutException) { if (e.getCause() instanceof SocketTimeoutException) {
if (TimeUnit.NANOSECONDS.toMillis(end - start) < 2900) { if (NANOSECONDS.toMillis(end - start) < 2_900) {
pass(); pass();
} else { } else {
System.err.println("Fail: Waited too long"); System.err.println("Fail: Waited too long");
...@@ -142,7 +146,7 @@ public class LdapTimeoutTest { ...@@ -142,7 +146,7 @@ public class LdapTimeoutTest {
void deadServerNoTimeout(Hashtable env) { void deadServerNoTimeout(Hashtable env) {
InitialContext ctx = null; InitialContext ctx = null;
ScheduledFuture killer = killSwitch(30000); ScheduledFuture killer = killSwitch(30_000);
long start = System.nanoTime(); long start = System.nanoTime();
try { try {
ctx = new InitialDirContext(env); ctx = new InitialDirContext(env);
...@@ -154,9 +158,13 @@ public class LdapTimeoutTest { ...@@ -154,9 +158,13 @@ public class LdapTimeoutTest {
fail(); fail();
} catch (NamingException e) { } catch (NamingException e) {
long end = System.nanoTime(); long end = System.nanoTime();
if (TimeUnit.NANOSECONDS.toMillis(end - start) < 14000) { long elapsed = NANOSECONDS.toMillis(end - start);
System.err.println("fail: timeout should be at least 15 seconds, actual time: " if (elapsed < Connection.DEFAULT_READ_TIMEOUT_MILLIS) {
+ TimeUnit.NANOSECONDS.toMillis(end - start)); 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(); fail();
} else { } else {
pass(); pass();
...@@ -184,7 +192,7 @@ public class LdapTimeoutTest { ...@@ -184,7 +192,7 @@ public class LdapTimeoutTest {
System.exit(0); System.exit(0);
return null; return null;
} }
}, ms, TimeUnit.MILLISECONDS); }, ms, MILLISECONDS);
} }
static class Server extends Thread { static class Server extends Thread {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册