8025415: Test SSLSocketImplThrowsWrongExceptions.java timed out
Reviewed-by: weijun
--- a/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLSocketImpl/SSLSocketImplThrowsWrongExceptions.java Tue Dec 24 16:43:19 2013 -0800
+++ b/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/SSLSocketImpl/SSLSocketImplThrowsWrongExceptions.java Tue Dec 24 20:07:12 2013 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -21,15 +21,17 @@
* questions.
*/
+//
+// SunJSSE does not support dynamic system properties, no way to re-use
+// system properties in samevm/agentvm mode.
+//
+
/*
* @test
* @bug 4361124 4325806
* @summary SSLServerSocket isn't throwing exceptions when negotiations are
* failing & java.net.SocketException: occures in Auth and clientmode
* @run main/othervm SSLSocketImplThrowsWrongExceptions
- *
- * SunJSSE does not support dynamic system properties, no way to re-use
- * system properties in samevm/agentvm mode.
* @author Brad Wetmore
*/
@@ -184,34 +186,76 @@
* Fork off the other side, then do your work.
*/
SSLSocketImplThrowsWrongExceptions () throws Exception {
- if (separateServerThread) {
- startServer(true);
- startClient(false);
- } else {
- startClient(true);
- startServer(false);
+ Exception startException = null;
+ try {
+ if (separateServerThread) {
+ startServer(true);
+ startClient(false);
+ } else {
+ startClient(true);
+ startServer(false);
+ }
+ } catch (Exception e) {
+ startException = e;
}
/*
* Wait for other side to close down.
*/
if (separateServerThread) {
- serverThread.join();
+ if (serverThread != null) {
+ serverThread.join();
+ }
} else {
- clientThread.join();
+ if (clientThread != null) {
+ clientThread.join();
+ }
}
/*
* When we get here, the test is pretty much over.
- *
- * If the main thread excepted, that propagates back
- * immediately. If the other thread threw an exception, we
- * should report back.
+ * Which side threw the error?
+ */
+ Exception local;
+ Exception remote;
+
+ if (separateServerThread) {
+ remote = serverException;
+ local = clientException;
+ } else {
+ remote = clientException;
+ local = serverException;
+ }
+
+ Exception exception = null;
+
+ /*
+ * Check various exception conditions.
*/
- if (serverException != null)
- throw serverException;
- if (clientException != null)
- throw clientException;
+ if ((local != null) && (remote != null)) {
+ // If both failed, return the curthread's exception.
+ local.initCause(remote);
+ exception = local;
+ } else if (local != null) {
+ exception = local;
+ } else if (remote != null) {
+ exception = remote;
+ } else if (startException != null) {
+ exception = startException;
+ }
+
+ /*
+ * If there was an exception *AND* a startException,
+ * output it.
+ */
+ if (exception != null) {
+ if (exception != startException && startException != null) {
+ exception.addSuppressed(startException);
+ }
+ throw exception;
+ }
+
+ // Fall-through: no exception to throw!
}
void startServer(boolean newThread) throws Exception {
@@ -226,7 +270,7 @@
*
* Release the client, if not active already...
*/
- System.out.println("Server died...");
+ System.err.println("Server died...");
serverReady = true;
serverException = e;
}
@@ -234,7 +278,13 @@
};
serverThread.start();
} else {
- doServerSide();
+ try {
+ doServerSide();
+ } catch (Exception e) {
+ serverException = e;
+ } finally {
+ serverReady = true;
+ }
}
}
@@ -248,14 +298,18 @@
/*
* Our client thread just died.
*/
- System.out.println("Client died...");
+ System.err.println("Client died...");
clientException = e;
}
}
};
clientThread.start();
} else {
- doClientSide();
+ try {
+ doClientSide();
+ } catch (Exception e) {
+ clientException = e;
+ }
}
}
}