test/com/sun/jndi/ldap/LdapTimeoutTest.java

Print this page
rev 10092 : 8046768: com/sun/jndi/ldap/LdapTimeoutTest.java fails intermittently
Summary: Added diagnostic printStackTrace() for NamingException
Reviewed-by: duke

*** 25,34 **** --- 25,36 ---- * @test * @bug 7094377 8000487 6176036 7056489 * @summary Timeout tests for ldap */ + import com.sun.jndi.ldap.Connection; + import java.net.Socket; import java.net.ServerSocket; import java.net.SocketTimeoutException; import java.io.*; import javax.naming.*;
*** 36,46 **** import java.util.Hashtable; 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; public class LdapTimeoutTest { private static final ScheduledExecutorService pool = Executors.newScheduledThreadPool(1); static volatile int passed = 0, failed = 0; --- 38,50 ---- import java.util.Hashtable; import java.util.concurrent.Callable; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; ! ! import static java.util.concurrent.TimeUnit.MILLISECONDS; ! import static java.util.concurrent.TimeUnit.NANOSECONDS; public class LdapTimeoutTest { private static final ScheduledExecutorService pool = Executors.newScheduledThreadPool(1); static volatile int passed = 0, failed = 0;
*** 83,93 **** } void ldapReadTimeoutTest(Hashtable env, boolean ssl) { InitialContext ctx = null; if (ssl) env.put(Context.SECURITY_PROTOCOL, "ssl"); ! ScheduledFuture killer = killSwitch(5000); long start = System.nanoTime(); try { ctx = new InitialDirContext(env); SearchControls scl = new SearchControls(); scl.setSearchScope(SearchControls.SUBTREE_SCOPE); --- 87,97 ---- } void ldapReadTimeoutTest(Hashtable env, boolean ssl) { InitialContext ctx = null; if (ssl) env.put(Context.SECURITY_PROTOCOL, "ssl"); ! ScheduledFuture killer = killSwitch(5_000); long start = System.nanoTime(); try { ctx = new InitialDirContext(env); SearchControls scl = new SearchControls(); scl.setSearchScope(SearchControls.SUBTREE_SCOPE);
*** 111,131 **** } } void simpleAuthConnectTest(Hashtable env) { InitialContext ctx = null; ! ScheduledFuture killer = killSwitch(5000); long start = System.nanoTime(); try { ctx = new InitialDirContext(env); // shouldn't reach here System.err.println("Fail: InitialDirContext succeeded"); fail(); } catch (NamingException e) { long end = System.nanoTime(); if (e.getCause() instanceof SocketTimeoutException) { ! if (TimeUnit.NANOSECONDS.toMillis(end - start) < 2900) { pass(); } else { System.err.println("Fail: Waited too long"); fail(); } --- 115,135 ---- } } void simpleAuthConnectTest(Hashtable env) { InitialContext ctx = null; ! ScheduledFuture killer = killSwitch(5_000); long start = System.nanoTime(); try { ctx = new InitialDirContext(env); // shouldn't reach here System.err.println("Fail: InitialDirContext succeeded"); fail(); } catch (NamingException e) { long end = System.nanoTime(); if (e.getCause() instanceof SocketTimeoutException) { ! if (NANOSECONDS.toMillis(end - start) < 2_900) { pass(); } else { System.err.println("Fail: Waited too long"); fail(); }
*** 140,150 **** } } void deadServerNoTimeout(Hashtable env) { InitialContext ctx = null; ! ScheduledFuture killer = killSwitch(30000); long start = System.nanoTime(); try { ctx = new InitialDirContext(env); SearchControls scl = new SearchControls(); scl.setSearchScope(SearchControls.SUBTREE_SCOPE); --- 144,154 ---- } } void deadServerNoTimeout(Hashtable env) { InitialContext ctx = null; ! ScheduledFuture killer = killSwitch(30_000); long start = System.nanoTime(); try { ctx = new InitialDirContext(env); SearchControls scl = new SearchControls(); scl.setSearchScope(SearchControls.SUBTREE_SCOPE);
*** 152,164 **** .search("ou=People,o=JNDITutorial", "(objectClass=*)", scl); // shouldn't reach here 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)); fail(); } else { pass(); } } finally { --- 156,172 ---- .search("ou=People,o=JNDITutorial", "(objectClass=*)", scl); // shouldn't reach here fail(); } catch (NamingException e) { long end = System.nanoTime(); ! 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(); } } finally {
*** 182,192 **** public Void call() throws Exception { System.err.println("Fail: killSwitch()"); System.exit(0); return null; } ! }, ms, TimeUnit.MILLISECONDS); } static class Server extends Thread { final ServerSocket serverSock; --- 190,200 ---- public Void call() throws Exception { System.err.println("Fail: killSwitch()"); System.exit(0); return null; } ! }, ms, MILLISECONDS); } static class Server extends Thread { final ServerSocket serverSock;