author | alanb |
Fri, 10 Sep 2010 18:48:49 +0100 | |
changeset 6538 | cb0da65ba680 |
parent 5970 | d4e98bbfb0be |
child 7668 | d4a77089c587 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2001, 2007, 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 4511624 |
|
26 |
* @summary Test Making lots of Selectors |
|
27 |
* @library .. |
|
28 |
*/ |
|
29 |
||
30 |
import java.io.*; |
|
31 |
import java.net.*; |
|
32 |
import java.nio.*; |
|
33 |
import java.nio.channels.*; |
|
34 |
import java.util.*; |
|
35 |
import java.nio.channels.spi.SelectorProvider; |
|
36 |
||
37 |
public class Connect { |
|
38 |
||
39 |
static int success = 0; |
|
5970
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
40 |
static int LIMIT = 100; |
2 | 41 |
|
42 |
public static void main(String[] args) throws Exception { |
|
43 |
scaleTest(); |
|
44 |
} |
|
45 |
||
46 |
public static void scaleTest() throws Exception { |
|
47 |
InetAddress myAddress=InetAddress.getByName(TestUtil.HOST); |
|
48 |
InetSocketAddress isa = new InetSocketAddress(myAddress,13); |
|
49 |
||
50 |
for (int j=0; j<LIMIT; j++) { |
|
51 |
SocketChannel sc = SocketChannel.open(); |
|
52 |
sc.configureBlocking(false); |
|
5970
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
53 |
boolean connected = sc.connect(isa); |
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
54 |
if (!connected) { |
2 | 55 |
Selector RSelector = SelectorProvider.provider().openSelector(); |
56 |
SelectionKey RKey = sc.register (RSelector, SelectionKey.OP_CONNECT); |
|
5970
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
57 |
while (!connected) { |
2 | 58 |
int keysAdded = RSelector.select(100); |
59 |
if (keysAdded > 0) { |
|
5970
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
60 |
Set<SelectionKey> readyKeys = RSelector.selectedKeys(); |
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
61 |
Iterator<SelectionKey> i = readyKeys.iterator(); |
2 | 62 |
while (i.hasNext()) { |
5970
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
63 |
SelectionKey sk = i.next(); |
2 | 64 |
SocketChannel nextReady = (SocketChannel)sk.channel(); |
5970
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
65 |
connected = nextReady.finishConnect(); |
2 | 66 |
} |
5970
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
67 |
readyKeys.clear(); |
2 | 68 |
} |
69 |
} |
|
70 |
RSelector.close(); |
|
71 |
} |
|
5970
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
72 |
readAndClose(sc); |
2 | 73 |
} |
74 |
} |
|
75 |
||
5970
d4e98bbfb0be
6963027: TEST_BUG: channels and buffer tests need to run in samevm mode
alanb
parents:
5506
diff
changeset
|
76 |
static void readAndClose(SocketChannel sc) throws Exception { |
2 | 77 |
ByteBuffer bb = ByteBuffer.allocateDirect(100); |
78 |
int n = 0; |
|
79 |
while (n == 0) // Note this is not a rigorous check for done reading |
|
80 |
n = sc.read(bb); |
|
81 |
//bb.position(bb.position() - 2); |
|
82 |
//bb.flip(); |
|
83 |
//CharBuffer cb = Charset.forName("US-ASCII").newDecoder().decode(bb); |
|
84 |
//System.out.println("Received: \"" + cb + "\""); |
|
85 |
sc.close(); |
|
86 |
success++; |
|
87 |
} |
|
88 |
} |