author | snikandrova |
Mon, 29 Aug 2016 20:55:06 +0300 | |
changeset 40569 | 686e7a790c5d |
parent 23052 | 241885315119 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
40569
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
2 |
* Copyright (c) 2002, 2016, 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 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4674913 |
|
27 |
* @summary Verify that EOFException are correctly handled during the handshake |
|
28 |
* @author Andreas Sterbenz |
|
40569
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
29 |
* @run main/othervm CloseSocket |
2 | 30 |
*/ |
31 |
||
40569
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
32 |
import javax.net.SocketFactory; |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
33 |
import javax.net.ssl.SSLSocket; |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
34 |
import javax.net.ssl.SSLSocketFactory; |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
35 |
import java.io.IOException; |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
36 |
import java.io.InputStream; |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
37 |
import java.io.OutputStream; |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
38 |
import java.net.ServerSocket; |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
39 |
import java.net.Socket; |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
40 |
import java.util.ArrayList; |
2 | 41 |
|
42 |
public class CloseSocket { |
|
43 |
||
40569
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
44 |
private static ArrayList<TestCase> testCases = new ArrayList<>(); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
45 |
|
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
46 |
static { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
47 |
testCases.add(socket -> socket.startHandshake()); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
48 |
testCases.add(socket -> { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
49 |
InputStream in = socket.getInputStream(); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
50 |
in.read(); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
51 |
}); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
52 |
testCases.add(socket -> { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
53 |
OutputStream out = socket.getOutputStream(); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
54 |
out.write(43); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
55 |
}); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
56 |
} |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
57 |
|
2 | 58 |
public static void main(String[] args) throws Exception { |
40569
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
59 |
try (Server server = new Server()) { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
60 |
new Thread(server).start(); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
61 |
|
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
62 |
SocketFactory factory = SSLSocketFactory.getDefault(); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
63 |
try (SSLSocket socket = (SSLSocket) factory.createSocket("localhost", |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
64 |
server.getPort())) { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
65 |
socket.setSoTimeout(2000); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
66 |
System.out.println("Client established TCP connection"); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
67 |
boolean failed = false; |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
68 |
for (TestCase testCase : testCases) { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
69 |
try { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
70 |
testCase.test(socket); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
71 |
System.out.println("ERROR: no exception"); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
72 |
failed = true; |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
73 |
} catch (IOException e) { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
74 |
System.out.println("Failed as expected: " + e); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
75 |
} |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
76 |
} |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
77 |
if (failed) { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
78 |
throw new Exception("One or more tests failed"); |
2 | 79 |
} |
80 |
} |
|
81 |
} |
|
82 |
} |
|
83 |
||
40569
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
84 |
static class Server implements AutoCloseable, Runnable { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
85 |
|
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
86 |
final ServerSocket serverSocket; |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
87 |
|
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
88 |
Server() throws IOException { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
89 |
serverSocket = new ServerSocket(0); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
90 |
} |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
91 |
|
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
92 |
public int getPort() { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
93 |
return serverSocket.getLocalPort(); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
94 |
} |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
95 |
|
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
96 |
@Override |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
97 |
public void run() { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
98 |
try (Socket s = serverSocket.accept()) { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
99 |
System.out.println("Server accepted connection"); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
100 |
// wait a bit before closing the socket to give |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
101 |
// the client time to send its hello message |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
102 |
Thread.currentThread().sleep(100); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
103 |
s.close(); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
104 |
System.out.println("Server closed socket, done."); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
105 |
} catch (Exception e) { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
106 |
throw new RuntimeException("Problem in test execution", e); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
107 |
} |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
108 |
} |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
109 |
|
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
110 |
@Override |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
111 |
public void close() throws Exception { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
112 |
if (!serverSocket.isClosed()) { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
113 |
serverSocket.close(); |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
114 |
} |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
115 |
} |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
116 |
} |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
117 |
|
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
118 |
interface TestCase { |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
119 |
void test(SSLSocket socket) throws IOException; |
686e7a790c5d
8164533: sun/security/ssl/SSLSocketImpl/CloseSocket.java failed with "Error while cleaning up threads after test"
snikandrova
parents:
23052
diff
changeset
|
120 |
} |
2 | 121 |
} |