author | alanb |
Fri, 14 Sep 2018 16:56:09 +0100 | |
changeset 51745 | 90c1dcdebc64 |
parent 49527 | 5aa40f834b50 |
permissions | -rw-r--r-- |
49527
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
1 |
/* |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
4 |
* |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
8 |
* |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
13 |
* accompanied this code). |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
14 |
* |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
18 |
* |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
21 |
* questions. |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
22 |
*/ |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
23 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
24 |
/* @test |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
25 |
* @run testng UpdateReadyOps |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
26 |
* @summary Test that the ready set from a selection operation is bitwise-disjoined |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
27 |
* into a key's ready set when the key is already in the selected-key set |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
28 |
*/ |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
29 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
30 |
import java.io.Closeable; |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
31 |
import java.io.IOException; |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
32 |
import java.net.InetAddress; |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
33 |
import java.net.InetSocketAddress; |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
34 |
import java.nio.ByteBuffer; |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
35 |
import java.nio.channels.SelectionKey; |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
36 |
import java.nio.channels.Selector; |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
37 |
import java.nio.channels.ServerSocketChannel; |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
38 |
import java.nio.channels.SocketChannel; |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
39 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
40 |
import org.testng.annotations.Test; |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
41 |
import static org.testng.Assert.*; |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
42 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
43 |
@Test |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
44 |
public class UpdateReadyOps { |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
45 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
46 |
/** |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
47 |
* Test that OP_WRITE is preserved when updating the ready set of a key in |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
48 |
* the selected-key set to add OP_READ. |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
49 |
*/ |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
50 |
public void testOpWritePreserved() throws Exception { |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
51 |
try (ConnectionPair pair = new ConnectionPair(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
52 |
Selector sel = Selector.open()) { |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
53 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
54 |
SocketChannel sc1 = pair.channel1(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
55 |
SocketChannel sc2 = pair.channel2(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
56 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
57 |
sc1.configureBlocking(false); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
58 |
SelectionKey key = sc1.register(sel, SelectionKey.OP_WRITE); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
59 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
60 |
int updated = sel.select(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
61 |
assertTrue(updated == 1); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
62 |
assertTrue(sel.selectedKeys().contains(key)); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
63 |
assertFalse(key.isReadable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
64 |
assertTrue(key.isWritable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
65 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
66 |
// select again, should be no updates |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
67 |
updated = sel.select(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
68 |
assertTrue(updated == 0); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
69 |
assertTrue(sel.selectedKeys().contains(key)); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
70 |
assertFalse(key.isReadable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
71 |
assertTrue(key.isWritable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
72 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
73 |
// write some bytes |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
74 |
sc2.write(helloMessage()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
75 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
76 |
// change interest ops to OP_READ, do a selection operation, and |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
77 |
// check that the ready set becomes OP_READ|OP_WRITE. |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
78 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
79 |
key.interestOps(SelectionKey.OP_READ); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
80 |
updated = sel.select(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
81 |
assertTrue(updated == 1); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
82 |
assertTrue(sel.selectedKeys().size() == 1); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
83 |
assertTrue(key.isReadable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
84 |
assertTrue(key.isWritable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
85 |
assertTrue(key.readyOps() == (SelectionKey.OP_READ|SelectionKey.OP_WRITE)); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
86 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
87 |
// select again, should be no updates |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
88 |
updated = sel.select(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
89 |
assertTrue(updated == 0); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
90 |
assertTrue(sel.selectedKeys().size() == 1); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
91 |
assertTrue(key.isReadable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
92 |
assertTrue(key.isWritable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
93 |
} |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
94 |
} |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
95 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
96 |
/** |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
97 |
* Test that OP_READ is preserved when updating the ready set of a key in |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
98 |
* the selected-key set to add OP_WRITE. |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
99 |
*/ |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
100 |
public void testOpReadPreserved() throws Exception { |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
101 |
try (ConnectionPair pair = new ConnectionPair(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
102 |
Selector sel = Selector.open()) { |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
103 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
104 |
SocketChannel sc1 = pair.channel1(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
105 |
SocketChannel sc2 = pair.channel2(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
106 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
107 |
sc1.configureBlocking(false); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
108 |
SelectionKey key = sc1.register(sel, SelectionKey.OP_READ); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
109 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
110 |
// write some bytes |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
111 |
sc2.write(helloMessage()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
112 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
113 |
int updated = sel.select(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
114 |
assertTrue(updated == 1); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
115 |
assertTrue(sel.selectedKeys().size() == 1); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
116 |
assertTrue(sel.selectedKeys().contains(key)); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
117 |
assertTrue(key.isReadable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
118 |
assertFalse(key.isWritable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
119 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
120 |
// select again, should be no updates |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
121 |
updated = sel.select(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
122 |
assertTrue(updated == 0); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
123 |
assertTrue(sel.selectedKeys().contains(key)); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
124 |
assertTrue(key.isReadable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
125 |
assertFalse(key.isWritable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
126 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
127 |
key.interestOps(SelectionKey.OP_WRITE); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
128 |
updated = sel.select(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
129 |
assertTrue(updated == 1); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
130 |
assertTrue(sel.selectedKeys().size() == 1); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
131 |
assertTrue(sel.selectedKeys().contains(key)); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
132 |
assertTrue(key.isReadable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
133 |
assertTrue(key.isWritable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
134 |
assertTrue(key.readyOps() == (SelectionKey.OP_READ|SelectionKey.OP_WRITE)); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
135 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
136 |
// select again, should be no updates |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
137 |
updated = sel.select(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
138 |
assertTrue(updated == 0); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
139 |
assertTrue(sel.selectedKeys().size() == 1); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
140 |
assertTrue(key.isReadable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
141 |
assertTrue(key.isWritable()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
142 |
} |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
143 |
} |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
144 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
145 |
static class ConnectionPair implements Closeable { |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
146 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
147 |
private final SocketChannel sc1; |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
148 |
private final SocketChannel sc2; |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
149 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
150 |
ConnectionPair() throws IOException { |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
151 |
InetAddress lb = InetAddress.getLoopbackAddress(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
152 |
try (ServerSocketChannel ssc = ServerSocketChannel.open()) { |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
153 |
ssc.bind(new InetSocketAddress(lb, 0)); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
154 |
this.sc1 = SocketChannel.open(ssc.getLocalAddress()); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
155 |
this.sc2 = ssc.accept(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
156 |
} |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
157 |
} |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
158 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
159 |
SocketChannel channel1() { |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
160 |
return sc1; |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
161 |
} |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
162 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
163 |
SocketChannel channel2() { |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
164 |
return sc2; |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
165 |
} |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
166 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
167 |
public void close() throws IOException { |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
168 |
sc1.close(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
169 |
sc2.close(); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
170 |
} |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
171 |
} |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
172 |
|
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
173 |
static ByteBuffer helloMessage() throws Exception { |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
174 |
return ByteBuffer.wrap("hello".getBytes("UTF-8")); |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
175 |
} |
5aa40f834b50
8200458: (se) Readiness information previously recorded in the ready set not preserved
alanb
parents:
diff
changeset
|
176 |
} |