author | alanb |
Fri, 02 Nov 2012 15:50:11 +0000 | |
changeset 14342 | 8435a30053c1 |
parent 13415 | 0430f69eed3b |
child 22099 | 4ebb34ef007e |
permissions | -rw-r--r-- |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
13415
diff
changeset
|
2 |
* Copyright (c) 2008, 2012, 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 |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
25 |
* @bug 4607272 |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
26 |
* @summary Unit test for AsynchronousChannelGroup |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
27 |
* @build Basic |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
28 |
* @run main/othervm -XX:-UseVMInterruptibleIO Basic |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
29 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
30 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
31 |
import java.nio.ByteBuffer; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
32 |
import java.nio.channels.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
33 |
import java.net.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
34 |
import java.util.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
35 |
import java.util.concurrent.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
36 |
import java.io.IOException; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
37 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
38 |
public class Basic { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
39 |
static final Random rand = new Random(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
40 |
static final ThreadFactory threadFactory = new ThreadFactory() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
41 |
@Override |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
42 |
public Thread newThread(final Runnable r) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
43 |
return new Thread(r); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
44 |
}}; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
45 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
46 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
47 |
public static void main(String[] args) throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
48 |
shutdownTests(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
49 |
shutdownNowTests(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
50 |
afterShutdownTests(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
51 |
miscTests(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
52 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
53 |
|
13415
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
54 |
static void testShutdownWithNoChannels(ExecutorService pool, |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
55 |
AsynchronousChannelGroup group) |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
56 |
throws Exception |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
57 |
{ |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
58 |
group.shutdown(); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
59 |
if (!group.isShutdown()) |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
60 |
throw new RuntimeException("Group should be shutdown"); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
61 |
// group should terminate quickly |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
62 |
boolean terminated = group.awaitTermination(3, TimeUnit.SECONDS); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
63 |
if (!terminated) |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
64 |
throw new RuntimeException("Group should have terminated"); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
65 |
if (pool != null && !pool.isTerminated()) |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
66 |
throw new RuntimeException("Executor should have terminated"); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
67 |
} |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
68 |
|
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
69 |
static void testShutdownWithChannels(ExecutorService pool, |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
70 |
AsynchronousChannelGroup group) |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
71 |
throws Exception |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
72 |
{ |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
73 |
|
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
74 |
// create channel that is bound to group |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
75 |
AsynchronousChannel ch; |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
76 |
switch (rand.nextInt(2)) { |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
77 |
case 0 : ch = AsynchronousSocketChannel.open(group); break; |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
78 |
case 1 : ch = AsynchronousServerSocketChannel.open(group); break; |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
79 |
default : throw new AssertionError(); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
80 |
} |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
81 |
group.shutdown(); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
82 |
if (!group.isShutdown()) |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
83 |
throw new RuntimeException("Group should be shutdown"); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
84 |
|
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
85 |
// last channel so should terminate after this channel is closed |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
86 |
ch.close(); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
87 |
|
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
88 |
// group should terminate quickly |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
89 |
boolean terminated = group.awaitTermination(3, TimeUnit.SECONDS); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
90 |
if (!terminated) |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
91 |
throw new RuntimeException("Group should have terminated"); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
92 |
if (pool != null && !pool.isTerminated()) |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
93 |
throw new RuntimeException("Executor should have terminated"); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
94 |
} |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
95 |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
96 |
static void shutdownTests() throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
97 |
System.out.println("-- test shutdown --"); |
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 |
// test shutdown with no channels in groups |
13415
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
100 |
for (int i = 0; i < 100; i++) { |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
101 |
ExecutorService pool = Executors.newCachedThreadPool(); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
102 |
AsynchronousChannelGroup group = AsynchronousChannelGroup |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
103 |
.withCachedThreadPool(pool, rand.nextInt(5)); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
104 |
testShutdownWithNoChannels(pool, group); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
105 |
} |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
106 |
for (int i = 0; i < 100; i++) { |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
107 |
int nThreads = 1 + rand.nextInt(8); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
108 |
AsynchronousChannelGroup group = AsynchronousChannelGroup |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
109 |
.withFixedThreadPool(nThreads, threadFactory); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
110 |
testShutdownWithNoChannels(null, group); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
111 |
} |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
112 |
for (int i = 0; i < 100; i++) { |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
113 |
ExecutorService pool = Executors.newCachedThreadPool(); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
114 |
AsynchronousChannelGroup group = AsynchronousChannelGroup |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
115 |
.withThreadPool(pool); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
116 |
testShutdownWithNoChannels(pool, group); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
117 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
118 |
|
13415
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
119 |
// test shutdown with channel in group |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
120 |
for (int i = 0; i < 100; i++) { |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
121 |
ExecutorService pool = Executors.newCachedThreadPool(); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
122 |
AsynchronousChannelGroup group = AsynchronousChannelGroup |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
123 |
.withCachedThreadPool(pool, rand.nextInt(10)); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
124 |
testShutdownWithChannels(pool, group); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
125 |
} |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
126 |
for (int i = 0; i < 100; i++) { |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
127 |
int nThreads = 1 + rand.nextInt(8); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
128 |
AsynchronousChannelGroup group = AsynchronousChannelGroup |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
129 |
.withFixedThreadPool(nThreads, threadFactory); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
130 |
testShutdownWithChannels(null, group); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
131 |
} |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
132 |
for (int i = 0; i < 100; i++) { |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
133 |
ExecutorService pool = Executors.newCachedThreadPool(); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
134 |
AsynchronousChannelGroup group = AsynchronousChannelGroup |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
135 |
.withThreadPool(pool); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
136 |
testShutdownWithChannels(pool, group); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
137 |
} |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
138 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
139 |
|
13415
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
140 |
static void testShutdownNow(ExecutorService pool, |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
141 |
AsynchronousChannelGroup group) |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
142 |
throws Exception |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
143 |
{ |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
144 |
// I/O in progress |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
145 |
AsynchronousServerSocketChannel ch = AsynchronousServerSocketChannel |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
146 |
.open(group).bind(new InetSocketAddress(0)); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
147 |
ch.accept(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
148 |
|
13415
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
149 |
// forceful shutdown |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
150 |
group.shutdownNow(); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
151 |
|
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
152 |
// shutdownNow is required to close all channels |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
153 |
if (ch.isOpen()) |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
154 |
throw new RuntimeException("Channel should be closed"); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
155 |
|
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
156 |
boolean terminated = group.awaitTermination(3, TimeUnit.SECONDS); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
157 |
if (!terminated) |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
158 |
throw new RuntimeException("Group should have terminated"); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
159 |
if (pool != null && !pool.isTerminated()) |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
160 |
throw new RuntimeException("Executor should have terminated"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
161 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
162 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
163 |
static void shutdownNowTests() throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
164 |
System.out.println("-- test shutdownNow --"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
165 |
|
13415
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
166 |
for (int i = 0; i < 10; i++) { |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
167 |
ExecutorService pool = pool = Executors.newCachedThreadPool(); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
168 |
AsynchronousChannelGroup group = AsynchronousChannelGroup |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
169 |
.withCachedThreadPool(pool, rand.nextInt(5)); |
13415
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
170 |
testShutdownNow(pool, group); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
171 |
} |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
172 |
for (int i = 0; i < 10; i++) { |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
173 |
int nThreads = 1 + rand.nextInt(8); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
174 |
AsynchronousChannelGroup group = AsynchronousChannelGroup |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
175 |
.withFixedThreadPool(nThreads, threadFactory); |
13415
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
176 |
testShutdownNow(null, group); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
177 |
} |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
178 |
for (int i = 0; i < 10; i++) { |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
179 |
ExecutorService pool = Executors.newCachedThreadPool(); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
180 |
AsynchronousChannelGroup group = AsynchronousChannelGroup |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
181 |
.withThreadPool(pool); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
182 |
testShutdownNow(pool, group); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
183 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
184 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
185 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
186 |
// test creating channels in group after group is shutdown |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
187 |
static void afterShutdownTests() throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
188 |
System.out.println("-- test operations after group is shutdown --"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
189 |
AsynchronousChannelGroup group = |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
190 |
AsynchronousChannelGroup.withFixedThreadPool(1, threadFactory); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
191 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
192 |
AsynchronousSocketChannel ch = AsynchronousSocketChannel.open(group); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
193 |
AsynchronousServerSocketChannel listener = AsynchronousServerSocketChannel.open(group); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
194 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
195 |
// initiate accept |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
196 |
listener.bind(new InetSocketAddress(0)); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
197 |
Future<AsynchronousSocketChannel> result = listener.accept(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
198 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
199 |
// shutdown group |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
200 |
group.shutdown(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
201 |
if (!group.isShutdown()) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
202 |
throw new RuntimeException("Group should be shutdown"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
203 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
204 |
// attempt to create another channel |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
205 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
206 |
AsynchronousSocketChannel.open(group); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
207 |
throw new RuntimeException("ShutdownChannelGroupException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
208 |
} catch (ShutdownChannelGroupException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
209 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
210 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
211 |
AsynchronousServerSocketChannel.open(group); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
212 |
throw new RuntimeException("ShutdownChannelGroupException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
213 |
} catch (ShutdownChannelGroupException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
214 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
215 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
216 |
// attempt to create another channel by connecting. This should cause |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
217 |
// the accept operation to fail. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
218 |
InetAddress lh = InetAddress.getLocalHost(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
219 |
int port = ((InetSocketAddress)listener.getLocalAddress()).getPort(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
220 |
InetSocketAddress isa = new InetSocketAddress(lh, port); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
221 |
ch.connect(isa).get(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
222 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
223 |
result.get(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
224 |
throw new RuntimeException("Connection was accepted"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
225 |
} catch (ExecutionException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
226 |
Throwable cause = x.getCause(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
227 |
if (!(cause instanceof IOException)) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
228 |
throw new RuntimeException("Cause should be IOException"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
229 |
cause = cause.getCause(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
230 |
if (!(cause instanceof ShutdownChannelGroupException)) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
231 |
throw new RuntimeException("IOException cause should be ShutdownChannelGroupException"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
232 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
233 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
234 |
// initiate another accept even though channel group is shutdown. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
235 |
Future<AsynchronousSocketChannel> res = listener.accept(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
236 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
237 |
res.get(3, TimeUnit.SECONDS); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
238 |
throw new RuntimeException("TimeoutException expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
239 |
} catch (TimeoutException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
240 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
241 |
// connect to the listener which should cause the accept to complete |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
242 |
AsynchronousSocketChannel.open().connect(isa); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
243 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
244 |
res.get(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
245 |
throw new RuntimeException("Connection was accepted"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
246 |
} catch (ExecutionException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
247 |
Throwable cause = x.getCause(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
248 |
if (!(cause instanceof IOException)) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
249 |
throw new RuntimeException("Cause should be IOException"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
250 |
cause = cause.getCause(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
251 |
if (!(cause instanceof ShutdownChannelGroupException)) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
252 |
throw new RuntimeException("IOException cause should be ShutdownChannelGroupException"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
253 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
254 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
255 |
// group should *not* terminate as channels are open |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
256 |
boolean terminated = group.awaitTermination(3, TimeUnit.SECONDS); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
257 |
if (terminated) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
258 |
throw new RuntimeException("Group should not have terminated"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
259 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
260 |
// close channel; group should terminate quickly |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
261 |
ch.close(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
262 |
listener.close(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
263 |
terminated = group.awaitTermination(3, TimeUnit.SECONDS); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
264 |
if (!terminated) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
265 |
throw new RuntimeException("Group should have terminated"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
266 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
267 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
268 |
static void miscTests() throws Exception { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
269 |
System.out.println("-- miscellenous tests --"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
270 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
271 |
AsynchronousChannelGroup.withFixedThreadPool(1, null); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
272 |
throw new RuntimeException("NPE expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
273 |
} catch (NullPointerException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
274 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
275 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
276 |
AsynchronousChannelGroup.withFixedThreadPool(0, threadFactory); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
277 |
throw new RuntimeException("IAE expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
278 |
} catch (IllegalArgumentException e) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
279 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
280 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
281 |
AsynchronousChannelGroup.withCachedThreadPool(null, 0); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
282 |
throw new RuntimeException("NPE expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
283 |
} catch (NullPointerException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
284 |
} |
13415
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
285 |
try { |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
286 |
AsynchronousChannelGroup.withThreadPool(null); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
287 |
throw new RuntimeException("NPE expected"); |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
288 |
} catch (NullPointerException e) { |
0430f69eed3b
7189886: (aio) Add test coverage for AsynchronousChannelGroup.withThreadPool
alanb
parents:
7668
diff
changeset
|
289 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
290 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
291 |
} |