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