author | aefimov |
Wed, 10 Jul 2019 16:09:20 +0100 | |
changeset 55645 | 3203e857fa71 |
parent 54811 | 9db7c0f561a6 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
55645
3203e857fa71
8226756: Replace wildcard address with loopback or local host in tests - part 18
aefimov
parents:
54811
diff
changeset
|
2 |
* Copyright (c) 2000, 2019, 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 4158021 |
|
54770
62b6e7587b1f
8220673: Add test library support for determining platform IP support
aeubanks
parents:
49431
diff
changeset
|
27 |
* @library /test/lib |
2 | 28 |
* @summary cannot distinguish Thread.interrupt and Socket.setSoTimeout exceptions |
49431
5812849b5027
8198358: Align organization of TwoStacksPlainSocketImp with DualStackPlainSocketImpl [win]
igerasim
parents:
47216
diff
changeset
|
29 |
* @run main SocketTimeout |
5812849b5027
8198358: Align organization of TwoStacksPlainSocketImp with DualStackPlainSocketImpl [win]
igerasim
parents:
47216
diff
changeset
|
30 |
* @run main/othervm -Djava.net.preferIPv4Stack=true SocketTimeout |
2 | 31 |
*/ |
32 |
||
33 |
import java.net.*; |
|
34 |
import java.io.*; |
|
54770
62b6e7587b1f
8220673: Add test library support for determining platform IP support
aeubanks
parents:
49431
diff
changeset
|
35 |
import jdk.test.lib.net.IPSupport; |
2 | 36 |
|
37 |
public class SocketTimeout { |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
38 |
static final int TIMEOUT = 1000; |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
39 |
|
2 | 40 |
public static void main(String args[]) throws Exception { |
54811
9db7c0f561a6
8223652: Rename IPSupport.skipIfCurrentConfigurationIsInvalid() to IPSupport.throwSkippedExceptionIfNonOperational()
aeubanks
parents:
54770
diff
changeset
|
41 |
IPSupport.throwSkippedExceptionIfNonOperational(); |
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
42 |
InetAddress sin = InetAddress.getLocalHost(); |
2 | 43 |
Socket soc = null,soc1 = null; |
44 |
InputStream is = null; |
|
45 |
ServerSocket srv = null; |
|
46 |
int port = 0; |
|
47 |
||
55645
3203e857fa71
8226756: Replace wildcard address with loopback or local host in tests - part 18
aefimov
parents:
54811
diff
changeset
|
48 |
srv = new ServerSocket(); |
3203e857fa71
8226756: Replace wildcard address with loopback or local host in tests - part 18
aefimov
parents:
54811
diff
changeset
|
49 |
srv.bind(new InetSocketAddress(sin, 0)); |
2 | 50 |
port = srv.getLocalPort(); |
51 |
soc = new Socket(sin, port); |
|
52 |
soc1 = srv.accept(); |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
53 |
soc.setSoTimeout(TIMEOUT); |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
54 |
srv.setSoTimeout(TIMEOUT); |
2 | 55 |
|
56 |
try { |
|
57 |
is = soc.getInputStream(); |
|
58 |
is.read(); |
|
59 |
} catch(InterruptedIOException e) { |
|
60 |
try { |
|
61 |
if (! (e instanceof java.net.SocketTimeoutException)) |
|
62 |
throw new Exception ("Wrong exception class thrown"); |
|
63 |
} catch(NoClassDefFoundError e1) { |
|
64 |
throw new Exception ("SocketTimeoutException: not found"); |
|
65 |
} |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
66 |
} finally { |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
67 |
soc.close(); |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
68 |
soc1.close(); |
2 | 69 |
} |
70 |
||
71 |
// now check accept |
|
72 |
||
73 |
try { |
|
74 |
srv.accept (); |
|
75 |
} catch(InterruptedIOException e) { |
|
76 |
try { |
|
77 |
if (! (e instanceof java.net.SocketTimeoutException)) |
|
78 |
throw new Exception ("Wrong exception class thrown"); |
|
79 |
} catch(NoClassDefFoundError e1) { |
|
80 |
throw new Exception ("SocketTimeoutException: not found"); |
|
81 |
} |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
82 |
} finally { |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
83 |
srv.close(); |
2 | 84 |
} |
85 |
||
86 |
// Now check DatagramSocket.receive() |
|
87 |
||
88 |
DatagramSocket dg = new DatagramSocket (); |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
89 |
dg.setSoTimeout (TIMEOUT); |
2 | 90 |
|
91 |
try { |
|
92 |
dg.receive (new DatagramPacket (new byte [64], 64)); |
|
93 |
} catch(InterruptedIOException e) { |
|
94 |
try { |
|
95 |
if (! (e instanceof java.net.SocketTimeoutException)) |
|
96 |
throw new Exception ("Wrong exception class thrown"); |
|
97 |
} catch(NoClassDefFoundError e1) { |
|
98 |
throw new Exception ("SocketTimeoutException: not found"); |
|
99 |
} |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
100 |
} finally { |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
101 |
dg.close(); |
2 | 102 |
} |
103 |
} |
|
104 |
} |