--- /dev/null 2018-06-20 11:01:03.657616567 -0700 +++ new/test/jdk/jdk/net/Sockets/rsocket/Selector/OpRead.java 2018-06-22 12:24:06.615671666 -0700 @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* @test + * @bug 8195160 + * @summary Test if OP_READ is detected with OP_WRITE in interestOps + * @requires (os.family == "linux") + * @library .. /test/lib + * @build RsocketTest + * @run main/othervm -Djava.net.preferIPv4Stack=true OpRead + */ + +import java.net.*; +import java.nio.*; +import java.nio.channels.*; +import java.util.*; +import jdk.net.Sockets; + +public class OpRead implements Runnable { + + static ServerSocketChannel ssc = null; + static SocketChannel sc = null; + static SocketChannel peer = null; + static InetAddress lh; + + static void test() throws Exception { + try { + lh = InetAddress.getLocalHost(); + ssc = Sockets.openRdmaServerSocketChannel().bind(new InetSocketAddress(lh, 0)); + + // loopback connection + sc = Sockets.openRdmaSocketChannel(); + Thread t = new Thread(new OpRead()); + t.start(); + + peer = ssc.accept(); + + // peer sends message so that "sc" will be readable + int n = peer.write(ByteBuffer.wrap("Hello".getBytes())); + assert n > 0; + + sc.configureBlocking(false); + + Selector selector = Sockets.openRdmaSelector(); + SelectionKey key = sc.register(selector, SelectionKey.OP_READ | + SelectionKey.OP_WRITE); + + boolean done = false; + int failCount = 0; + while (!done) { + int nSelected = selector.select(); + if (nSelected > 0) { + if (nSelected > 1) + throw new RuntimeException("More than one channel selected"); + Set keys = selector.selectedKeys(); + Iterator 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(); + } + } + + public void run() { + try { + sc.connect(new InetSocketAddress(lh, ssc.socket().getLocalPort())); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Test Failed!"); + } + } + + public static void main(String[] args) throws Exception { + if (!RsocketTest.isRsocketAvailable()) + return; + + test(); + } + +}