jdk/test/javax/net/ssl/SSLSession/SessionTimeOutTests.java
author sundar
Mon, 16 May 2016 14:50:43 +0530
changeset 37951 ce2744a0f1a7
parent 35240 08f593b14d4f
child 43300 0ee82282214b
permissions -rw-r--r--
8156914: jlink API minor cleanups Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
35240
08f593b14d4f 8146669: Test SessionTimeOutTests fails intermittently
xuelei
parents: 34387
diff changeset
     2
 * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
    24
// SunJSSE does not support dynamic system properties, no way to re-use
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
    25
// system properties in samevm/agentvm mode.
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
    26
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @bug   4366807
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @summary Need new APIs to get/set session timeout and session cache size.
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    31
 * @run main/othervm SessionTimeOutTests
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.*;
34387
92a5f8d50d1a 8144313: Test SessionTimeOutTests can be timeout
xuelei
parents: 23052
diff changeset
    39
import java.util.concurrent.atomic.AtomicInteger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Session reuse time-out tests cover the cases below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * 1. general test, i.e timeout is set to x and session invalidates when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * its lifetime exceeds x.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * 2. Effect of changing the timeout limit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * The test suite does not cover the default timeout(24 hours) usage. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * case has been tested independetly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Invairant for passing this test is, at any given time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * lifetime of a session < current_session_timeout, such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * current_session_timeout > 0, for all sessions cached by the session
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class SessionTimeOutTests {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * =============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Set the various variables needed for the tests, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * specify what tests to run on each side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * Should we run the client or server in a separate thread?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Both sides can throw exceptions, but do you have a preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * as to which side should be the main thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    static boolean separateServerThread = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Where do we find the keystores?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
23052
241885315119 8032473: Restructure JSSE regression test hierarchy in jdk test
xuelei
parents: 19575
diff changeset
    73
    static String pathToStores = "../etc";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    static String keyStoreFile = "keystore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    static String trustStoreFile = "truststore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    static String passwd = "passphrase";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static int PORTS = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Is the server ready to serve?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
34387
92a5f8d50d1a 8144313: Test SessionTimeOutTests can be timeout
xuelei
parents: 23052
diff changeset
    83
    AtomicInteger serverReady = new AtomicInteger(PORTS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Turn on SSL debugging?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    static boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * If the client or server is doing some kind of object creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * that the other side depends on, and that thread prematurely
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * exits, you may experience a hang.  The test harness will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * terminate all hung threads after its timeout has expired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * currently 3 minutes by default, but you might try to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * smart about it....
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Define the server side of the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
34387
92a5f8d50d1a 8144313: Test SessionTimeOutTests can be timeout
xuelei
parents: 23052
diff changeset
   102
     * If the server prematurely exits, serverReady will be set to zero
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * to avoid infinite hangs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * A limit on the number of connections at any given time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    static int MAX_ACTIVE_CONNECTIONS = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    void doServerSide(int serverPort, int serverConns) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        SSLServerSocket sslServerSocket =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            (SSLServerSocket) sslssf.createServerSocket(serverPort);
35240
08f593b14d4f 8146669: Test SessionTimeOutTests fails intermittently
xuelei
parents: 34387
diff changeset
   115
        int slot = createdPorts.getAndIncrement();
08f593b14d4f 8146669: Test SessionTimeOutTests fails intermittently
xuelei
parents: 34387
diff changeset
   116
        serverPorts[slot] = sslServerSocket.getLocalPort();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
         * Signal Client, we're ready for his connect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         */
34387
92a5f8d50d1a 8144313: Test SessionTimeOutTests can be timeout
xuelei
parents: 23052
diff changeset
   121
        serverReady.getAndDecrement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        int read = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        int nConnections = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        SSLSession sessions [] = new SSLSession [serverConns];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        while (nConnections < serverConns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            InputStream sslIS = sslSocket.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            OutputStream sslOS = sslSocket.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            read = sslIS.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            sessions[nConnections] = sslSocket.getSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            sslOS.write(85);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            sslOS.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            sslSocket.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            nConnections++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Define the client side of the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
34387
92a5f8d50d1a 8144313: Test SessionTimeOutTests can be timeout
xuelei
parents: 23052
diff changeset
   142
     * If the server prematurely exits, serverReady will be set to zero
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * to avoid infinite hangs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    void doClientSide() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         * Wait for server to get started.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         */
34387
92a5f8d50d1a 8144313: Test SessionTimeOutTests can be timeout
xuelei
parents: 23052
diff changeset
   150
        while (serverReady.get() > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            Thread.sleep(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        int nConnections = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        SSLSocket sslSockets[] = new SSLSocket [MAX_ACTIVE_CONNECTIONS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        Vector sessions = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        SSLSessionContext sessCtx = sslctx.getClientSessionContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        sessCtx.setSessionTimeout(10); // in secs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        int timeout = sessCtx.getSessionTimeout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        while (nConnections < MAX_ACTIVE_CONNECTIONS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            // divide the connections among the available server ports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            sslSockets[nConnections] = (SSLSocket) sslsf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                        createSocket("localhost",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                        serverPorts [nConnections % (serverPorts.length)]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            InputStream sslIS = sslSockets[nConnections].getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            OutputStream sslOS = sslSockets[nConnections].getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            sslOS.write(237);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            sslOS.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            int read = sslIS.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            SSLSession sess = sslSockets[nConnections].getSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            if (!sessions.contains(sess))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                sessions.add(sess);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            nConnections++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        System.out.println("Current timeout is set to: " + timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        System.out.println("Testing SSLSessionContext.getSession()......");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        System.out.println("========================================"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                + "=======================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        System.out.println("Session                                 "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                + "Session-     Session");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        System.out.println("                                        "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                + "lifetime     timedout?");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        System.out.println("========================================"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                + "=======================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        for (int i = 0; i < sessions.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            SSLSession session = (SSLSession) sessions.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            long currentTime  = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            long creationTime = session.getCreationTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            long lifetime = (currentTime - creationTime) / 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            System.out.print(session + "      " + lifetime + "            ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            if (sessCtx.getSession(session.getId()) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                if (lifetime < timeout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    // sessions can be garbage collected before the timeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    // limit is reached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    System.out.println("Invalidated before timeout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    System.out.println("YES");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                System.out.println("NO");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                if ((timeout != 0) && (lifetime > timeout)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    throw new Exception("Session timeout test failed for the"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                        + " obove session");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            // change the timeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            if (i == ((sessions.size()) / 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                sessCtx.setSessionTimeout(2); // in secs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                timeout = sessCtx.getSessionTimeout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                System.out.println("timeout is changed to: " + timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                System.out.println();
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
   216
           }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        // check the ids returned by the enumerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        Enumeration e = sessCtx.getIds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        System.out.println("----------------------------------------"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                + "-----------------------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        System.out.println("Testing SSLSessionContext.getId()......");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        SSLSession nextSess = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        SSLSession sess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        for (int i = 0; i < sessions.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            sess = (SSLSession)sessions.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            String isTimedout = "YES";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            long currentTime  = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            long creationTime  = sess.getCreationTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            long lifetime = (currentTime - creationTime) / 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            if (nextSess != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                if (isEqualSessionId(nextSess.getId(), sess.getId())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    isTimedout = "NO";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    nextSess = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            } else if (e.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                nextSess = sessCtx.getSession((byte[]) e.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                if ((nextSess != null) && isEqualSessionId(nextSess.getId(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                        sess.getId())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    nextSess = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    isTimedout = "NO";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
             * A session not invalidated even after it's timeout?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if ((timeout != 0) && (lifetime > timeout) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                        (isTimedout.equals("NO"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                throw new Exception("Session timeout test failed for session: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                + sess + " lifetime: " + lifetime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            System.out.print(sess + "      " + lifetime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            if (((timeout == 0) || (lifetime < timeout)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                  (isTimedout == "YES")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                isTimedout = "Invalidated before timeout";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            System.out.println("            " + isTimedout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        for (int i = 0; i < nConnections; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            sslSockets[i].close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   268
        System.out.println("----------------------------------------"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                                 + "-----------------------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        System.out.println("Session timeout test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    boolean isEqualSessionId(byte[] id1, byte[] id2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (id1.length != id2.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
           return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            for (int i = 0; i < id1.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                if (id1[i] != id2[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                   return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * =============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * The remainder is just support stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
35240
08f593b14d4f 8146669: Test SessionTimeOutTests fails intermittently
xuelei
parents: 34387
diff changeset
   292
    int serverPorts[] = new int[PORTS];
08f593b14d4f 8146669: Test SessionTimeOutTests fails intermittently
xuelei
parents: 34387
diff changeset
   293
    AtomicInteger createdPorts = new AtomicInteger(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    static SSLServerSocketFactory sslssf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    static SSLSocketFactory sslsf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    static SSLContext sslctx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    volatile Exception serverException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    volatile Exception clientException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        String keyFilename =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            System.getProperty("test.src", "./") + "/" + pathToStores +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                "/" + keyStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        String trustFilename =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            System.getProperty("test.src", "./") + "/" + pathToStores +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                "/" + trustStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        System.setProperty("javax.net.ssl.keyStore", keyFilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        System.setProperty("javax.net.ssl.keyStorePassword", passwd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        System.setProperty("javax.net.ssl.trustStore", trustFilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        System.setProperty("javax.net.ssl.trustStorePassword", passwd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        sslctx = SSLContext.getInstance("TLS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        KeyStore ks = KeyStore.getInstance("JKS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        ks.load(new FileInputStream(keyFilename), passwd.toCharArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        kmf.init(ks, passwd.toCharArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        sslctx.init(kmf.getKeyManagers(), null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        sslssf = (SSLServerSocketFactory) sslctx.getServerSocketFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        sslsf = (SSLSocketFactory) sslctx.getSocketFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if (debug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            System.setProperty("javax.net.debug", "all");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
         * Start the tests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        new SessionTimeOutTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    Thread clientThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    Thread serverThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Primary constructor, used to drive remainder of the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * Fork off the other side, then do your work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    SessionTimeOutTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
         * create the SSLServerSocket and SSLSocket factories
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         * Divide the max connections among the available server ports.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         * The use of more than one server port ensures creation of more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         * than one session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        int serverConns = MAX_ACTIVE_CONNECTIONS / (serverPorts.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        int remainingConns = MAX_ACTIVE_CONNECTIONS % (serverPorts.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   353
        Exception startException = null;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   354
        try {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   355
            if (separateServerThread) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   356
                for (int i = 0; i < serverPorts.length; i++) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   357
                    // distribute remaining connections among the
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   358
                    // vailable ports
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   359
                    if (i < remainingConns)
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   360
                        startServer(serverPorts[i], (serverConns + 1), true);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   361
                    else
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   362
                        startServer(serverPorts[i], serverConns, true);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   363
                }
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   364
                startClient(false);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   365
            } else {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   366
                startClient(true);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   367
                for (int i = 0; i < serverPorts.length; i++) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   368
                    if (i < remainingConns)
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   369
                        startServer(serverPorts[i], (serverConns + 1), false);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   370
                    else
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   371
                        startServer(serverPorts[i], serverConns, false);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   372
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   374
        } catch (Exception e) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   375
            startException = e;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
         * Wait for other side to close down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (separateServerThread) {
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   382
            if (serverThread != null) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   383
                serverThread.join();
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   384
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        } else {
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   386
            if (clientThread != null) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   387
                clientThread.join();
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   388
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
         * When we get here, the test is pretty much over.
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   393
         * Which side threw the error?
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   394
         */
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   395
        Exception local;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   396
        Exception remote;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   397
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   398
        if (separateServerThread) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   399
            remote = serverException;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   400
            local = clientException;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   401
        } else {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   402
            remote = clientException;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   403
            local = serverException;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   404
        }
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   405
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   406
        Exception exception = null;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   407
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   408
        /*
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   409
         * Check various exception conditions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
         */
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   411
        if ((local != null) && (remote != null)) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   412
            // If both failed, return the curthread's exception.
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   413
            local.initCause(remote);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   414
            exception = local;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   415
        } else if (local != null) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   416
            exception = local;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   417
        } else if (remote != null) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   418
            exception = remote;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   419
        } else if (startException != null) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   420
            exception = startException;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   421
        }
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   422
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   423
        /*
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   424
         * If there was an exception *AND* a startException,
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   425
         * output it.
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   426
         */
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   427
        if (exception != null) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   428
            if (exception != startException && startException != null) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   429
                exception.addSuppressed(startException);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   430
            }
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   431
            throw exception;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   432
        }
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   433
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   434
        // Fall-through: no exception to throw!
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    void startServer(final int port, final int nConns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                        boolean newThread) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        if (newThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            serverThread = new Thread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                        doServerSide(port, nConns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                         * Our server thread just died.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                         * Release the client, if not active already...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                        System.err.println("Server died...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                        e.printStackTrace();
34387
92a5f8d50d1a 8144313: Test SessionTimeOutTests can be timeout
xuelei
parents: 23052
diff changeset
   452
                        serverReady.set(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                        serverException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            serverThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        } else {
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   459
            try {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   460
                doServerSide(port, nConns);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   461
            } catch (Exception e) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   462
                serverException = e;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   463
            } finally {
34387
92a5f8d50d1a 8144313: Test SessionTimeOutTests can be timeout
xuelei
parents: 23052
diff changeset
   464
                serverReady.set(0);
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   465
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    void startClient(boolean newThread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                 throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        if (newThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            clientThread = new Thread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                        doClientSide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                         * Our client thread just died.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                        System.err.println("Client died...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                        clientException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            clientThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        } else {
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   487
            try {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   488
                doClientSide();
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   489
            } catch (Exception e) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   490
                clientException = e;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   491
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
}