author | vtewari |
Wed, 30 May 2018 16:36:35 +0530 | |
changeset 50303 | 7164c3bb55df |
parent 49840 | 799e6e42b95f |
permissions | -rw-r--r-- |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1 |
/* |
49840
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
4 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
8 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
13 |
* accompanied this code). |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
14 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
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. |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
22 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
23 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
24 |
/* @test |
8572
67473782b7a7
7023403: (ch) sun.nio.ch.SolarisEventPort.startPoll failed with AssertionError
alanb
parents:
7668
diff
changeset
|
25 |
* @bug 4607272 6842687 6878369 6944810 7023403 |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
26 |
* @summary Unit test for AsynchronousSocketChannel(use -Dseed=X to set PRNG seed) |
45288
58be10a068c2
8180805: move RandomFactory to the top level testlibrary
iignatyev
parents:
44111
diff
changeset
|
27 |
* @library /test/lib |
50303
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
28 |
* @modules jdk.net |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
29 |
* @key randomness intermittent |
49840
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
30 |
* @build jdk.test.lib.RandomFactory jdk.test.lib.Utils |
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
31 |
* @run main/othervm/timeout=600 Basic -skipSlowConnectTest |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
32 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
33 |
|
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
34 |
import java.io.Closeable; |
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
35 |
import java.io.IOException; |
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
36 |
import java.net.*; |
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
37 |
import static java.net.StandardSocketOptions.*; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
38 |
import java.nio.ByteBuffer; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
39 |
import java.nio.channels.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
40 |
import java.util.Random; |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
41 |
import java.util.Set; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
42 |
import java.util.concurrent.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
43 |
import java.util.concurrent.atomic.*; |
45288
58be10a068c2
8180805: move RandomFactory to the top level testlibrary
iignatyev
parents:
44111
diff
changeset
|
44 |
import jdk.test.lib.RandomFactory; |
50303
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
45 |
import java.util.List; |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
46 |
import static jdk.net.ExtendedSocketOptions.TCP_KEEPCOUNT; |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
47 |
import static jdk.net.ExtendedSocketOptions.TCP_KEEPIDLE; |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
48 |
import static jdk.net.ExtendedSocketOptions.TCP_KEEPINTERVAL; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
49 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
50 |
public class Basic { |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
51 |
private static final Random RAND = RandomFactory.getRandom(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
52 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
53 |
static boolean skipSlowConnectTest = false; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
54 |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
55 |
public static void main(String[] args) throws Exception { |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
56 |
for (String arg: args) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
57 |
switch (arg) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
58 |
case "-skipSlowConnectTest" : |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
59 |
skipSlowConnectTest = true; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
60 |
break; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
61 |
default: |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
62 |
throw new RuntimeException("Unrecognized argument: " + arg); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
63 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
64 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
65 |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
66 |
testBind(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
67 |
testSocketOptions(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
68 |
testConnect(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
69 |
testCloseWhenPending(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
70 |
testCancel(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
71 |
testRead1(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
72 |
testRead2(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
73 |
testRead3(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
74 |
testWrite1(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
75 |
testWrite2(); |
11132
6b0ee6fede7a
7117717: (aio) Tests failing due to implementation bug 7052549
alanb
parents:
10071
diff
changeset
|
76 |
// skip timeout tests until 7052549 is fixed |
6b0ee6fede7a
7117717: (aio) Tests failing due to implementation bug 7052549
alanb
parents:
10071
diff
changeset
|
77 |
if (!System.getProperty("os.name").startsWith("Windows")) |
6b0ee6fede7a
7117717: (aio) Tests failing due to implementation bug 7052549
alanb
parents:
10071
diff
changeset
|
78 |
testTimeout(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
79 |
testShutdown(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
80 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
81 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
82 |
static class Server implements Closeable { |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
83 |
private final ServerSocketChannel ssc; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
84 |
private final InetSocketAddress address; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
85 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
86 |
Server() throws IOException { |
49840
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
87 |
this(0); |
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
88 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
89 |
|
49840
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
90 |
Server(int recvBufSize) throws IOException { |
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
91 |
ssc = ServerSocketChannel.open(); |
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
92 |
if (recvBufSize > 0) { |
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
93 |
ssc.setOption(SO_RCVBUF, recvBufSize); |
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
94 |
} |
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
95 |
ssc.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); |
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
96 |
address = (InetSocketAddress)ssc.getLocalAddress(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
97 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
98 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
99 |
InetSocketAddress address() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
100 |
return address; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
101 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
102 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
103 |
SocketChannel accept() throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
104 |
return ssc.accept(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
105 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
106 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
107 |
public void close() throws IOException { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
108 |
ssc.close(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
109 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
110 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
111 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
112 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
113 |
static void testBind() throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
114 |
System.out.println("-- bind --"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
115 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
116 |
try (AsynchronousSocketChannel ch = AsynchronousSocketChannel.open()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
117 |
if (ch.getLocalAddress() != null) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
118 |
throw new RuntimeException("Local address should be 'null'"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
119 |
ch.bind(new InetSocketAddress(0)); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
120 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
121 |
// check local address after binding |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
122 |
InetSocketAddress local = (InetSocketAddress)ch.getLocalAddress(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
123 |
if (local.getPort() == 0) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
124 |
throw new RuntimeException("Unexpected port"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
125 |
if (!local.getAddress().isAnyLocalAddress()) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
126 |
throw new RuntimeException("Not bound to a wildcard address"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
127 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
128 |
// try to re-bind |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
129 |
try { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
130 |
ch.bind(new InetSocketAddress(0)); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
131 |
throw new RuntimeException("AlreadyBoundException expected"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
132 |
} catch (AlreadyBoundException x) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
133 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
134 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
135 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
136 |
// check ClosedChannelException |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
137 |
AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
138 |
ch.close(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
139 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
140 |
ch.bind(new InetSocketAddress(0)); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
141 |
throw new RuntimeException("ClosedChannelException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
142 |
} catch (ClosedChannelException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
143 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
144 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
145 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
146 |
static void testSocketOptions() throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
147 |
System.out.println("-- socket options --"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
148 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
149 |
try (AsynchronousSocketChannel ch = AsynchronousSocketChannel.open()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
150 |
ch.setOption(SO_RCVBUF, 128*1024) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
151 |
.setOption(SO_SNDBUF, 128*1024) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
152 |
.setOption(SO_REUSEADDR, true); |
6696
7201f23dae0d
6989190: SO_SNDBUF/SO_RCVBUF limits should only be checked when setsockopt fails (sol)
alanb
parents:
5970
diff
changeset
|
153 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
154 |
// check SO_SNDBUF/SO_RCVBUF limits |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
155 |
int before, after; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
156 |
before = ch.getOption(SO_SNDBUF); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
157 |
after = ch.setOption(SO_SNDBUF, Integer.MAX_VALUE).getOption(SO_SNDBUF); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
158 |
if (after < before) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
159 |
throw new RuntimeException("setOption caused SO_SNDBUF to decrease"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
160 |
before = ch.getOption(SO_RCVBUF); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
161 |
after = ch.setOption(SO_RCVBUF, Integer.MAX_VALUE).getOption(SO_RCVBUF); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
162 |
if (after < before) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
163 |
throw new RuntimeException("setOption caused SO_RCVBUF to decrease"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
164 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
165 |
ch.bind(new InetSocketAddress(0)); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
166 |
|
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
167 |
// default values |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
168 |
if (ch.getOption(SO_KEEPALIVE)) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
169 |
throw new RuntimeException("Default of SO_KEEPALIVE should be 'false'"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
170 |
if (ch.getOption(TCP_NODELAY)) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
171 |
throw new RuntimeException("Default of TCP_NODELAY should be 'false'"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
172 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
173 |
// set and check |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
174 |
if (!ch.setOption(SO_KEEPALIVE, true).getOption(SO_KEEPALIVE)) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
175 |
throw new RuntimeException("SO_KEEPALIVE did not change"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
176 |
if (!ch.setOption(TCP_NODELAY, true).getOption(TCP_NODELAY)) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
177 |
throw new RuntimeException("SO_KEEPALIVE did not change"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
178 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
179 |
// read others (can't check as actual value is implementation dependent) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
180 |
ch.getOption(SO_RCVBUF); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
181 |
ch.getOption(SO_SNDBUF); |
36115 | 182 |
|
183 |
Set<SocketOption<?>> options = ch.supportedOptions(); |
|
184 |
boolean reuseport = options.contains(SO_REUSEPORT); |
|
185 |
if (reuseport) { |
|
186 |
if (ch.getOption(SO_REUSEPORT)) |
|
187 |
throw new RuntimeException("Default of SO_REUSEPORT should be 'false'"); |
|
188 |
if (!ch.setOption(SO_REUSEPORT, true).getOption(SO_REUSEPORT)) |
|
189 |
throw new RuntimeException("SO_REUSEPORT did not change"); |
|
190 |
} |
|
50303
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
191 |
List<? extends SocketOption> extOptions = List.of(TCP_KEEPCOUNT, |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
192 |
TCP_KEEPIDLE, TCP_KEEPINTERVAL); |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
193 |
if (options.containsAll(extOptions)) { |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
194 |
ch.setOption(TCP_KEEPIDLE, 1234); |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
195 |
checkOption(ch, TCP_KEEPIDLE, 1234); |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
196 |
ch.setOption(TCP_KEEPINTERVAL, 123); |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
197 |
checkOption(ch, TCP_KEEPINTERVAL, 123); |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
198 |
ch.setOption(TCP_KEEPCOUNT, 7); |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
199 |
checkOption(ch, TCP_KEEPCOUNT, 7); |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
200 |
} |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
201 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
202 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
203 |
|
50303
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
204 |
static void checkOption(AsynchronousSocketChannel sc, SocketOption name, Object expectedValue) |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
205 |
throws IOException { |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
206 |
Object value = sc.getOption(name); |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
207 |
if (!value.equals(expectedValue)) { |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
208 |
throw new RuntimeException("value not as expected"); |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
209 |
} |
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49840
diff
changeset
|
210 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
211 |
static void testConnect() throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
212 |
System.out.println("-- connect --"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
213 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
214 |
SocketAddress address; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
215 |
|
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
216 |
try (Server server = new Server()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
217 |
address = server.address(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
218 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
219 |
// connect to server and check local/remote addresses |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
220 |
try (AsynchronousSocketChannel ch = AsynchronousSocketChannel.open()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
221 |
ch.connect(address).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
222 |
// check local address |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
223 |
if (ch.getLocalAddress() == null) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
224 |
throw new RuntimeException("Not bound to local address"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
225 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
226 |
// check remote address |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
227 |
InetSocketAddress remote = (InetSocketAddress)ch.getRemoteAddress(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
228 |
if (remote.getPort() != server.address().getPort()) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
229 |
throw new RuntimeException("Connected to unexpected port"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
230 |
if (!remote.getAddress().equals(server.address().getAddress())) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
231 |
throw new RuntimeException("Connected to unexpected address"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
232 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
233 |
// try to connect again |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
234 |
try { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
235 |
ch.connect(server.address()).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
236 |
throw new RuntimeException("AlreadyConnectedException expected"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
237 |
} catch (AlreadyConnectedException x) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
238 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
239 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
240 |
// clean-up |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
241 |
server.accept().close(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
242 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
243 |
|
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
244 |
// check that connect fails with ClosedChannelException |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
245 |
AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
246 |
ch.close(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
247 |
try { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
248 |
ch.connect(server.address()).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
249 |
throw new RuntimeException("ExecutionException expected"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
250 |
} catch (ExecutionException x) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
251 |
if (!(x.getCause() instanceof ClosedChannelException)) |
42158
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
252 |
throw new RuntimeException("Cause of ClosedChannelException expected", |
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
253 |
x.getCause()); |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
254 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
255 |
final AtomicReference<Throwable> connectException = new AtomicReference<>(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
256 |
ch.connect(server.address(), (Void)null, new CompletionHandler<Void,Void>() { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
257 |
public void completed(Void result, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
258 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
259 |
public void failed(Throwable exc, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
260 |
connectException.set(exc); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
261 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
262 |
}); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
263 |
while (connectException.get() == null) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
264 |
Thread.sleep(100); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
265 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
266 |
if (!(connectException.get() instanceof ClosedChannelException)) |
42158
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
267 |
throw new RuntimeException("ClosedChannelException expected", |
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
268 |
connectException.get()); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
269 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
270 |
|
5783
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
271 |
// test that failure to connect closes the channel |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
272 |
try (AsynchronousSocketChannel ch = AsynchronousSocketChannel.open()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
273 |
try { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
274 |
ch.connect(address).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
275 |
} catch (ExecutionException x) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
276 |
// failed to establish connection |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
277 |
if (ch.isOpen()) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
278 |
throw new RuntimeException("Channel should be closed"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
279 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
280 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
281 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
282 |
// repeat test by connecting to a (probably) non-existent host. This |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
283 |
// improves the chance that the connect will not fail immediately. |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
284 |
if (!skipSlowConnectTest) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
285 |
try (AsynchronousSocketChannel ch = AsynchronousSocketChannel.open()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
286 |
try { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
287 |
ch.connect(genSocketAddress()).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
288 |
} catch (ExecutionException x) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
289 |
// failed to establish connection |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
290 |
if (ch.isOpen()) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
291 |
throw new RuntimeException("Channel should be closed"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
292 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
293 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
294 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
295 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
296 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
297 |
static void testCloseWhenPending() throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
298 |
System.out.println("-- asynchronous close when connecting --"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
299 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
300 |
AsynchronousSocketChannel ch; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
301 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
302 |
// asynchronous close while connecting |
5783
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
303 |
ch = AsynchronousSocketChannel.open(); |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
304 |
Future<Void> connectResult = ch.connect(genSocketAddress()); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
305 |
|
5783
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
306 |
// give time to initiate the connect (SYN) |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
307 |
Thread.sleep(50); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
308 |
|
5783
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
309 |
// close |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
310 |
ch.close(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
311 |
|
5783
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
312 |
// check that exception is thrown in timely manner |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
313 |
try { |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
314 |
connectResult.get(5, TimeUnit.SECONDS); |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
315 |
} catch (TimeoutException x) { |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
316 |
throw new RuntimeException("AsynchronousCloseException not thrown"); |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
317 |
} catch (ExecutionException x) { |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
318 |
// expected |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
319 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
320 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
321 |
System.out.println("-- asynchronous close when reading --"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
322 |
|
49840
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
323 |
try (Server server = new Server(1)) { |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
324 |
ch = AsynchronousSocketChannel.open(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
325 |
ch.connect(server.address()).get(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
326 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
327 |
ByteBuffer dst = ByteBuffer.allocateDirect(100); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
328 |
Future<Integer> result = ch.read(dst); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
329 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
330 |
// attempt a second read - should fail with ReadPendingException |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
331 |
ByteBuffer buf = ByteBuffer.allocateDirect(100); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
332 |
try { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
333 |
ch.read(buf); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
334 |
throw new RuntimeException("ReadPendingException expected"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
335 |
} catch (ReadPendingException x) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
336 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
337 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
338 |
// close channel (should cause initial read to complete) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
339 |
ch.close(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
340 |
server.accept().close(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
341 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
342 |
// check that AsynchronousCloseException is thrown |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
343 |
try { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
344 |
result.get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
345 |
throw new RuntimeException("Should not read"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
346 |
} catch (ExecutionException x) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
347 |
if (!(x.getCause() instanceof AsynchronousCloseException)) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
348 |
throw new RuntimeException(x); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
349 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
350 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
351 |
System.out.println("-- asynchronous close when writing --"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
352 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
353 |
ch = AsynchronousSocketChannel.open(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
354 |
ch.connect(server.address()).get(); |
49840
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
355 |
SocketChannel peer = server.accept(); |
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
356 |
peer.setOption(SO_RCVBUF, 1); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
357 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
358 |
final AtomicReference<Throwable> writeException = |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
359 |
new AtomicReference<Throwable>(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
360 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
361 |
// write bytes to fill socket buffer |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
362 |
final AtomicInteger numCompleted = new AtomicInteger(); |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
363 |
ch.write(genBuffer(), ch, new CompletionHandler<Integer,AsynchronousSocketChannel>() { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
364 |
public void completed(Integer result, AsynchronousSocketChannel ch) { |
49840
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
365 |
System.out.println("completed write to async channel: " + result); |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
366 |
numCompleted.incrementAndGet(); |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
367 |
ch.write(genBuffer(), ch, this); |
49840
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
368 |
System.out.println("started another write to async channel: " + result); |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
369 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
370 |
public void failed(Throwable x, AsynchronousSocketChannel ch) { |
49840
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
371 |
System.out.println("failed write to async channel"); |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
372 |
writeException.set(x); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
373 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
374 |
}); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
375 |
|
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
376 |
// give time for socket buffer to fill up - |
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
377 |
// take pauses until the handler is no longer being invoked |
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
378 |
// because all writes are being pended which guarantees that |
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
379 |
// the internal channel state indicates it is writing |
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
380 |
int prevNumCompleted = numCompleted.get(); |
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
381 |
do { |
49840
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
382 |
Thread.sleep((long)(1000 * jdk.test.lib.Utils.TIMEOUT_FACTOR)); |
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
383 |
System.out.println("check if buffer is filled up"); |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
384 |
if (numCompleted.get() == prevNumCompleted) { |
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
385 |
break; |
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
386 |
} |
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
387 |
prevNumCompleted = numCompleted.get(); |
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
388 |
} while (true); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
389 |
|
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
390 |
// attempt a concurrent write - |
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
391 |
// should fail with WritePendingException |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
392 |
try { |
49840
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
393 |
System.out.println("concurrent write to async channel"); |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
394 |
ch.write(genBuffer()); |
49840
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
395 |
System.out.format("prevNumCompleted: %d, numCompleted: %d%n", |
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
396 |
prevNumCompleted, numCompleted.get()); |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
397 |
throw new RuntimeException("WritePendingException expected"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
398 |
} catch (WritePendingException x) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
399 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
400 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
401 |
// close channel - should cause initial write to complete |
49840
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
402 |
System.out.println("closing async channel..."); |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
403 |
ch.close(); |
49840
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
404 |
System.out.println("closed async channel"); |
799e6e42b95f
8161991: java/nio/channels/AsynchronousSocketChannel/Basic.java failed due to RuntimeException: WritePendingException expected
mli
parents:
47216
diff
changeset
|
405 |
peer.close(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
406 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
407 |
// wait for exception |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
408 |
while (writeException.get() == null) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
409 |
Thread.sleep(100); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
410 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
411 |
if (!(writeException.get() instanceof AsynchronousCloseException)) |
42158
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
412 |
throw new RuntimeException("AsynchronousCloseException expected", |
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
413 |
writeException.get()); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
414 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
415 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
416 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
417 |
static void testCancel() throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
418 |
System.out.println("-- cancel --"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
419 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
420 |
try (Server server = new Server()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
421 |
for (int i=0; i<2; i++) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
422 |
boolean mayInterruptIfRunning = (i == 0) ? false : true; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
423 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
424 |
// establish loopback connection |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
425 |
AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
426 |
ch.connect(server.address()).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
427 |
SocketChannel peer = server.accept(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
428 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
429 |
// start read operation |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
430 |
ByteBuffer buf = ByteBuffer.allocate(1); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
431 |
Future<Integer> res = ch.read(buf); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
432 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
433 |
// cancel operation |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
434 |
boolean cancelled = res.cancel(mayInterruptIfRunning); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
435 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
436 |
// check post-conditions |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
437 |
if (!res.isDone()) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
438 |
throw new RuntimeException("isDone should return true"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
439 |
if (res.isCancelled() != cancelled) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
440 |
throw new RuntimeException("isCancelled not consistent"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
441 |
try { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
442 |
res.get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
443 |
throw new RuntimeException("CancellationException expected"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
444 |
} catch (CancellationException x) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
445 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
446 |
try { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
447 |
res.get(1, TimeUnit.SECONDS); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
448 |
throw new RuntimeException("CancellationException expected"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
449 |
} catch (CancellationException x) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
450 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
451 |
|
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
452 |
// check that the cancel doesn't impact writing to the channel |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
453 |
if (!mayInterruptIfRunning) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
454 |
buf = ByteBuffer.wrap("a".getBytes()); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
455 |
ch.write(buf).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
456 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
457 |
|
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
458 |
ch.close(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
459 |
peer.close(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
460 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
461 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
462 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
463 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
464 |
static void testRead1() throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
465 |
System.out.println("-- read (1) --"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
466 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
467 |
try (Server server = new Server()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
468 |
final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
469 |
ch.connect(server.address()).get(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
470 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
471 |
// read with 0 bytes remaining should complete immediately |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
472 |
ByteBuffer buf = ByteBuffer.allocate(1); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
473 |
buf.put((byte)0); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
474 |
int n = ch.read(buf).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
475 |
if (n != 0) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
476 |
throw new RuntimeException("0 expected"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
477 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
478 |
// write bytes and close connection |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
479 |
ByteBuffer src = genBuffer(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
480 |
try (SocketChannel sc = server.accept()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
481 |
sc.setOption(SO_SNDBUF, src.remaining()); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
482 |
while (src.hasRemaining()) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
483 |
sc.write(src); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
484 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
485 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
486 |
// reads should complete immediately |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
487 |
final ByteBuffer dst = ByteBuffer.allocateDirect(src.capacity() + 100); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
488 |
final CountDownLatch latch = new CountDownLatch(1); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
489 |
ch.read(dst, (Void)null, new CompletionHandler<Integer,Void>() { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
490 |
public void completed(Integer result, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
491 |
int n = result; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
492 |
if (n > 0) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
493 |
ch.read(dst, (Void)null, this); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
494 |
} else { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
495 |
latch.countDown(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
496 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
497 |
} |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
498 |
public void failed(Throwable exc, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
499 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
500 |
}); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
501 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
502 |
latch.await(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
503 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
504 |
// check buffers |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
505 |
src.flip(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
506 |
dst.flip(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
507 |
if (!src.equals(dst)) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
508 |
throw new RuntimeException("Contents differ"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
509 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
510 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
511 |
// close channel |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
512 |
ch.close(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
513 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
514 |
// check read fails with ClosedChannelException |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
515 |
try { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
516 |
ch.read(dst).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
517 |
throw new RuntimeException("ExecutionException expected"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
518 |
} catch (ExecutionException x) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
519 |
if (!(x.getCause() instanceof ClosedChannelException)) |
42158
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
520 |
throw new RuntimeException("Cause of ClosedChannelException expected", |
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
521 |
x.getCause()); |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
522 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
523 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
524 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
525 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
526 |
static void testRead2() throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
527 |
System.out.println("-- read (2) --"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
528 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
529 |
try (Server server = new Server()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
530 |
final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
531 |
ch.connect(server.address()).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
532 |
SocketChannel sc = server.accept(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
533 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
534 |
ByteBuffer src = genBuffer(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
535 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
536 |
// read until the buffer is full |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
537 |
final ByteBuffer dst = ByteBuffer.allocateDirect(src.capacity()); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
538 |
final CountDownLatch latch = new CountDownLatch(1); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
539 |
ch.read(dst, (Void)null, new CompletionHandler<Integer,Void>() { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
540 |
public void completed(Integer result, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
541 |
if (dst.hasRemaining()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
542 |
ch.read(dst, (Void)null, this); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
543 |
} else { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
544 |
latch.countDown(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
545 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
546 |
} |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
547 |
public void failed(Throwable exc, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
548 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
549 |
}); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
550 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
551 |
// trickle the writing |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
552 |
do { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
553 |
int rem = src.remaining(); |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
554 |
int size = (rem <= 100) ? rem : 50 + RAND.nextInt(rem - 100); |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
555 |
ByteBuffer buf = ByteBuffer.allocate(size); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
556 |
for (int i=0; i<size; i++) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
557 |
buf.put(src.get()); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
558 |
buf.flip(); |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
559 |
Thread.sleep(50 + RAND.nextInt(1500)); |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
560 |
while (buf.hasRemaining()) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
561 |
sc.write(buf); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
562 |
} while (src.hasRemaining()); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
563 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
564 |
// wait until ascynrhonous reading has completed |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
565 |
latch.await(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
566 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
567 |
// check buffers |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
568 |
src.flip(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
569 |
dst.flip(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
570 |
if (!src.equals(dst)) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
571 |
throw new RuntimeException("Contents differ"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
572 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
573 |
|
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
574 |
sc.close(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
575 |
ch.close(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
576 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
577 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
578 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
579 |
// exercise scattering read |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
580 |
static void testRead3() throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
581 |
System.out.println("-- read (3) --"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
582 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
583 |
try (Server server = new Server()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
584 |
final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
585 |
ch.connect(server.address()).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
586 |
SocketChannel sc = server.accept(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
587 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
588 |
ByteBuffer[] dsts = new ByteBuffer[3]; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
589 |
for (int i=0; i<dsts.length; i++) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
590 |
dsts[i] = ByteBuffer.allocateDirect(100); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
591 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
592 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
593 |
// scattering read that completes ascynhronously |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
594 |
final CountDownLatch l1 = new CountDownLatch(1); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
595 |
ch.read(dsts, 0, dsts.length, 0L, TimeUnit.SECONDS, (Void)null, |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
596 |
new CompletionHandler<Long,Void>() { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
597 |
public void completed(Long result, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
598 |
long n = result; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
599 |
if (n <= 0) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
600 |
throw new RuntimeException("No bytes read"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
601 |
l1.countDown(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
602 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
603 |
public void failed(Throwable exc, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
604 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
605 |
}); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
606 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
607 |
// write some bytes |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
608 |
sc.write(genBuffer()); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
609 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
610 |
// read should now complete |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
611 |
l1.await(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
612 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
613 |
// write more bytes |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
614 |
sc.write(genBuffer()); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
615 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
616 |
// read should complete immediately |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
617 |
for (int i=0; i<dsts.length; i++) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
618 |
dsts[i].rewind(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
619 |
} |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
3327
diff
changeset
|
620 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
621 |
final CountDownLatch l2 = new CountDownLatch(1); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
622 |
ch.read(dsts, 0, dsts.length, 0L, TimeUnit.SECONDS, (Void)null, |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
623 |
new CompletionHandler<Long,Void>() { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
624 |
public void completed(Long result, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
625 |
long n = result; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
626 |
if (n <= 0) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
627 |
throw new RuntimeException("No bytes read"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
628 |
l2.countDown(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
629 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
630 |
public void failed(Throwable exc, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
631 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
632 |
}); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
633 |
l2.await(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
634 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
635 |
ch.close(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
636 |
sc.close(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
637 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
638 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
639 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
640 |
static void testWrite1() throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
641 |
System.out.println("-- write (1) --"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
642 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
643 |
try (Server server = new Server()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
644 |
final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
645 |
ch.connect(server.address()).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
646 |
SocketChannel sc = server.accept(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
647 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
648 |
// write with 0 bytes remaining should complete immediately |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
649 |
ByteBuffer buf = ByteBuffer.allocate(1); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
650 |
buf.put((byte)0); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
651 |
int n = ch.write(buf).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
652 |
if (n != 0) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
653 |
throw new RuntimeException("0 expected"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
654 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
655 |
// write all bytes and close connection when done |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
656 |
final ByteBuffer src = genBuffer(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
657 |
ch.write(src, (Void)null, new CompletionHandler<Integer,Void>() { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
658 |
public void completed(Integer result, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
659 |
if (src.hasRemaining()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
660 |
ch.write(src, (Void)null, this); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
661 |
} else { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
662 |
try { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
663 |
ch.close(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
664 |
} catch (IOException ignore) { } |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
665 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
666 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
667 |
public void failed(Throwable exc, Void att) { |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
668 |
} |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
669 |
}); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
670 |
|
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
671 |
// read to EOF or buffer full |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
672 |
ByteBuffer dst = ByteBuffer.allocateDirect(src.capacity() + 100); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
673 |
do { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
674 |
n = sc.read(dst); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
675 |
} while (n > 0); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
676 |
sc.close(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
677 |
|
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
678 |
// check buffers |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
679 |
src.flip(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
680 |
dst.flip(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
681 |
if (!src.equals(dst)) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
682 |
throw new RuntimeException("Contents differ"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
683 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
684 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
685 |
// check write fails with ClosedChannelException |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
686 |
try { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
687 |
ch.read(dst).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
688 |
throw new RuntimeException("ExecutionException expected"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
689 |
} catch (ExecutionException x) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
690 |
if (!(x.getCause() instanceof ClosedChannelException)) |
42158
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
691 |
throw new RuntimeException("Cause of ClosedChannelException expected", |
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
692 |
x.getCause()); |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
693 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
694 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
695 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
696 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
697 |
// exercise gathering write |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
698 |
static void testWrite2() throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
699 |
System.out.println("-- write (2) --"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
700 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
701 |
try (Server server = new Server()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
702 |
final AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
703 |
ch.connect(server.address()).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
704 |
SocketChannel sc = server.accept(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
705 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
706 |
// number of bytes written |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
707 |
final AtomicLong bytesWritten = new AtomicLong(0); |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
3327
diff
changeset
|
708 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
709 |
// write buffers (should complete immediately) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
710 |
ByteBuffer[] srcs = genBuffers(1); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
711 |
final CountDownLatch l1 = new CountDownLatch(1); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
712 |
ch.write(srcs, 0, srcs.length, 0L, TimeUnit.SECONDS, (Void)null, |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
713 |
new CompletionHandler<Long,Void>() { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
714 |
public void completed(Long result, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
715 |
long n = result; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
716 |
if (n <= 0) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
717 |
throw new RuntimeException("No bytes read"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
718 |
bytesWritten.addAndGet(n); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
719 |
l1.countDown(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
720 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
721 |
public void failed(Throwable exc, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
722 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
723 |
}); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
724 |
l1.await(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
725 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
726 |
// set to true to signal that no more buffers should be written |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
727 |
final AtomicBoolean continueWriting = new AtomicBoolean(true); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
728 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
729 |
// write until socket buffer is full so as to create the conditions |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
730 |
// for when a write does not complete immediately |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
731 |
srcs = genBuffers(1); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
732 |
ch.write(srcs, 0, srcs.length, 0L, TimeUnit.SECONDS, (Void)null, |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
733 |
new CompletionHandler<Long,Void>() { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
734 |
public void completed(Long result, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
735 |
long n = result; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
736 |
if (n <= 0) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
737 |
throw new RuntimeException("No bytes written"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
738 |
bytesWritten.addAndGet(n); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
739 |
if (continueWriting.get()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
740 |
ByteBuffer[] srcs = genBuffers(8); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
741 |
ch.write(srcs, 0, srcs.length, 0L, TimeUnit.SECONDS, |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
742 |
(Void)null, this); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
743 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
744 |
} |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
745 |
public void failed(Throwable exc, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
746 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
747 |
}); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
748 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
749 |
// give time for socket buffer to fill up. |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
750 |
Thread.sleep(5*1000); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
751 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
752 |
// signal handler to stop further writing |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
753 |
continueWriting.set(false); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
754 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
755 |
// read until done |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
756 |
ByteBuffer buf = ByteBuffer.allocateDirect(4096); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
757 |
long total = 0L; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
758 |
do { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
759 |
int n = sc.read(buf); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
760 |
if (n <= 0) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
761 |
throw new RuntimeException("No bytes read"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
762 |
buf.rewind(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
763 |
total += n; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
764 |
} while (total < bytesWritten.get()); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
765 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
766 |
ch.close(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
767 |
sc.close(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
768 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
769 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
770 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
771 |
static void testShutdown() throws Exception { |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
772 |
System.out.println("-- shutdown --"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
773 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
774 |
try (Server server = new Server(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
775 |
AsynchronousSocketChannel ch = AsynchronousSocketChannel.open()) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
776 |
{ |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
777 |
ch.connect(server.address()).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
778 |
try (SocketChannel peer = server.accept()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
779 |
ByteBuffer buf = ByteBuffer.allocateDirect(1000); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
780 |
int n; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
781 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
782 |
// check read |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
783 |
ch.shutdownInput(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
784 |
n = ch.read(buf).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
785 |
if (n != -1) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
786 |
throw new RuntimeException("-1 expected"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
787 |
// check full with full buffer |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
788 |
buf.put(new byte[100]); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
789 |
n = ch.read(buf).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
790 |
if (n != -1) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
791 |
throw new RuntimeException("-1 expected"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
792 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
793 |
// check write |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
794 |
ch.shutdownOutput(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
795 |
try { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
796 |
ch.write(buf).get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
797 |
throw new RuntimeException("ClosedChannelException expected"); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
798 |
} catch (ExecutionException x) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
799 |
if (!(x.getCause() instanceof ClosedChannelException)) |
42158
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
800 |
throw new RuntimeException("ClosedChannelException expected", |
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
801 |
x.getCause()); |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
802 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
803 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
804 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
805 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
806 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
807 |
static void testTimeout() throws Exception { |
7298
895772293d6e
6878369: (ch) AsynchronousSocketChannel read/write methods that specify timeouts should not throw IAE
alanb
parents:
6696
diff
changeset
|
808 |
System.out.println("-- timeouts --"); |
895772293d6e
6878369: (ch) AsynchronousSocketChannel read/write methods that specify timeouts should not throw IAE
alanb
parents:
6696
diff
changeset
|
809 |
testTimeout(Integer.MIN_VALUE, TimeUnit.SECONDS); |
895772293d6e
6878369: (ch) AsynchronousSocketChannel read/write methods that specify timeouts should not throw IAE
alanb
parents:
6696
diff
changeset
|
810 |
testTimeout(-1L, TimeUnit.SECONDS); |
895772293d6e
6878369: (ch) AsynchronousSocketChannel read/write methods that specify timeouts should not throw IAE
alanb
parents:
6696
diff
changeset
|
811 |
testTimeout(0L, TimeUnit.SECONDS); |
895772293d6e
6878369: (ch) AsynchronousSocketChannel read/write methods that specify timeouts should not throw IAE
alanb
parents:
6696
diff
changeset
|
812 |
testTimeout(2L, TimeUnit.SECONDS); |
895772293d6e
6878369: (ch) AsynchronousSocketChannel read/write methods that specify timeouts should not throw IAE
alanb
parents:
6696
diff
changeset
|
813 |
} |
895772293d6e
6878369: (ch) AsynchronousSocketChannel read/write methods that specify timeouts should not throw IAE
alanb
parents:
6696
diff
changeset
|
814 |
|
895772293d6e
6878369: (ch) AsynchronousSocketChannel read/write methods that specify timeouts should not throw IAE
alanb
parents:
6696
diff
changeset
|
815 |
static void testTimeout(final long timeout, final TimeUnit unit) throws Exception { |
44111
bdec8d5e30da
8176317: (ch) Add print of timeout value to java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
44110
diff
changeset
|
816 |
System.out.printf("---- timeout: %d ms%n", unit.toMillis(timeout)); |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
817 |
try (Server server = new Server()) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
818 |
AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
819 |
ch.connect(server.address()).get(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
820 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
821 |
ByteBuffer dst = ByteBuffer.allocate(512); |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
3327
diff
changeset
|
822 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
823 |
final AtomicReference<Throwable> readException = new AtomicReference<Throwable>(); |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
3327
diff
changeset
|
824 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
825 |
// this read should timeout if value is > 0 |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
826 |
ch.read(dst, timeout, unit, null, new CompletionHandler<Integer,Void>() { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
827 |
public void completed(Integer result, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
828 |
readException.set(new RuntimeException("Should not complete")); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
829 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
830 |
public void failed(Throwable exc, Void att) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
831 |
readException.set(exc); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
832 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
833 |
}); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
834 |
if (timeout > 0L) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
835 |
// wait for exception |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
836 |
while (readException.get() == null) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
837 |
Thread.sleep(100); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
838 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
839 |
if (!(readException.get() instanceof InterruptedByTimeoutException)) |
42158
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
840 |
throw new RuntimeException("InterruptedByTimeoutException expected", |
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
841 |
readException.get()); |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
842 |
|
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
843 |
// after a timeout then further reading should throw unspecified runtime exception |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
844 |
boolean exceptionThrown = false; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
845 |
try { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
846 |
ch.read(dst); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
847 |
} catch (RuntimeException x) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
848 |
exceptionThrown = true; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
849 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
850 |
if (!exceptionThrown) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
851 |
throw new RuntimeException("RuntimeException expected after timeout."); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
852 |
} else { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
853 |
Thread.sleep(1000); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
854 |
Throwable exc = readException.get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
855 |
if (exc != null) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
856 |
throw new RuntimeException(exc); |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
3327
diff
changeset
|
857 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
858 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
859 |
final AtomicReference<Throwable> writeException = new AtomicReference<Throwable>(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
860 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
861 |
// write bytes to fill socket buffer |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
862 |
ch.write(genBuffer(), timeout, unit, ch, |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
863 |
new CompletionHandler<Integer,AsynchronousSocketChannel>() |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
864 |
{ |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
865 |
public void completed(Integer result, AsynchronousSocketChannel ch) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
866 |
ch.write(genBuffer(), timeout, unit, ch, this); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
867 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
868 |
public void failed(Throwable exc, AsynchronousSocketChannel ch) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
869 |
writeException.set(exc); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
870 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
871 |
}); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
872 |
if (timeout > 0) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
873 |
// wait for exception |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
874 |
while (writeException.get() == null) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
875 |
Thread.sleep(100); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
876 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
877 |
if (!(writeException.get() instanceof InterruptedByTimeoutException)) |
42158
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
878 |
throw new RuntimeException("InterruptedByTimeoutException expected", |
80c04775edbd
8169764: output more information when java/nio/channels/AsynchronousSocketChannel/Basic.java fails
mli
parents:
37817
diff
changeset
|
879 |
writeException.get()); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
880 |
|
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
881 |
// after a timeout then further writing should throw unspecified runtime exception |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
882 |
boolean exceptionThrown = false; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
883 |
try { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
884 |
ch.write(genBuffer()); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
885 |
} catch (RuntimeException x) { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
886 |
exceptionThrown = true; |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
887 |
} |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
888 |
if (!exceptionThrown) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
889 |
throw new RuntimeException("RuntimeException expected after timeout."); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
890 |
} else { |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
891 |
Thread.sleep(1000); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
892 |
Throwable exc = writeException.get(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
893 |
if (exc != null) |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
894 |
throw new RuntimeException(exc); |
7298
895772293d6e
6878369: (ch) AsynchronousSocketChannel read/write methods that specify timeouts should not throw IAE
alanb
parents:
6696
diff
changeset
|
895 |
} |
10071
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
896 |
|
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
897 |
// clean-up |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
898 |
server.accept().close(); |
fa021581a1ba
6965150: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java takes too long
alanb
parents:
9679
diff
changeset
|
899 |
ch.close(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
900 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
901 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
902 |
|
5783
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
903 |
// returns ByteBuffer with random bytes |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
904 |
static ByteBuffer genBuffer() { |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
905 |
int size = 1024 + RAND.nextInt(16000); |
5783
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
906 |
byte[] buf = new byte[size]; |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
907 |
RAND.nextBytes(buf); |
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
908 |
boolean useDirect = RAND.nextBoolean(); |
5783
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
909 |
if (useDirect) { |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
910 |
ByteBuffer bb = ByteBuffer.allocateDirect(buf.length); |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
911 |
bb.put(buf); |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
912 |
bb.flip(); |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
913 |
return bb; |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
914 |
} else { |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
915 |
return ByteBuffer.wrap(buf); |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
916 |
} |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
917 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
918 |
|
5783
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
919 |
// return ByteBuffer[] with random bytes |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
920 |
static ByteBuffer[] genBuffers(int max) { |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
921 |
int len = 1; |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
922 |
if (max > 1) |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
923 |
len += RAND.nextInt(max); |
5783
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
924 |
ByteBuffer[] bufs = new ByteBuffer[len]; |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
925 |
for (int i=0; i<len; i++) |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
926 |
bufs[i] = genBuffer(); |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
927 |
return bufs; |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
928 |
} |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
929 |
|
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
930 |
// return random SocketAddress |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
931 |
static SocketAddress genSocketAddress() { |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
932 |
StringBuilder sb = new StringBuilder("10."); |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
933 |
sb.append(RAND.nextInt(256)); |
5783
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
934 |
sb.append('.'); |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
935 |
sb.append(RAND.nextInt(256)); |
5783
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
936 |
sb.append('.'); |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
937 |
sb.append(RAND.nextInt(256)); |
5783
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
938 |
InetAddress rh; |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
939 |
try { |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
940 |
rh = InetAddress.getByName(sb.toString()); |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
941 |
} catch (UnknownHostException x) { |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
942 |
throw new InternalError("Should not happen"); |
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
943 |
} |
44110
192a17e5bef2
8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java
bpb
parents:
42158
diff
changeset
|
944 |
return new InetSocketAddress(rh, RAND.nextInt(65535)+1); |
5783
a330d1984034
6934585: TEST_BUG: java/nio/channels/AsynchronousSocketChannel/Basic.java
alanb
parents:
5506
diff
changeset
|
945 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
946 |
} |