提交 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,59 +24,63 @@ ...@@ -24,59 +24,63 @@
/* @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));
sc.connect(isa); // loopback connection
InetAddress lh = InetAddress.getLocalHost();
sc = SocketChannel.open(new InetSocketAddress(lh, ssc.socket().getLocalPort()));
peer = ssc.accept();
sc.configureBlocking(false); // peer sends message so that "sc" will be readable
int n = peer.write(ByteBuffer.wrap("Hello".getBytes()));
assert n > 0;
Selector selector = SelectorProvider.provider().openSelector(); sc.configureBlocking(false);
SelectionKey key = sc.register(selector, SelectionKey.OP_READ |
SelectionKey.OP_WRITE);
boolean done = false; Selector selector = Selector.open();
int failCount = 0; SelectionKey key = sc.register(selector, SelectionKey.OP_READ |
while (!done) { SelectionKey.OP_WRITE);
if (selector.select() > 0) {
Set keys = selector.selectedKeys(); boolean done = false;
Iterator iterator = keys.iterator(); int failCount = 0;
while (iterator.hasNext()) { while (!done) {
key = (SelectionKey)iterator.next(); if (selector.select() > 0) {
iterator.remove(); Set<SelectionKey> keys = selector.selectedKeys();
if (key.isWritable()) { Iterator<SelectionKey> iterator = keys.iterator();
failCount++; while (iterator.hasNext()) {
if (failCount > 10) key = iterator.next();
throw new RuntimeException("Test failed"); iterator.remove();
Thread.sleep(100); if (key.isWritable()) {
} failCount++;
if (key.isReadable()) { if (failCount > 10)
done = true; throw new RuntimeException("Test failed");
Thread.sleep(250);
}
if (key.isReadable()) {
done = true;
}
} }
} }
} }
} finally {
if (peer != null) peer.close();
if (sc != null) sc.close();
if (ssc != null) ssc.close();
} }
sc.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.
先完成此消息的编辑!
想要评论请 注册