author | amurillo |
Wed, 15 Aug 2012 16:49:38 -0700 | |
changeset 13465 | d3fc5d192448 |
parent 7668 | d4a77089c587 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2000, 2010, 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 |
|
27 |
* @summary cannot distinguish Thread.interrupt and Socket.setSoTimeout exceptions |
|
28 |
*/ |
|
29 |
||
30 |
import java.net.*; |
|
31 |
import java.io.*; |
|
32 |
||
33 |
public class SocketTimeout { |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
34 |
static final int TIMEOUT = 1000; |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
35 |
|
2 | 36 |
public static void main(String args[]) throws Exception { |
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
37 |
InetAddress sin = InetAddress.getLocalHost(); |
2 | 38 |
Socket soc = null,soc1 = null; |
39 |
InputStream is = null; |
|
40 |
ServerSocket srv = null; |
|
41 |
int port = 0; |
|
42 |
||
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
43 |
srv = new ServerSocket(0); |
2 | 44 |
port = srv.getLocalPort(); |
45 |
soc = new Socket(sin, port); |
|
46 |
soc1 = srv.accept(); |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
47 |
soc.setSoTimeout(TIMEOUT); |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
48 |
srv.setSoTimeout(TIMEOUT); |
2 | 49 |
|
50 |
try { |
|
51 |
is = soc.getInputStream(); |
|
52 |
is.read(); |
|
53 |
} catch(InterruptedIOException e) { |
|
54 |
try { |
|
55 |
if (! (e instanceof java.net.SocketTimeoutException)) |
|
56 |
throw new Exception ("Wrong exception class thrown"); |
|
57 |
} catch(NoClassDefFoundError e1) { |
|
58 |
throw new Exception ("SocketTimeoutException: not found"); |
|
59 |
} |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
60 |
} finally { |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
61 |
soc.close(); |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
62 |
soc1.close(); |
2 | 63 |
} |
64 |
||
65 |
// now check accept |
|
66 |
||
67 |
try { |
|
68 |
srv.accept (); |
|
69 |
} catch(InterruptedIOException e) { |
|
70 |
try { |
|
71 |
if (! (e instanceof java.net.SocketTimeoutException)) |
|
72 |
throw new Exception ("Wrong exception class thrown"); |
|
73 |
} catch(NoClassDefFoundError e1) { |
|
74 |
throw new Exception ("SocketTimeoutException: not found"); |
|
75 |
} |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
76 |
} finally { |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
77 |
srv.close(); |
2 | 78 |
} |
79 |
||
80 |
// Now check DatagramSocket.receive() |
|
81 |
||
82 |
DatagramSocket dg = new DatagramSocket (); |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
83 |
dg.setSoTimeout (TIMEOUT); |
2 | 84 |
|
85 |
try { |
|
86 |
dg.receive (new DatagramPacket (new byte [64], 64)); |
|
87 |
} catch(InterruptedIOException e) { |
|
88 |
try { |
|
89 |
if (! (e instanceof java.net.SocketTimeoutException)) |
|
90 |
throw new Exception ("Wrong exception class thrown"); |
|
91 |
} catch(NoClassDefFoundError e1) { |
|
92 |
throw new Exception ("SocketTimeoutException: not found"); |
|
93 |
} |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
94 |
} finally { |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
95 |
dg.close(); |
2 | 96 |
} |
97 |
} |
|
98 |
} |