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) 1998, 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 |
/* @test |
|
25 |
@bug 4156625 |
|
26 |
@summary Socket.setSoTimeout(T) can cause incorrect delay of T |
|
27 |
under green threads |
|
28 |
@author Tom Rodriguez |
|
29 |
*/ |
|
30 |
||
31 |
/* |
|
32 |
* This program depends a bit on the particular behaviour of the green |
|
33 |
* threads scheduler to produce the problem, but given that the underlying |
|
34 |
* bug a green threads bug, I think that's OK. |
|
35 |
*/ |
|
36 |
||
37 |
import java.net.*; |
|
38 |
||
39 |
public class SoTimeout implements Runnable { |
|
40 |
static ServerSocket serverSocket; |
|
41 |
static long timeWritten; |
|
42 |
static InetAddress addr; |
|
43 |
static int port; |
|
44 |
||
45 |
public static void main(String[] args) throws Exception { |
|
46 |
addr = InetAddress.getLocalHost(); |
|
47 |
serverSocket = new ServerSocket(0); |
|
48 |
port = serverSocket.getLocalPort(); |
|
49 |
||
50 |
byte[] b = new byte[12]; |
|
51 |
Thread t = new Thread(new SoTimeout()); |
|
52 |
t.start(); |
|
53 |
||
54 |
Socket s = serverSocket.accept(); |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
55 |
serverSocket.close(); |
2 | 56 |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
57 |
// set a 5 second timeout on the socket |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
58 |
s.setSoTimeout(5000); |
2 | 59 |
|
60 |
s.getInputStream().read(b, 0, b.length); |
|
61 |
s.close(); |
|
62 |
||
63 |
long waited = System.currentTimeMillis() - timeWritten; |
|
64 |
||
65 |
// this sequence should complete fairly quickly and if it |
|
66 |
// takes something resembling the the SoTimeout value then |
|
67 |
// we are probably incorrectly blocking and not waking up |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
68 |
if (waited > 2000) { |
2 | 69 |
throw new Exception("shouldn't take " + waited + " to complete"); |
70 |
} |
|
71 |
} |
|
72 |
||
73 |
public void run() { |
|
74 |
try { |
|
75 |
byte[] b = new byte[12]; |
|
76 |
Socket s = new Socket(addr, port); |
|
77 |
||
78 |
Thread.yield(); |
|
79 |
timeWritten = System.currentTimeMillis(); |
|
80 |
s.getOutputStream().write(b, 0, 12); |
|
81 |
s.close(); |
|
82 |
} catch (Exception e) { |
|
83 |
e.printStackTrace(); |
|
84 |
} |
|
85 |
} |
|
86 |
||
87 |
} |