test/jdk/com/sun/jndi/ldap/LdapTimeoutTest.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 36004 jdk/test/com/sun/jndi/ldap/LdapTimeoutTest.java@91d5f006921d
child 58126 1def54255e93
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
     1
/*
36004
91d5f006921d 8149920: Remove intermittent key from jdk_core tests
amlu
parents: 34531
diff changeset
     2
 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
     4
 *
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
     8
 *
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    13
 * accompanied this code).
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    14
 *
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    18
 *
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    21
 * questions.
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    22
 */
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    23
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    24
/**
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    25
 * @test
25411
b827000aa99a 8049884: Reduce possible timing noise in com/sun/jndi/ldap/LdapTimeoutTest.java
prappo
parents: 25406
diff changeset
    26
 * @run main/othervm LdapTimeoutTest
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    27
 * @bug 7094377 8000487 6176036 7056489
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    28
 * @summary Timeout tests for ldap
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    29
 */
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    30
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    31
import java.net.Socket;
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    32
import java.net.ServerSocket;
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    33
import java.net.SocketTimeoutException;
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    34
import java.io.*;
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    35
import javax.naming.*;
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    36
import javax.naming.directory.*;
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    37
import java.util.List;
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    38
import java.util.Hashtable;
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    39
import java.util.ArrayList;
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    40
import java.util.concurrent.Callable;
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    41
import java.util.concurrent.ExecutionException;
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    42
import java.util.concurrent.Executors;
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    43
import java.util.concurrent.ExecutorService;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    44
import java.util.concurrent.Future;
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    45
import java.util.concurrent.ScheduledExecutorService;
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    46
import java.util.concurrent.ScheduledFuture;
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    47
import java.util.concurrent.TimeoutException;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    48
import java.util.concurrent.TimeUnit;
33676
7350cdfdf5ac 8132455: com/sun/jndi/ldap/LdapTimeoutTest.java fails at handleNamingException
robm
parents: 32771
diff changeset
    49
import javax.net.ssl.SSLHandshakeException;
25406
4814eec6a323 8047062: Improve diagnostic output in com/sun/jndi/ldap/LdapTimeoutTest.java
prappo
parents: 24519
diff changeset
    50
4814eec6a323 8047062: Improve diagnostic output in com/sun/jndi/ldap/LdapTimeoutTest.java
prappo
parents: 24519
diff changeset
    51
import static java.util.concurrent.TimeUnit.MILLISECONDS;
4814eec6a323 8047062: Improve diagnostic output in com/sun/jndi/ldap/LdapTimeoutTest.java
prappo
parents: 24519
diff changeset
    52
import static java.util.concurrent.TimeUnit.NANOSECONDS;
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    53
27486
3549217e0897 8059311: com/sun/jndi/ldap/LdapTimeoutTest.java fails with exit_code == 0
prappo
parents: 25411
diff changeset
    54
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    55
abstract class LdapTest implements Callable {
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    56
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    57
    Hashtable env;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    58
    TestServer server;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    59
    ScheduledExecutorService killSwitchPool;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    60
    boolean passed = false;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    61
    private int HANGING_TEST_TIMEOUT = 20_000;
24519
2fab99d91c4d 8042857: 14 stuck threads waiting for notification on LDAPRequest
robm
parents: 14342
diff changeset
    62
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    63
    public LdapTest (TestServer server, Hashtable env) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    64
        this.server = server;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    65
        this.env = env;
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    66
    }
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    67
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    68
    public LdapTest(TestServer server, Hashtable env,
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    69
            ScheduledExecutorService killSwitchPool)
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    70
    {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    71
        this(server, env);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    72
        this.killSwitchPool = killSwitchPool;
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    73
    }
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    74
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    75
    public abstract void performOp(InitialContext ctx) throws NamingException;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    76
    public abstract void handleNamingException(
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    77
        NamingException e, long start, long end);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    78
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    79
    public void pass() {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    80
        this.passed = true;
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    81
    }
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    82
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    83
    public void fail() {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
    84
        throw new RuntimeException("Test failed");
24519
2fab99d91c4d 8042857: 14 stuck threads waiting for notification on LDAPRequest
robm
parents: 14342
diff changeset
    85
    }
2fab99d91c4d 8042857: 14 stuck threads waiting for notification on LDAPRequest
robm
parents: 14342
diff changeset
    86
32272
107a28901a7b 8046768: com/sun/jndi/ldap/LdapTimeoutTest.java fails intermittently
robm
parents: 29528
diff changeset
    87
    public void fail(Exception e) {
107a28901a7b 8046768: com/sun/jndi/ldap/LdapTimeoutTest.java fails intermittently
robm
parents: 29528
diff changeset
    88
        throw new RuntimeException("Test failed", e);
107a28901a7b 8046768: com/sun/jndi/ldap/LdapTimeoutTest.java fails intermittently
robm
parents: 29528
diff changeset
    89
    }
107a28901a7b 8046768: com/sun/jndi/ldap/LdapTimeoutTest.java fails intermittently
robm
parents: 29528
diff changeset
    90
27486
3549217e0897 8059311: com/sun/jndi/ldap/LdapTimeoutTest.java fails with exit_code == 0
prappo
parents: 25411
diff changeset
    91
    boolean shutItDown(InitialContext ctx) {
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    92
        try {
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    93
            if (ctx != null) ctx.close();
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    94
            return true;
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    95
        } catch (NamingException ex) {
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    96
            return false;
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    97
        }
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    98
    }
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
    99
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   100
    public Boolean call() {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   101
        InitialContext ctx = null;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   102
        ScheduledFuture killer = null;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   103
        long start = System.nanoTime();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   104
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   105
        try {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   106
            while(!server.accepting())
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   107
                Thread.sleep(200); // allow the server to start up
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   108
            Thread.sleep(200); // to be sure
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
   109
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   110
            // if this is a hanging test, scheduled a thread to
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   111
            // interrupt after a certain time
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   112
            if (killSwitchPool != null) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   113
                final Thread current = Thread.currentThread();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   114
                killer = killSwitchPool.schedule(
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   115
                    new Callable<Void>() {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   116
                        public Void call() throws Exception {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   117
                            current.interrupt();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   118
                            return null;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   119
                        }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   120
                    }, HANGING_TEST_TIMEOUT, MILLISECONDS);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   121
            }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   122
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   123
            env.put(Context.PROVIDER_URL, "ldap://localhost:" +
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   124
                    server.getLocalPort());
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   125
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   126
            try {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   127
                ctx = new InitialDirContext(env);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   128
                performOp(ctx);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   129
                fail();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   130
            } catch (NamingException e) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   131
                long end = System.nanoTime();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   132
                System.out.println(this.getClass().toString() + " - elapsed: "
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   133
                        + NANOSECONDS.toMillis(end - start));
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   134
                handleNamingException(e, start, end);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   135
            } finally {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   136
                if (killer != null && !killer.isDone())
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   137
                    killer.cancel(true);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   138
                shutItDown(ctx);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   139
                server.close();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   140
            }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   141
            return passed;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   142
        } catch (IOException|InterruptedException e) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   143
            throw new RuntimeException(e);
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
   144
        }
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   145
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   146
}
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
   147
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   148
abstract class ReadServerTest extends LdapTest {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   149
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   150
    public ReadServerTest(Hashtable env) throws IOException {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   151
        super(new BindableServer(), env);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   152
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   153
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   154
    public ReadServerTest(Hashtable env,
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   155
                          ScheduledExecutorService killSwitchPool)
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   156
            throws IOException
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   157
    {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   158
        super(new BindableServer(), env, killSwitchPool);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   159
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   160
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   161
    public void performOp(InitialContext ctx) throws NamingException {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   162
        SearchControls scl = new SearchControls();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   163
        scl.setSearchScope(SearchControls.SUBTREE_SCOPE);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   164
        NamingEnumeration<SearchResult> answer = ((InitialDirContext)ctx)
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   165
            .search("ou=People,o=JNDITutorial", "(objectClass=*)", scl);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   166
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   167
}
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   168
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   169
abstract class DeadServerTest extends LdapTest {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   170
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   171
    public DeadServerTest(Hashtable env) throws IOException {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   172
        super(new DeadServer(), env);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   173
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   174
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   175
    public DeadServerTest(Hashtable env,
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   176
                          ScheduledExecutorService killSwitchPool)
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   177
            throws IOException
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   178
    {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   179
        super(new DeadServer(), env, killSwitchPool);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   180
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   181
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   182
    public void performOp(InitialContext ctx) throws NamingException {}
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   183
}
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   184
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   185
class DeadServerNoTimeoutTest extends DeadServerTest {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   186
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   187
    public DeadServerNoTimeoutTest(Hashtable env,
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   188
                                   ScheduledExecutorService killSwitchPool)
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   189
            throws IOException
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   190
    {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   191
        super(env, killSwitchPool);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   192
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   193
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   194
    public void handleNamingException(NamingException e, long start, long end) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   195
        if (e instanceof InterruptedNamingException) Thread.interrupted();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   196
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   197
        if (NANOSECONDS.toMillis(end - start) < LdapTimeoutTest.MIN_TIMEOUT) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   198
            System.err.printf("DeadServerNoTimeoutTest fail: timeout should be " +
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   199
                              "at least %s ms, actual time is %s ms%n",
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   200
                              LdapTimeoutTest.MIN_TIMEOUT,
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   201
                              NANOSECONDS.toMillis(end - start));
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   202
            fail();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   203
        } else {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   204
            pass();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   205
        }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   206
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   207
}
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   208
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   209
class DeadServerTimeoutTest extends DeadServerTest {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   210
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   211
    public DeadServerTimeoutTest(Hashtable env) throws IOException {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   212
        super(env);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   213
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   214
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   215
    public void handleNamingException(NamingException e, long start, long end)
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   216
    {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   217
        // non SSL connect will timeout via readReply using connectTimeout
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   218
        if (NANOSECONDS.toMillis(end - start) < 2_900) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   219
            pass();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   220
        } else {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   221
            System.err.println("Fail: Waited too long");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   222
            fail();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   223
        }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   224
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   225
}
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   226
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   227
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   228
class ReadServerNoTimeoutTest extends ReadServerTest {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   229
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   230
    public ReadServerNoTimeoutTest(Hashtable env,
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   231
                                   ScheduledExecutorService killSwitchPool)
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   232
            throws IOException
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   233
    {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   234
        super(env, killSwitchPool);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   235
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   236
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   237
    public void handleNamingException(NamingException e, long start, long end) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   238
        if (e instanceof InterruptedNamingException) Thread.interrupted();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   239
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   240
        if (NANOSECONDS.toMillis(end - start) < LdapTimeoutTest.MIN_TIMEOUT) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   241
            System.err.printf("ReadServerNoTimeoutTest fail: timeout should be " +
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   242
                              "at least %s ms, actual time is %s ms%n",
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   243
                              LdapTimeoutTest.MIN_TIMEOUT,
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   244
                              NANOSECONDS.toMillis(end - start));
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   245
            fail();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   246
        } else {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   247
            pass();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   248
        }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   249
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   250
}
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   251
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   252
class ReadServerTimeoutTest extends ReadServerTest {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   253
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   254
    public ReadServerTimeoutTest(Hashtable env) throws IOException {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   255
        super(env);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   256
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   257
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   258
    public void handleNamingException(NamingException e, long start, long end) {
32272
107a28901a7b 8046768: com/sun/jndi/ldap/LdapTimeoutTest.java fails intermittently
robm
parents: 29528
diff changeset
   259
        System.out.println("ReadServerTimeoutTest: end-start=" + NANOSECONDS.toMillis(end - start));
107a28901a7b 8046768: com/sun/jndi/ldap/LdapTimeoutTest.java fails intermittently
robm
parents: 29528
diff changeset
   260
        if (NANOSECONDS.toMillis(end - start) < 2_500) {
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   261
            fail();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   262
        } else {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   263
            pass();
14184
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
   264
        }
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
   265
    }
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
   266
}
5553422ece67 8000487: Java JNDI connection library on ldap conn is not honoring configured timeout
robm
parents:
diff changeset
   267
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   268
class TestServer extends Thread {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   269
    ServerSocket serverSock;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   270
    boolean accepting = false;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   271
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   272
    public TestServer() throws IOException {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   273
        this.serverSock = new ServerSocket(0);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   274
        start();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   275
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   276
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   277
    public int getLocalPort() {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   278
        return serverSock.getLocalPort();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   279
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   280
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   281
    public boolean accepting() {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   282
        return accepting;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   283
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   284
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   285
    public void close() throws IOException {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   286
        serverSock.close();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   287
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   288
}
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   289
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   290
class BindableServer extends TestServer {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   291
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   292
    public BindableServer() throws IOException {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   293
        super();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   294
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   295
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   296
    private byte[] bindResponse = {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   297
        0x30, 0x0C, 0x02, 0x01, 0x01, 0x61, 0x07, 0x0A,
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   298
        0x01, 0x00, 0x04, 0x00, 0x04, 0x00
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   299
    };
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   300
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   301
    public void run() {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   302
        try {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   303
            accepting = true;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   304
            Socket socket = serverSock.accept();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   305
            InputStream in = socket.getInputStream();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   306
            OutputStream out = socket.getOutputStream();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   307
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   308
            // Read the LDAP BindRequest
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   309
            while (in.read() != -1) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   310
                in.skip(in.available());
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   311
                break;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   312
            }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   313
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   314
            // Write an LDAP BindResponse
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   315
            out.write(bindResponse);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   316
            out.flush();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   317
        } catch (IOException e) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   318
            // ignore
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   319
        }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   320
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   321
}
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   322
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   323
class DeadServer extends TestServer {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   324
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   325
    public DeadServer() throws IOException {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   326
        super();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   327
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   328
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   329
    public void run() {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   330
        while(true) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   331
            try {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   332
                accepting = true;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   333
                Socket socket = serverSock.accept();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   334
            } catch (Exception e) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   335
                break;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   336
            }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   337
        }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   338
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   339
}
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   340
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   341
public class LdapTimeoutTest {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   342
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   343
    private static final ExecutorService testPool =
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   344
        Executors.newFixedThreadPool(3);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   345
    private static final ScheduledExecutorService killSwitchPool =
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   346
        Executors.newScheduledThreadPool(3);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   347
    public static int MIN_TIMEOUT = 18_000;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   348
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   349
    static Hashtable createEnv() {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   350
        Hashtable env = new Hashtable(11);
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   351
        env.put(Context.INITIAL_CONTEXT_FACTORY,
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   352
            "com.sun.jndi.ldap.LdapCtxFactory");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   353
        return env;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   354
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   355
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   356
    public static void main(String[] args) throws Exception {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   357
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   358
        InitialContext ctx = null;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   359
        List<Future> results = new ArrayList<>();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   360
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   361
        try {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   362
            // run the DeadServerTest with no timeouts set
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   363
            // this should get stuck indefinitely, so we need to kill
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   364
            // it after a timeout
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   365
            System.out.println("Running connect timeout test with 20s kill switch");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   366
            Hashtable env = createEnv();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   367
            results.add(
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   368
                    testPool.submit(new DeadServerNoTimeoutTest(env, killSwitchPool)));
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   369
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   370
            // run the ReadServerTest with connect timeout set
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   371
            // this should get stuck indefinitely so we need to kill
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   372
            // it after a timeout
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   373
            System.out.println("Running read timeout test with 10ms connect timeout & 20s kill switch");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   374
            Hashtable env1 = createEnv();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   375
            env1.put("com.sun.jndi.ldap.connect.timeout", "10");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   376
            results.add(testPool.submit(
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   377
                    new ReadServerNoTimeoutTest(env1, killSwitchPool)));
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   378
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   379
            // run the ReadServerTest with no timeouts set
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   380
            // this should get stuck indefinitely, so we need to kill
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   381
            // it after a timeout
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   382
            System.out.println("Running read timeout test with 20s kill switch");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   383
            Hashtable env2 = createEnv();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   384
            results.add(testPool.submit(
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   385
                    new ReadServerNoTimeoutTest(env2, killSwitchPool)));
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   386
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   387
            // run the DeadServerTest with connect / read timeouts set
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   388
            // this should exit after the connect timeout expires
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   389
            System.out.println("Running connect timeout test with 10ms connect timeout, 3000ms read timeout");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   390
            Hashtable env3 = createEnv();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   391
            env3.put("com.sun.jndi.ldap.connect.timeout", "10");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   392
            env3.put("com.sun.jndi.ldap.read.timeout", "3000");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   393
            results.add(testPool.submit(new DeadServerTimeoutTest(env3)));
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   394
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   395
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   396
            // run the ReadServerTest with connect / read timeouts set
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   397
            // this should exit after the connect timeout expires
32771
732bf1c40a25 8135124: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents: 32272
diff changeset
   398
            //
732bf1c40a25 8135124: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents: 32272
diff changeset
   399
            // NOTE: commenting this test out as it is failing intermittently.
732bf1c40a25 8135124: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents: 32272
diff changeset
   400
            //
732bf1c40a25 8135124: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents: 32272
diff changeset
   401
            // System.out.println("Running read timeout test with 10ms connect timeout, 3000ms read timeout");
732bf1c40a25 8135124: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents: 32272
diff changeset
   402
            // Hashtable env4 = createEnv();
732bf1c40a25 8135124: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents: 32272
diff changeset
   403
            // env4.put("com.sun.jndi.ldap.connect.timeout", "10");
732bf1c40a25 8135124: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents: 32272
diff changeset
   404
            // env4.put("com.sun.jndi.ldap.read.timeout", "3000");
732bf1c40a25 8135124: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents: 32272
diff changeset
   405
            // results.add(testPool.submit(new ReadServerTimeoutTest(env4)));
27935
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   406
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   407
            // run the DeadServerTest with connect timeout set
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   408
            // this should exit after the connect timeout expires
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   409
            System.out.println("Running connect timeout test with 10ms connect timeout");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   410
            Hashtable env5 = createEnv();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   411
            env5.put("com.sun.jndi.ldap.connect.timeout", "10");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   412
            results.add(testPool.submit(new DeadServerTimeoutTest(env5)));
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   413
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   414
            // 8000487: Java JNDI connection library on ldap conn is
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   415
            // not honoring configured timeout
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   416
            System.out.println("Running simple auth connection test");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   417
            Hashtable env6 = createEnv();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   418
            env6.put("com.sun.jndi.ldap.connect.timeout", "10");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   419
            env6.put("com.sun.jndi.ldap.read.timeout", "3000");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   420
            env6.put(Context.SECURITY_AUTHENTICATION, "simple");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   421
            env6.put(Context.SECURITY_PRINCIPAL, "user");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   422
            env6.put(Context.SECURITY_CREDENTIALS, "password");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   423
            results.add(testPool.submit(new DeadServerTimeoutTest(env6)));
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   424
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   425
            boolean testFailed = false;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   426
            for (Future test : results) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   427
                while (!test.isDone()) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   428
                    if ((Boolean) test.get() == false)
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   429
                        testFailed = true;
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   430
                }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   431
            }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   432
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   433
            if (testFailed) {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   434
                throw new AssertionError("some tests failed");
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   435
            }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   436
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   437
        } finally {
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   438
            LdapTimeoutTest.killSwitchPool.shutdown();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   439
            LdapTimeoutTest.testPool.shutdown();
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   440
        }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   441
    }
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   442
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   443
}
80c148fb46c5 8065238: javax.naming.NamingException after upgrade to JDK 8
robm
parents: 27486
diff changeset
   444