test/jdk/com/sun/jndi/ldap/DeadSSLLdapTimeoutTest.java
author xuelei
Mon, 25 Jun 2018 13:41:39 -0700
changeset 50768 68fa3d4026ea
parent 47216 71c04702a3d5
permissions -rw-r--r--
8196584: TLS 1.3 Implementation Reviewed-by: ascarpino, coffeys, dfuchs, jjiang, jnimeh, mullan, rhalade, ssahoo, valeriep, weijun, wetmore, xuelei Contributed-by: Adam Petcher <adam.petcher@oracle.com>, Amanda Jiang <amanda.jiang@oracle.com>, Anthony Scarpino <anthony.scarpino@oracle.com>, Bradford Wetmore <bradford.wetmore@oracle.com>, Jamil Nimeh <jamil.j.nimeh@oracle.com>, John Jiang <sha.jiang@oracle.com>, Rajan Halade <rajan.halade@oracle.com>, Sibabrata Sahoo <sibabrata.sahoo@oracle.com>, Valerie Peng <valerie.peng@oracle.com>, Weijun Wang <weijun.wang@oracle.com>, Xuelei Fan <xuelei.fan@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34531
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
     1
/*
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 47216
diff changeset
     2
 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
34531
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
     4
 *
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
     8
 *
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    13
 * accompanied this code).
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    14
 *
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    18
 *
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    21
 * questions.
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    22
 */
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    23
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    24
/**
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    25
 * @test
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    26
 * @run main/othervm DeadSSLLdapTimeoutTest
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    27
 * @bug 8141370
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    28
 * @key intermittent
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    29
 */
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    30
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    31
import java.net.Socket;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    32
import java.net.ServerSocket;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    33
import java.net.SocketTimeoutException;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    34
import java.io.*;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    35
import javax.naming.*;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    36
import javax.naming.directory.*;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    37
import java.util.List;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    38
import java.util.Hashtable;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    39
import java.util.ArrayList;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    40
import java.util.concurrent.Callable;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    41
import java.util.concurrent.ExecutionException;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    42
import java.util.concurrent.Executors;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    43
import java.util.concurrent.ExecutorService;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    44
import java.util.concurrent.Future;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    45
import java.util.concurrent.ScheduledExecutorService;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    46
import java.util.concurrent.ScheduledFuture;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    47
import java.util.concurrent.TimeoutException;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    48
import java.util.concurrent.TimeUnit;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    49
import javax.net.ssl.SSLHandshakeException;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    50
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    51
import static java.util.concurrent.TimeUnit.MILLISECONDS;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    52
import static java.util.concurrent.TimeUnit.NANOSECONDS;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    53
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    54
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    55
class DeadServerTimeoutSSLTest implements Callable {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    56
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    57
    Hashtable env;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    58
    DeadSSLServer server;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    59
    boolean passed = false;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    60
    private int HANGING_TEST_TIMEOUT = 20_000;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    61
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    62
    public DeadServerTimeoutSSLTest(Hashtable env) throws IOException {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    63
        this.server = new DeadSSLServer();
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    64
        this.env = env;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    65
    }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    66
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    67
    public void performOp(InitialContext ctx) throws NamingException {}
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    68
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    69
    public void handleNamingException(NamingException e, long start, long end) {
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 47216
diff changeset
    70
        if (e.getCause() instanceof SocketTimeoutException
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 47216
diff changeset
    71
                || e.getCause().getCause() instanceof SocketTimeoutException) {
34531
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    72
            // SSL connect will timeout via readReply using
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    73
            // SocketTimeoutException
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    74
            e.printStackTrace();
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    75
            pass();
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    76
        } else if (e.getCause() instanceof SSLHandshakeException
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    77
                && e.getCause().getCause() instanceof EOFException) {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    78
            // test seems to be failing intermittently on some
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    79
            // platforms.
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    80
            pass();
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    81
        } else {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    82
            fail(e);
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    83
        }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    84
    }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    85
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    86
    public void pass() {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    87
        this.passed = true;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    88
    }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    89
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    90
    public void fail() {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    91
        throw new RuntimeException("Test failed");
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    92
    }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    93
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    94
    public void fail(Exception e) {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    95
        throw new RuntimeException("Test failed", e);
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    96
    }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    97
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    98
    boolean shutItDown(InitialContext ctx) {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
    99
        try {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   100
            if (ctx != null) ctx.close();
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   101
            return true;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   102
        } catch (NamingException ex) {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   103
            return false;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   104
        }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   105
    }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   106
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   107
    public Boolean call() {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   108
        InitialContext ctx = null;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   109
        ScheduledFuture killer = null;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   110
        long start = System.nanoTime();
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   111
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   112
        try {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   113
            while(!server.accepting())
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   114
                Thread.sleep(200); // allow the server to start up
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   115
            Thread.sleep(200); // to be sure
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   116
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   117
            env.put(Context.PROVIDER_URL, "ldap://localhost:" +
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   118
                    server.getLocalPort());
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   119
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   120
            try {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   121
                ctx = new InitialDirContext(env);
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   122
                performOp(ctx);
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   123
                fail();
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   124
            } catch (NamingException e) {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   125
                long end = System.nanoTime();
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   126
                System.out.println(this.getClass().toString() + " - elapsed: "
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   127
                        + NANOSECONDS.toMillis(end - start));
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   128
                handleNamingException(e, start, end);
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   129
            } finally {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   130
                if (killer != null && !killer.isDone())
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   131
                    killer.cancel(true);
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   132
                shutItDown(ctx);
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   133
                server.close();
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   134
            }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   135
            return passed;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   136
        } catch (IOException|InterruptedException e) {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   137
            throw new RuntimeException(e);
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   138
        }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   139
    }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   140
}
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   141
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   142
class DeadSSLServer extends Thread {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   143
    ServerSocket serverSock;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   144
    boolean accepting = false;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   145
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   146
    public DeadSSLServer() throws IOException {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   147
        this.serverSock = new ServerSocket(0);
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   148
        start();
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   149
    }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   150
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   151
    public void run() {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   152
        while(true) {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   153
            try {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   154
                accepting = true;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   155
                Socket socket = serverSock.accept();
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   156
            } catch (Exception e) {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   157
                break;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   158
            }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   159
        }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   160
    }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   161
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   162
    public int getLocalPort() {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   163
        return serverSock.getLocalPort();
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   164
    }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   165
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   166
    public boolean accepting() {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   167
        return accepting;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   168
    }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   169
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   170
    public void close() throws IOException {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   171
        serverSock.close();
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   172
    }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   173
}
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   174
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   175
public class DeadSSLLdapTimeoutTest {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   176
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   177
    static Hashtable createEnv() {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   178
        Hashtable env = new Hashtable(11);
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   179
        env.put(Context.INITIAL_CONTEXT_FACTORY,
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   180
            "com.sun.jndi.ldap.LdapCtxFactory");
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   181
        return env;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   182
    }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   183
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   184
    public static void main(String[] args) throws Exception {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   185
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   186
        InitialContext ctx = null;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   187
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   188
        //
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   189
        // Running this test serially as it seems to tickle a problem
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   190
        // on older kernels
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   191
        //
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   192
        // run the DeadServerTest with connect / read timeouts set
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   193
        // and ssl enabled
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   194
        // this should exit with a SocketTimeoutException as the root cause
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   195
        // it should also use the connect timeout instead of the read timeout
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   196
        System.out.println("Running connect timeout test with 10ms connect timeout, 3000ms read timeout & SSL");
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   197
        Hashtable sslenv = createEnv();
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   198
        sslenv.put("com.sun.jndi.ldap.connect.timeout", "10");
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   199
        sslenv.put("com.sun.jndi.ldap.read.timeout", "3000");
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   200
        sslenv.put(Context.SECURITY_PROTOCOL, "ssl");
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   201
        boolean testFailed =
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   202
            (new DeadServerTimeoutSSLTest(sslenv).call()) ? false : true;
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   203
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   204
        if (testFailed) {
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   205
            throw new AssertionError("some tests failed");
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   206
        }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   207
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   208
    }
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   209
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   210
}
7f00d9e3e545 8141370: com/sun/jndi/ldap/LdapTimeoutTest.java failed intermittently
robm
parents:
diff changeset
   211