OpenJDK / bsd-port / jdk9 / jdk
changeset 2480:72022d7d4578
6932744: TEST_BUG: java/nio/channels/Selector/OpRead.java failing
Reviewed-by: chegar
author | alanb |
---|---|
date | Tue, 15 Jun 2010 16:36:20 +0100 |
parents | 76a9c90e9019 |
children | 91124d60b2ed |
files | test/ProblemList.txt test/java/nio/channels/Selector/OpRead.java |
diffstat | 2 files changed, 40 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/test/ProblemList.txt Tue Jun 15 10:03:37 2010 +0100 +++ b/test/ProblemList.txt Tue Jun 15 16:36:20 2010 +0100 @@ -816,9 +816,6 @@ # Considered a stress test, can consume all resources. 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 # Considered a stress test, can consume all resources. java/nio/channels/Selector/RegAfterPreClose.java generic-all
--- a/test/java/nio/channels/Selector/OpRead.java Tue Jun 15 10:03:37 2010 +0100 +++ b/test/java/nio/channels/Selector/OpRead.java Tue Jun 15 16:36:20 2010 +0100 @@ -24,59 +24,63 @@ /* @test * @bug 4755720 * @summary Test if OP_READ is detected with OP_WRITE in interestOps - * @library .. */ import java.net.*; -import java.io.*; import java.nio.*; import java.nio.channels.*; -import java.nio.channels.spi.SelectorProvider; import java.util.*; public class OpRead { - static final int DAYTIME_PORT = 13; - static final String DAYTIME_HOST = TestUtil.HOST; + static void test() throws Exception { + ServerSocketChannel ssc = null; + SocketChannel sc = null; + SocketChannel peer = null; + try { + ssc = ServerSocketChannel.open().bind(new InetSocketAddress(0)); - static void test() throws Exception { - InetSocketAddress isa - = new InetSocketAddress(InetAddress.getByName(DAYTIME_HOST), - DAYTIME_PORT); - SocketChannel sc = SocketChannel.open(); + // loopback connection + InetAddress lh = InetAddress.getLocalHost(); + sc = SocketChannel.open(new InetSocketAddress(lh, ssc.socket().getLocalPort())); + peer = ssc.accept(); - sc.connect(isa); - - 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(); - SelectionKey key = sc.register(selector, SelectionKey.OP_READ | - SelectionKey.OP_WRITE); + sc.configureBlocking(false); - boolean done = false; - int failCount = 0; - while (!done) { - if (selector.select() > 0) { - Set keys = selector.selectedKeys(); - Iterator iterator = keys.iterator(); - while (iterator.hasNext()) { - key = (SelectionKey)iterator.next(); - iterator.remove(); - if (key.isWritable()) { - failCount++; - if (failCount > 10) - throw new RuntimeException("Test failed"); - Thread.sleep(100); - } - if (key.isReadable()) { - done = true; + Selector selector = Selector.open(); + SelectionKey key = sc.register(selector, SelectionKey.OP_READ | + SelectionKey.OP_WRITE); + + boolean done = false; + int failCount = 0; + while (!done) { + if (selector.select() > 0) { + Set<SelectionKey> keys = selector.selectedKeys(); + Iterator<SelectionKey> iterator = keys.iterator(); + while (iterator.hasNext()) { + key = iterator.next(); + iterator.remove(); + if (key.isWritable()) { + failCount++; + if (failCount > 10) + 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 {