author | prr |
Thu, 18 Dec 2014 10:45:45 -0800 | |
changeset 29908 | 83e2c403fefd |
parent 23743 | 92cae64be74e |
child 34947 | e937e10e46f7 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23743 | 2 |
* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
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 | 29 |
/* |
30 |
* @test |
|
23743 | 31 |
* @bug 4366807 |
2 | 32 |
* @summary Need new APIs to get/set session timeout and session cache size. |
10328 | 33 |
* @run main/othervm SessionCacheSizeTests |
2 | 34 |
*/ |
35 |
||
36 |
import java.io.*; |
|
37 |
import java.net.*; |
|
38 |
import javax.net.ssl.*; |
|
39 |
import java.util.*; |
|
40 |
import java.security.*; |
|
41 |
||
42 |
/** |
|
43 |
* Session cache size tests cover the following cases: |
|
44 |
* 1. Effect of system property javax.net.ssl.SessionCacheSize (this |
|
45 |
* property is not documented for public). |
|
46 |
* 2. Reducing the cache size, results in uncaching of sessions if #of |
|
47 |
* sessions present exceeds the new size. |
|
48 |
* 3. Increasing the cache size, results in accomodating new sessions if the |
|
49 |
* number of cached sessions is the current size limit. |
|
50 |
* |
|
51 |
* Invairant for passing this test is, at any given time, |
|
52 |
* #cached_sessions <= current_cache_size , for current_cache_size > 0 |
|
53 |
*/ |
|
54 |
||
55 |
public class SessionCacheSizeTests { |
|
56 |
||
57 |
/* |
|
58 |
* ============================================================= |
|
59 |
* Set the various variables needed for the tests, then |
|
60 |
* specify what tests to run on each side. |
|
61 |
*/ |
|
62 |
||
63 |
/* |
|
64 |
* Should we run the client or server in a separate thread? |
|
65 |
* Both sides can throw exceptions, but do you have a preference |
|
66 |
* as to which side should be the main thread. |
|
67 |
*/ |
|
68 |
static boolean separateServerThread = true; |
|
69 |
||
70 |
/* |
|
71 |
* Where do we find the keystores? |
|
72 |
*/ |
|
23052
241885315119
8032473: Restructure JSSE regression test hierarchy in jdk test
xuelei
parents:
19575
diff
changeset
|
73 |
static String pathToStores = "../etc"; |
2 | 74 |
static String keyStoreFile = "keystore"; |
75 |
static String trustStoreFile = "truststore"; |
|
76 |
static String passwd = "passphrase"; |
|
77 |
||
78 |
/* |
|
79 |
* Is the server ready to serve? |
|
80 |
*/ |
|
81 |
volatile static boolean serverReady = false; |
|
82 |
||
83 |
/* |
|
84 |
* Turn on SSL debugging? |
|
85 |
*/ |
|
86 |
static boolean debug = false; |
|
87 |
||
88 |
/* |
|
89 |
* If the client or server is doing some kind of object creation |
|
90 |
* that the other side depends on, and that thread prematurely |
|
91 |
* exits, you may experience a hang. The test harness will |
|
92 |
* terminate all hung threads after its timeout has expired, |
|
93 |
* currently 3 minutes by default, but you might try to be |
|
94 |
* smart about it.... |
|
95 |
*/ |
|
96 |
||
97 |
/* |
|
98 |
* Define the server side of the test. |
|
99 |
* |
|
100 |
* If the server prematurely exits, serverReady will be set to true |
|
101 |
* to avoid infinite hangs. |
|
102 |
*/ |
|
103 |
||
104 |
/* |
|
105 |
* A limit on the number of connections at any given time |
|
106 |
*/ |
|
107 |
static int MAX_ACTIVE_CONNECTIONS = 4; |
|
108 |
||
109 |
void doServerSide(int serverPort, int serverConns) throws Exception { |
|
110 |
||
111 |
SSLServerSocket sslServerSocket = |
|
112 |
(SSLServerSocket) sslssf.createServerSocket(serverPort); |
|
23743 | 113 |
sslServerSocket.setSoTimeout(45000); // timeout to accept a connection |
2 | 114 |
serverPorts[createdPorts++] = sslServerSocket.getLocalPort(); |
115 |
||
116 |
/* |
|
117 |
* Signal Client, we're ready for his connect. |
|
118 |
*/ |
|
19575
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
119 |
if (createdPorts == serverPorts.length) { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
120 |
serverReady = true; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
121 |
} |
2 | 122 |
int read = 0; |
123 |
int nConnections = 0; |
|
124 |
/* |
|
125 |
* Divide the max connections among the available server ports. |
|
126 |
* The use of more than one server port ensures creation of more |
|
127 |
* than one session. |
|
128 |
*/ |
|
129 |
SSLSession sessions [] = new SSLSession [serverConns]; |
|
130 |
SSLSessionContext sessCtx = sslctx.getServerSessionContext(); |
|
131 |
||
23743 | 132 |
try { |
133 |
while (nConnections < serverConns) { |
|
134 |
try (SSLSocket sslSocket = |
|
135 |
(SSLSocket)sslServerSocket.accept()) { |
|
136 |
sslSocket.setSoTimeout(90000); // timeout to read |
|
137 |
InputStream sslIS = sslSocket.getInputStream(); |
|
138 |
OutputStream sslOS = sslSocket.getOutputStream(); |
|
139 |
read = sslIS.read(); |
|
140 |
sessions[nConnections] = sslSocket.getSession(); |
|
141 |
sslOS.write(85); |
|
142 |
sslOS.flush(); |
|
143 |
nConnections++; |
|
144 |
} |
|
145 |
} |
|
146 |
} finally { |
|
147 |
sslServerSocket.close(); |
|
2 | 148 |
} |
149 |
} |
|
150 |
||
151 |
/* |
|
152 |
* Define the client side of the test. |
|
153 |
* |
|
154 |
* If the server prematurely exits, serverReady will be set to true |
|
155 |
* to avoid infinite hangs. |
|
156 |
*/ |
|
157 |
void doClientSide() throws Exception { |
|
158 |
||
159 |
/* |
|
160 |
* Wait for server to get started. |
|
161 |
*/ |
|
162 |
while (!serverReady) { |
|
163 |
Thread.sleep(50); |
|
164 |
} |
|
165 |
||
166 |
int nConnections = 0; |
|
167 |
SSLSocket sslSockets[] = new SSLSocket [MAX_ACTIVE_CONNECTIONS]; |
|
168 |
Vector sessions = new Vector(); |
|
169 |
SSLSessionContext sessCtx = sslctx.getClientSessionContext(); |
|
170 |
sessCtx.setSessionTimeout(0); // no limit |
|
171 |
||
172 |
while (nConnections < (MAX_ACTIVE_CONNECTIONS - 1)) { |
|
173 |
// divide the connections among the available server ports |
|
174 |
sslSockets[nConnections] = (SSLSocket) sslsf. |
|
175 |
createSocket("localhost", |
|
176 |
serverPorts [nConnections % (serverPorts.length)]); |
|
177 |
InputStream sslIS = sslSockets[nConnections].getInputStream(); |
|
178 |
OutputStream sslOS = sslSockets[nConnections].getOutputStream(); |
|
179 |
sslOS.write(237); |
|
180 |
sslOS.flush(); |
|
181 |
int read = sslIS.read(); |
|
182 |
SSLSession sess = sslSockets[nConnections].getSession(); |
|
183 |
if (!sessions.contains(sess)) |
|
184 |
sessions.add(sess); |
|
185 |
nConnections++; |
|
186 |
} |
|
187 |
System.out.println("Current cacheSize is set to: " + |
|
188 |
sessCtx.getSessionCacheSize()); |
|
189 |
System.out.println(); |
|
190 |
System.out.println("Currently cached Sessions......"); |
|
191 |
System.out.println("============================================" |
|
192 |
+ "============================"); |
|
193 |
System.out.println("Session " |
|
194 |
+ " Session-last-accessTime"); |
|
195 |
System.out.println("============================================" |
|
196 |
+ "============================"); |
|
197 |
checkCachedSessions(sessCtx, nConnections); |
|
198 |
// Change session cache size |
|
199 |
sessCtx.setSessionCacheSize(2); |
|
200 |
System.out.println("Session cache size changed to: " |
|
201 |
+ sessCtx.getSessionCacheSize()); |
|
202 |
System.out.println(); |
|
203 |
checkCachedSessions(sessCtx, nConnections); |
|
204 |
||
205 |
// Test the effect of increasing the cache size |
|
206 |
sessCtx.setSessionCacheSize(3); |
|
207 |
System.out.println("Session cache size changed to: " |
|
208 |
+ sessCtx.getSessionCacheSize()); |
|
209 |
// create a new session |
|
210 |
sslSockets[nConnections] = (SSLSocket) sslsf. |
|
211 |
createSocket("localhost", |
|
212 |
serverPorts [nConnections % (serverPorts.length)]); |
|
213 |
InputStream sslIS = sslSockets[nConnections].getInputStream(); |
|
214 |
OutputStream sslOS = sslSockets[nConnections].getOutputStream(); |
|
215 |
sslOS.write(237); |
|
216 |
sslOS.flush(); |
|
217 |
int read = sslIS.read(); |
|
218 |
SSLSession sess = sslSockets[nConnections].getSession(); |
|
219 |
if (!sessions.contains(sess)) |
|
220 |
sessions.add(sess); |
|
221 |
nConnections++; |
|
222 |
||
223 |
// test the number of sessions cached against the cache size |
|
224 |
checkCachedSessions(sessCtx, nConnections); |
|
225 |
||
226 |
for (int i = 0; i < nConnections; i++) { |
|
227 |
sslSockets[i].close(); |
|
228 |
} |
|
229 |
System.out.println("Session cache size tests passed"); |
|
230 |
} |
|
231 |
||
232 |
void checkCachedSessions(SSLSessionContext sessCtx, |
|
233 |
int nConn) throws Exception { |
|
234 |
int nSessions = 0; |
|
235 |
Enumeration e = sessCtx.getIds(); |
|
236 |
int cacheSize = sessCtx.getSessionCacheSize(); |
|
237 |
SSLSession sess; |
|
238 |
||
239 |
while (e.hasMoreElements()) { |
|
240 |
sess = sessCtx.getSession((byte[]) e.nextElement()); |
|
241 |
long lastAccessedTime = sess.getLastAccessedTime(); |
|
242 |
System.out.println(sess + " " |
|
243 |
+ new Date(lastAccessedTime)); |
|
244 |
||
245 |
nSessions++; |
|
246 |
} |
|
247 |
System.out.println("--------------------------------------------" |
|
248 |
+ "----------------------------"); |
|
249 |
if ((cacheSize > 0) && (nSessions > cacheSize)) { |
|
250 |
||
251 |
// close all active connections before exiting |
|
252 |
for (int conn = nConn; conn < MAX_ACTIVE_CONNECTIONS; conn++) { |
|
253 |
SSLSocket s = (SSLSocket) sslsf.createSocket("localhost", |
|
254 |
serverPorts [conn % (serverPorts.length)]); |
|
255 |
s.close(); |
|
256 |
} |
|
257 |
throw new Exception("Session cache size test failed," |
|
258 |
+ " current cache size: " + cacheSize + " #sessions cached: " |
|
259 |
+ nSessions); |
|
260 |
} |
|
261 |
} |
|
262 |
||
263 |
/* |
|
264 |
* ============================================================= |
|
265 |
* The remainder is just support stuff |
|
266 |
*/ |
|
267 |
||
268 |
/* |
|
269 |
* #of ports > 1, guarantees creation of more than one session. |
|
270 |
* Using four ports (one per each connection), we are able to create |
|
271 |
* alteast four sessions. |
|
272 |
*/ |
|
273 |
volatile int serverPorts[] = new int[]{0, 0, 0, 0}; |
|
274 |
volatile int createdPorts = 0; |
|
275 |
static SSLServerSocketFactory sslssf; |
|
276 |
static SSLSocketFactory sslsf; |
|
277 |
static SSLContext sslctx; |
|
278 |
||
279 |
volatile Exception serverException = null; |
|
280 |
volatile Exception clientException = null; |
|
281 |
||
282 |
public static void main(String[] args) throws Exception { |
|
283 |
String keyFilename = |
|
284 |
System.getProperty("test.src", "./") + "/" + pathToStores + |
|
285 |
"/" + keyStoreFile; |
|
286 |
String trustFilename = |
|
287 |
System.getProperty("test.src", "./") + "/" + pathToStores + |
|
288 |
"/" + trustStoreFile; |
|
289 |
||
290 |
System.setProperty("javax.net.ssl.keyStore", keyFilename); |
|
291 |
System.setProperty("javax.net.ssl.keyStorePassword", passwd); |
|
292 |
System.setProperty("javax.net.ssl.trustStore", trustFilename); |
|
293 |
System.setProperty("javax.net.ssl.trustStorePassword", passwd); |
|
294 |
||
295 |
// test the effect of javax.net.ssl.sessionCacheSize |
|
296 |
System.setProperty("javax.net.ssl.sessionCacheSize", String.valueOf(0)); |
|
297 |
||
298 |
sslctx = SSLContext.getInstance("TLS"); |
|
299 |
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); |
|
300 |
KeyStore ks = KeyStore.getInstance("JKS"); |
|
301 |
ks.load(new FileInputStream(keyFilename), passwd.toCharArray()); |
|
302 |
kmf.init(ks, passwd.toCharArray()); |
|
303 |
sslctx.init(kmf.getKeyManagers(), null, null); |
|
304 |
sslssf = (SSLServerSocketFactory) sslctx.getServerSocketFactory(); |
|
305 |
sslsf = (SSLSocketFactory) sslctx.getSocketFactory(); |
|
306 |
if (debug) |
|
307 |
System.setProperty("javax.net.debug", "all"); |
|
308 |
||
309 |
/* |
|
310 |
* Start the tests. |
|
311 |
*/ |
|
312 |
new SessionCacheSizeTests(); |
|
313 |
} |
|
314 |
||
315 |
Thread clientThread = null; |
|
316 |
Thread serverThread = null; |
|
317 |
||
318 |
/* |
|
319 |
* Primary constructor, used to drive remainder of the test. |
|
320 |
* |
|
321 |
* Fork off the other side, then do your work. |
|
322 |
*/ |
|
323 |
SessionCacheSizeTests() throws Exception { |
|
324 |
/* |
|
325 |
* create the SSLServerSocket and SSLSocket factories |
|
326 |
*/ |
|
327 |
||
328 |
/* |
|
329 |
* Divide the max connections among the available server ports. |
|
330 |
* The use of more than one server port ensures creation of more |
|
331 |
* than one session. |
|
332 |
*/ |
|
333 |
int serverConns = MAX_ACTIVE_CONNECTIONS / (serverPorts.length); |
|
334 |
int remainingConns = MAX_ACTIVE_CONNECTIONS % (serverPorts.length); |
|
335 |
||
19575
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
336 |
Exception startException = null; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
337 |
try { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
338 |
if (separateServerThread) { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
339 |
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
|
340 |
// distribute remaining connections among the |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
341 |
// available ports |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
342 |
if (i < remainingConns) |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
343 |
startServer(serverPorts[i], (serverConns + 1), true); |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
344 |
else |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
345 |
startServer(serverPorts[i], serverConns, true); |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
346 |
} |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
347 |
startClient(false); |
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 |
startClient(true); |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
350 |
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
|
351 |
if (i < remainingConns) |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
352 |
startServer(serverPorts[i], (serverConns + 1), false); |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
353 |
else |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
354 |
startServer(serverPorts[i], serverConns, false); |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
355 |
} |
2 | 356 |
} |
19575
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
357 |
} catch (Exception e) { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
358 |
startException = e; |
2 | 359 |
} |
360 |
||
361 |
/* |
|
362 |
* Wait for other side to close down. |
|
363 |
*/ |
|
364 |
if (separateServerThread) { |
|
19575
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
365 |
if (serverThread != null) { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
366 |
serverThread.join(); |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
367 |
} |
2 | 368 |
} else { |
19575
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
369 |
if (clientThread != null) { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
370 |
clientThread.join(); |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
371 |
} |
2 | 372 |
} |
373 |
||
374 |
/* |
|
375 |
* 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
|
376 |
*/ |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
377 |
Exception local; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
378 |
Exception remote; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
379 |
|
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
380 |
if (separateServerThread) { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
381 |
remote = serverException; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
382 |
local = clientException; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
383 |
} else { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
384 |
remote = clientException; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
385 |
local = serverException; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
386 |
} |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
387 |
|
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
388 |
Exception exception = null; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
389 |
|
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 |
* Check various exception conditions. |
2 | 392 |
*/ |
19575
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
393 |
if ((local != null) && (remote != null)) { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
394 |
// 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
|
395 |
local.initCause(remote); |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
396 |
exception = local; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
397 |
} else if (local != null) { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
398 |
exception = local; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
399 |
} else if (remote != null) { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
400 |
exception = remote; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
401 |
} else if (startException != null) { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
402 |
exception = startException; |
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 |
|
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 |
* 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
|
407 |
* output it. |
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 |
if (exception != null) { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
410 |
if (exception != startException && startException != null) { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
411 |
exception.addSuppressed(startException); |
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 |
throw exception; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
414 |
} |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
415 |
|
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
416 |
// Fall-through: no exception to throw! |
2 | 417 |
} |
418 |
||
419 |
void startServer(final int port, final int nConns, |
|
420 |
boolean newThread) throws Exception { |
|
421 |
if (newThread) { |
|
422 |
serverThread = new Thread() { |
|
423 |
public void run() { |
|
424 |
try { |
|
425 |
doServerSide(port, nConns); |
|
426 |
} catch (Exception e) { |
|
427 |
/* |
|
428 |
* Our server thread just died. |
|
429 |
* |
|
430 |
* Release the client, if not active already... |
|
431 |
*/ |
|
432 |
System.err.println("Server died..."); |
|
433 |
e.printStackTrace(); |
|
434 |
serverReady = true; |
|
435 |
serverException = e; |
|
436 |
} |
|
437 |
} |
|
438 |
}; |
|
439 |
serverThread.start(); |
|
440 |
} else { |
|
19575
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
441 |
try { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
442 |
doServerSide(port, nConns); |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
443 |
} catch (Exception e) { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
444 |
serverException = e; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
445 |
} finally { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
446 |
serverReady = true; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
447 |
} |
2 | 448 |
} |
449 |
} |
|
450 |
||
451 |
void startClient(boolean newThread) |
|
452 |
throws Exception { |
|
453 |
if (newThread) { |
|
454 |
clientThread = new Thread() { |
|
455 |
public void run() { |
|
456 |
try { |
|
457 |
doClientSide(); |
|
458 |
} catch (Exception e) { |
|
459 |
/* |
|
460 |
* Our client thread just died. |
|
461 |
*/ |
|
462 |
System.err.println("Client died..."); |
|
463 |
clientException = e; |
|
464 |
} |
|
465 |
} |
|
466 |
}; |
|
467 |
clientThread.start(); |
|
468 |
} else { |
|
19575
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
469 |
try { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
470 |
doClientSide(); |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
471 |
} catch (Exception e) { |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
472 |
clientException = e; |
ff87fda24d33
8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents:
14342
diff
changeset
|
473 |
} |
2 | 474 |
} |
475 |
} |
|
476 |
} |