jdk/test/javax/net/ssl/SSLSession/SessionCacheSizeTests.java
author amlu
Thu, 18 Feb 2016 09:46:07 +0800
changeset 36003 6519aa869709
parent 34948 9293584191b6
child 38952 ca428fb526d4
permissions -rw-r--r--
8149922: Remove intermittent key from security tests 8150047: Remove SSLSession/SessionCacheSizeTests from ProblemList Reviewed-by: xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
34948
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
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
//
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
    25
// 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
    26
// system properties in samevm/agentvm mode.
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
    27
//
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
    28
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @test
23743
92cae64be74e 8037557: test SessionCacheSizeTests.java timeout
xuelei
parents: 23052
diff changeset
    31
 * @bug 4366807
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @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
    33
 * @run main/othervm SessionCacheSizeTests
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Session cache size tests cover the following cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * 1. Effect of system property javax.net.ssl.SessionCacheSize (this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * property is not documented for public).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * 2. Reducing the cache size, results in uncaching of sessions if #of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * sessions present exceeds the new size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * 3. Increasing the cache size, results in accomodating  new sessions if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * number of cached sessions is the current size limit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Invairant for passing this test is, at any given time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * #cached_sessions <= current_cache_size , for current_cache_size > 0
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 SessionCacheSizeTests {
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
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Is the server ready to serve?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    volatile static boolean serverReady = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Turn on SSL debugging?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    static boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * If the client or server is doing some kind of object creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * that the other side depends on, and that thread prematurely
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * exits, you may experience a hang.  The test harness will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * terminate all hung threads after its timeout has expired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * currently 3 minutes by default, but you might try to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * smart about it....
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Define the server side of the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * If the server prematurely exits, serverReady will be set to true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * to avoid infinite hangs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * A limit on the number of connections at any given time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    static int MAX_ACTIVE_CONNECTIONS = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    void doServerSide(int serverPort, int serverConns) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
34948
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   111
        try (SSLServerSocket sslServerSocket =
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   112
                (SSLServerSocket) sslssf.createServerSocket(serverPort)) {
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   113
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   114
            // timeout to accept a connection
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   115
            sslServerSocket.setSoTimeout(45000);
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   116
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   117
            // make sure createdPorts++ is atomic
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   118
            synchronized(serverPorts) {
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   119
                serverPorts[createdPorts++] = sslServerSocket.getLocalPort();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
34948
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   121
                /*
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   122
                 * Signal Client, we're ready for his connect.
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   123
                 */
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   124
                if (createdPorts == serverPorts.length) {
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   125
                    serverReady = true;
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   126
                }
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   127
            }
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   128
            int read = 0;
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   129
            int nConnections = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
34948
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   131
            /*
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   132
             * Divide the max connections among the available server ports.
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   133
             * The use of more than one server port ensures creation of more
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   134
             * than one session.
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   135
             */
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   136
            SSLSession sessions [] = new SSLSession [serverConns];
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   137
            SSLSessionContext sessCtx = sslctx.getServerSessionContext();
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   138
23743
92cae64be74e 8037557: test SessionCacheSizeTests.java timeout
xuelei
parents: 23052
diff changeset
   139
            while (nConnections < serverConns) {
92cae64be74e 8037557: test SessionCacheSizeTests.java timeout
xuelei
parents: 23052
diff changeset
   140
                try (SSLSocket sslSocket =
92cae64be74e 8037557: test SessionCacheSizeTests.java timeout
xuelei
parents: 23052
diff changeset
   141
                        (SSLSocket)sslServerSocket.accept()) {
92cae64be74e 8037557: test SessionCacheSizeTests.java timeout
xuelei
parents: 23052
diff changeset
   142
                    sslSocket.setSoTimeout(90000);      // timeout to read
92cae64be74e 8037557: test SessionCacheSizeTests.java timeout
xuelei
parents: 23052
diff changeset
   143
                    InputStream sslIS = sslSocket.getInputStream();
92cae64be74e 8037557: test SessionCacheSizeTests.java timeout
xuelei
parents: 23052
diff changeset
   144
                    OutputStream sslOS = sslSocket.getOutputStream();
92cae64be74e 8037557: test SessionCacheSizeTests.java timeout
xuelei
parents: 23052
diff changeset
   145
                    read = sslIS.read();
92cae64be74e 8037557: test SessionCacheSizeTests.java timeout
xuelei
parents: 23052
diff changeset
   146
                    sessions[nConnections] = sslSocket.getSession();
92cae64be74e 8037557: test SessionCacheSizeTests.java timeout
xuelei
parents: 23052
diff changeset
   147
                    sslOS.write(85);
92cae64be74e 8037557: test SessionCacheSizeTests.java timeout
xuelei
parents: 23052
diff changeset
   148
                    sslOS.flush();
92cae64be74e 8037557: test SessionCacheSizeTests.java timeout
xuelei
parents: 23052
diff changeset
   149
                    nConnections++;
92cae64be74e 8037557: test SessionCacheSizeTests.java timeout
xuelei
parents: 23052
diff changeset
   150
                }
92cae64be74e 8037557: test SessionCacheSizeTests.java timeout
xuelei
parents: 23052
diff changeset
   151
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Define the client side of the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * If the server prematurely exits, serverReady will be set to true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * to avoid infinite hangs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    void doClientSide() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         * Wait for server to get started.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        while (!serverReady) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            Thread.sleep(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        int nConnections = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        SSLSocket sslSockets[] = new SSLSocket [MAX_ACTIVE_CONNECTIONS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        Vector sessions = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        SSLSessionContext sessCtx = sslctx.getClientSessionContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        sessCtx.setSessionTimeout(0); // no limit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        while (nConnections < (MAX_ACTIVE_CONNECTIONS - 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            // divide the connections among the available server ports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            sslSockets[nConnections] = (SSLSocket) sslsf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                        createSocket("localhost",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                        serverPorts [nConnections % (serverPorts.length)]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            InputStream sslIS = sslSockets[nConnections].getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            OutputStream sslOS = sslSockets[nConnections].getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            sslOS.write(237);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            sslOS.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            int read = sslIS.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            SSLSession sess = sslSockets[nConnections].getSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if (!sessions.contains(sess))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                sessions.add(sess);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            nConnections++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        System.out.println("Current cacheSize is set to: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                                 sessCtx.getSessionCacheSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        System.out.println("Currently cached Sessions......");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        System.out.println("============================================"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                                + "============================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        System.out.println("Session                                     "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                                + "      Session-last-accessTime");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        System.out.println("============================================"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                + "============================");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        checkCachedSessions(sessCtx, nConnections);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        // Change session cache size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        sessCtx.setSessionCacheSize(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        System.out.println("Session cache size changed to: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                        + sessCtx.getSessionCacheSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        checkCachedSessions(sessCtx, nConnections);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        // Test the effect of increasing the cache size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        sessCtx.setSessionCacheSize(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        System.out.println("Session cache size changed to: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                        + sessCtx.getSessionCacheSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        // create a new session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        sslSockets[nConnections] = (SSLSocket) sslsf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                        createSocket("localhost",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                        serverPorts [nConnections % (serverPorts.length)]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        InputStream sslIS = sslSockets[nConnections].getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        OutputStream sslOS = sslSockets[nConnections].getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        sslOS.write(237);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        sslOS.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        int read = sslIS.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        SSLSession sess = sslSockets[nConnections].getSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (!sessions.contains(sess))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            sessions.add(sess);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        nConnections++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        // test the number of sessions cached against the cache size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        checkCachedSessions(sessCtx, nConnections);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        for (int i = 0; i < nConnections; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            sslSockets[i].close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        System.out.println("Session cache size tests passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    void checkCachedSessions(SSLSessionContext sessCtx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                int nConn) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        int nSessions = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        Enumeration e = sessCtx.getIds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        int cacheSize = sessCtx.getSessionCacheSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        SSLSession sess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        while (e.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            sess = sessCtx.getSession((byte[]) e.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            long lastAccessedTime  = sess.getLastAccessedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                System.out.println(sess + "       "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                        +  new Date(lastAccessedTime));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            nSessions++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        System.out.println("--------------------------------------------"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                + "----------------------------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if ((cacheSize > 0) && (nSessions > cacheSize)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            // close all active connections before exiting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            for (int conn = nConn; conn < MAX_ACTIVE_CONNECTIONS; conn++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                SSLSocket s = (SSLSocket) sslsf.createSocket("localhost",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                        serverPorts [conn % (serverPorts.length)]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                s.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            throw new Exception("Session cache size test failed,"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                + " current cache size: " + cacheSize + " #sessions cached: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                + nSessions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * =============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * The remainder is just support stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * #of ports > 1, guarantees creation of more than one session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Using four ports (one per each connection), we are able to create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * alteast four sessions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
34948
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   277
    int serverPorts[] = new int[]{0, 0, 0, 0};  // MAX_ACTIVE_CONNECTIONS: 4
9293584191b6 8146387: Test SSLSession/SessionCacheSizeTests socket accept timed out
xuelei
parents: 34947
diff changeset
   278
    int createdPorts = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    static SSLServerSocketFactory sslssf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    static SSLSocketFactory sslsf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    static SSLContext sslctx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    volatile Exception serverException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    volatile Exception clientException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        String keyFilename =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            System.getProperty("test.src", "./") + "/" + pathToStores +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                "/" + keyStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        String trustFilename =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            System.getProperty("test.src", "./") + "/" + pathToStores +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                "/" + trustStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        System.setProperty("javax.net.ssl.keyStore", keyFilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        System.setProperty("javax.net.ssl.keyStorePassword", passwd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        System.setProperty("javax.net.ssl.trustStore", trustFilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        System.setProperty("javax.net.ssl.trustStorePassword", passwd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        // test the effect of javax.net.ssl.sessionCacheSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        System.setProperty("javax.net.ssl.sessionCacheSize", String.valueOf(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        sslctx = SSLContext.getInstance("TLS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        KeyStore ks = KeyStore.getInstance("JKS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        ks.load(new FileInputStream(keyFilename), passwd.toCharArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        kmf.init(ks, passwd.toCharArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        sslctx.init(kmf.getKeyManagers(), null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        sslssf = (SSLServerSocketFactory) sslctx.getServerSocketFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        sslsf = (SSLSocketFactory) sslctx.getSocketFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if (debug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            System.setProperty("javax.net.debug", "all");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
         * Start the tests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        new SessionCacheSizeTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    Thread clientThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    Thread serverThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Primary constructor, used to drive remainder of the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * Fork off the other side, then do your work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    SessionCacheSizeTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
         * create the SSLServerSocket and SSLSocket factories
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
         * Divide the max connections among the available server ports.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
         * The use of more than one server port ensures creation of more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
         * than one session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        int serverConns = MAX_ACTIVE_CONNECTIONS / (serverPorts.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        int remainingConns = MAX_ACTIVE_CONNECTIONS % (serverPorts.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   340
        Exception startException = null;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   341
        try {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   342
            if (separateServerThread) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   343
                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
   344
                    // distribute remaining connections among the
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   345
                    // available ports
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   346
                    if (i < remainingConns)
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   347
                        startServer(serverPorts[i], (serverConns + 1), true);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   348
                    else
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   349
                        startServer(serverPorts[i], serverConns, true);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   350
                }
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   351
                startClient(false);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   352
            } else {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   353
                startClient(true);
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
                    if (i < remainingConns)
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   356
                        startServer(serverPorts[i], (serverConns + 1), false);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   357
                    else
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   358
                        startServer(serverPorts[i], serverConns, false);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   359
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            }
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   361
        } catch (Exception e) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   362
            startException = e;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
         * Wait for other side to close down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        if (separateServerThread) {
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   369
            if (serverThread != null) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   370
                serverThread.join();
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   371
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        } else {
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   373
            if (clientThread != null) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   374
                clientThread.join();
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   375
            }
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
         * 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
   380
         */
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   381
        Exception local;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   382
        Exception remote;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   383
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   384
        if (separateServerThread) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   385
            remote = serverException;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   386
            local = clientException;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   387
        } else {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   388
            remote = clientException;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   389
            local = serverException;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   390
        }
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   391
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   392
        Exception exception = null;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   393
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
         * Check various exception conditions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
         */
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   397
        if ((local != null) && (remote != null)) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   398
            // 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
   399
            local.initCause(remote);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   400
            exception = local;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   401
        } else if (local != null) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   402
            exception = local;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   403
        } else if (remote != null) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   404
            exception = remote;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   405
        } else if (startException != null) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   406
            exception = startException;
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
        /*
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   410
         * 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
   411
         * output it.
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   412
         */
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   413
        if (exception != null) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   414
            if (exception != startException && startException != null) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   415
                exception.addSuppressed(startException);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   416
            }
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   417
            throw exception;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   418
        }
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
        // Fall-through: no exception to throw!
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    void startServer(final int port, final int nConns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                        boolean newThread) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        if (newThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            serverThread = new Thread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                        doServerSide(port, nConns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                         * Our server thread just died.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                         * Release the client, if not active already...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                        System.err.println("Server died...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                        e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                        serverReady = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                        serverException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            serverThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        } else {
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   445
            try {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   446
                doServerSide(port, nConns);
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   447
            } catch (Exception e) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   448
                serverException = e;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   449
            } finally {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   450
                serverReady = true;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   451
            }
2
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
    void startClient(boolean newThread)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                 throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if (newThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            clientThread = new Thread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                        doClientSide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                         * Our client thread just died.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                        System.err.println("Client died...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                        clientException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            clientThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        } else {
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   473
            try {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   474
                doClientSide();
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   475
            } catch (Exception e) {
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   476
                clientException = e;
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 14342
diff changeset
   477
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
}