author | prr |
Fri, 25 May 2018 12:12:24 -0700 | |
changeset 50347 | b2f046ae8eb6 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
20176
diff
changeset
|
2 |
* Copyright (c) 2002, 2013, 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 |
|
20176
59b7a49e7f8b
8024883: (se) SelectableChannel.register throws NPE if fd >= 64k (lnx)
alanb
parents:
7668
diff
changeset
|
25 |
* @bug 4777504 8024883 |
2 | 26 |
* @summary Ensure that a Selector can return at least 100 selected keys |
27 |
* @author Mark Reinhold |
|
28 |
* @library .. |
|
5970
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
29 |
* @build SelectorLimit |
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
30 |
* @run main/othervm SelectorLimit |
20176
59b7a49e7f8b
8024883: (se) SelectableChannel.register throws NPE if fd >= 64k (lnx)
alanb
parents:
7668
diff
changeset
|
31 |
* @run main/othervm -Dsun.nio.ch.maxUpdateArraySize=128 SelectorLimit |
2 | 32 |
*/ |
33 |
||
34 |
import java.io.*; |
|
35 |
import java.net.*; |
|
36 |
import java.nio.*; |
|
37 |
import java.nio.channels.*; |
|
38 |
import java.util.*; |
|
39 |
||
40 |
||
41 |
public class SelectorLimit { |
|
42 |
||
43 |
static PrintStream log = System.err; |
|
44 |
||
45 |
static class Listener |
|
46 |
extends TestThread |
|
47 |
{ |
|
48 |
volatile int count = 0; |
|
49 |
private ServerSocketChannel ssc; |
|
50 |
||
51 |
Listener(ServerSocketChannel ssc) { |
|
52 |
super("Listener"); |
|
53 |
this.ssc = ssc; |
|
54 |
} |
|
55 |
||
56 |
void go() throws IOException { |
|
57 |
for (;;) { |
|
58 |
ssc.accept(); |
|
59 |
count++; |
|
60 |
} |
|
61 |
} |
|
62 |
||
63 |
} |
|
64 |
||
65 |
static final int N_KEYS = 500; |
|
66 |
static final int MIN_KEYS = 100; |
|
67 |
||
68 |
public static void main(String[] args) throws Exception { |
|
69 |
ServerSocketChannel ssc = ServerSocketChannel.open(); |
|
70 |
TestUtil.bind(ssc); |
|
71 |
Listener lth = new Listener(ssc); |
|
72 |
lth.start(); |
|
73 |
||
74 |
Selector sel = Selector.open(); |
|
75 |
SocketChannel[] sca = new SocketChannel[N_KEYS]; |
|
76 |
for (int i = 0; i < N_KEYS; i++) { |
|
77 |
SocketChannel sc = SocketChannel.open(); |
|
78 |
sc.configureBlocking(false); |
|
79 |
sc.register(sel, SelectionKey.OP_CONNECT | SelectionKey.OP_WRITE); |
|
80 |
sc.connect(ssc.socket().getLocalSocketAddress()); |
|
81 |
} |
|
82 |
||
83 |
for (int i = 0; i < 10; i++) { |
|
84 |
if (lth.count >= MIN_KEYS) |
|
85 |
break; |
|
86 |
Thread.sleep(1000); |
|
87 |
} |
|
88 |
log.println(lth.count + " connections accepted"); |
|
89 |
Thread.sleep(500); |
|
90 |
||
91 |
int n = sel.select(); |
|
92 |
log.println(n + " keys selected"); |
|
93 |
if (n < MIN_KEYS) |
|
94 |
throw new Exception("Only selected " + n + " keys"); |
|
95 |
||
96 |
} |
|
97 |
||
98 |
} |