提交 1c84fcf0 编写于 作者: A alanb

6932744: TEST_BUG: java/nio/channels/Selector/OpRead.java failing

Reviewed-by: chegar
上级 ed15c7a1
...@@ -816,9 +816,6 @@ java/nio/channels/Channels/Basic2.java windows-5.0 ...@@ -816,9 +816,6 @@ java/nio/channels/Channels/Basic2.java windows-5.0
# Considered a stress test, can consume all resources. # Considered a stress test, can consume all resources.
java/nio/channels/Selector/LotsOfChannels.java generic-all java/nio/channels/Selector/LotsOfChannels.java generic-all
# Solaris sparcv9, just fails with exception
java/nio/channels/Selector/OpRead.java solaris-sparc
# Windows i586 client, crashed hotspot? Unpredictable # Windows i586 client, crashed hotspot? Unpredictable
# Considered a stress test, can consume all resources. # Considered a stress test, can consume all resources.
java/nio/channels/Selector/RegAfterPreClose.java generic-all java/nio/channels/Selector/RegAfterPreClose.java generic-all
......
...@@ -24,32 +24,34 @@ ...@@ -24,32 +24,34 @@
/* @test /* @test
* @bug 4755720 * @bug 4755720
* @summary Test if OP_READ is detected with OP_WRITE in interestOps * @summary Test if OP_READ is detected with OP_WRITE in interestOps
* @library ..
*/ */
import java.net.*; import java.net.*;
import java.io.*;
import java.nio.*; import java.nio.*;
import java.nio.channels.*; import java.nio.channels.*;
import java.nio.channels.spi.SelectorProvider;
import java.util.*; import java.util.*;
public class OpRead { public class OpRead {
static final int DAYTIME_PORT = 13;
static final String DAYTIME_HOST = TestUtil.HOST;
static void test() throws Exception { static void test() throws Exception {
InetSocketAddress isa ServerSocketChannel ssc = null;
= new InetSocketAddress(InetAddress.getByName(DAYTIME_HOST), SocketChannel sc = null;
DAYTIME_PORT); SocketChannel peer = null;
SocketChannel sc = SocketChannel.open(); try {
ssc = ServerSocketChannel.open().bind(new InetSocketAddress(0));
// loopback connection
InetAddress lh = InetAddress.getLocalHost();
sc = SocketChannel.open(new InetSocketAddress(lh, ssc.socket().getLocalPort()));
peer = ssc.accept();
sc.connect(isa); // peer sends message so that "sc" will be readable
int n = peer.write(ByteBuffer.wrap("Hello".getBytes()));
assert n > 0;
sc.configureBlocking(false); sc.configureBlocking(false);
Selector selector = SelectorProvider.provider().openSelector(); Selector selector = Selector.open();
SelectionKey key = sc.register(selector, SelectionKey.OP_READ | SelectionKey key = sc.register(selector, SelectionKey.OP_READ |
SelectionKey.OP_WRITE); SelectionKey.OP_WRITE);
...@@ -57,16 +59,16 @@ public class OpRead { ...@@ -57,16 +59,16 @@ public class OpRead {
int failCount = 0; int failCount = 0;
while (!done) { while (!done) {
if (selector.select() > 0) { if (selector.select() > 0) {
Set keys = selector.selectedKeys(); Set<SelectionKey> keys = selector.selectedKeys();
Iterator iterator = keys.iterator(); Iterator<SelectionKey> iterator = keys.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
key = (SelectionKey)iterator.next(); key = iterator.next();
iterator.remove(); iterator.remove();
if (key.isWritable()) { if (key.isWritable()) {
failCount++; failCount++;
if (failCount > 10) if (failCount > 10)
throw new RuntimeException("Test failed"); throw new RuntimeException("Test failed");
Thread.sleep(100); Thread.sleep(250);
} }
if (key.isReadable()) { if (key.isReadable()) {
done = true; done = true;
...@@ -74,9 +76,11 @@ public class OpRead { ...@@ -74,9 +76,11 @@ public class OpRead {
} }
} }
} }
} finally {
if (peer != null) peer.close();
sc.close(); if (sc != null) sc.close();
if (ssc != null) ssc.close();
}
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册