author | alanb |
Fri, 14 Sep 2018 16:56:09 +0100 | |
changeset 51745 | 90c1dcdebc64 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2001, 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 4940372 |
|
26 |
* @summary Ensure that the wakeup state is cleared by selectNow() |
|
27 |
*/ |
|
28 |
||
29 |
import java.nio.channels.*; |
|
30 |
||
31 |
public class WakeupNow { |
|
32 |
||
33 |
public static void main(String[] args) throws Exception { |
|
34 |
test1(); |
|
35 |
test2(); |
|
36 |
} |
|
37 |
||
38 |
// Test if selectNow clears wakeup with the wakeup fd and |
|
39 |
// another fd in the selector. |
|
40 |
// This fails before the fix on Linux |
|
41 |
private static void test1() throws Exception { |
|
42 |
Selector sel = Selector.open(); |
|
43 |
Pipe p = Pipe.open(); |
|
44 |
p.source().configureBlocking(false); |
|
45 |
p.source().register(sel, SelectionKey.OP_READ); |
|
46 |
sel.wakeup(); |
|
5970
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
47 |
// ensure wakeup is consumed by selectNow |
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
48 |
Thread.sleep(2000); |
2 | 49 |
sel.selectNow(); |
50 |
long startTime = System.currentTimeMillis(); |
|
51 |
int n = sel.select(2000); |
|
52 |
long endTime = System.currentTimeMillis(); |
|
5970
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
53 |
p.source().close(); |
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
54 |
p.sink().close(); |
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
55 |
sel.close(); |
2 | 56 |
if (endTime - startTime < 1000) |
57 |
throw new RuntimeException("test failed"); |
|
58 |
} |
|
59 |
||
60 |
// Test if selectNow clears wakeup with only the wakeup fd |
|
61 |
// in the selector. |
|
62 |
// This fails before the fix on Solaris |
|
63 |
private static void test2() throws Exception { |
|
64 |
Selector sel = Selector.open(); |
|
65 |
Pipe p = Pipe.open(); |
|
66 |
p.source().configureBlocking(false); |
|
67 |
sel.wakeup(); |
|
5970
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
68 |
// ensure wakeup is consumed by selectNow |
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
69 |
Thread.sleep(2000); |
2 | 70 |
sel.selectNow(); |
71 |
long startTime = System.currentTimeMillis(); |
|
72 |
int n = sel.select(2000); |
|
73 |
long endTime = System.currentTimeMillis(); |
|
5970
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
74 |
sel.close(); |
2 | 75 |
if (endTime - startTime < 1000) |
76 |
throw new RuntimeException("test failed"); |
|
77 |
} |
|
78 |
||
79 |
} |