< prev index next >

test/jdk/jdk/net/RdmaSockets/rsocket/Selector/Connect.java

Print this page
rev 53031 : [mq]: selector_Connect
rev 53029 : imported patch jdk12-8195160-version25.patch


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 8195160
  26  * @summary Test Test Making lots of Selectors
  27  * @requires (os.family == "linux")
  28  * @library .. /test/lib
  29  * @build jdk.test.lib.Utils TestServers
  30  * @build RsocketTest
  31  * @run main/othervm Connect
  32  */
  33 
  34 import java.net.InetAddress;
  35 import java.net.InetSocketAddress;
  36 import java.net.StandardProtocolFamily;
  37 import java.nio.ByteBuffer;
  38 import java.nio.channels.SelectionKey;
  39 import java.nio.channels.Selector;
  40 import java.nio.channels.SocketChannel;
  41 import java.nio.channels.spi.SelectorProvider;
  42 import java.util.Iterator;
  43 import java.util.Set;
  44 import jdk.net.RdmaSockets;
  45 
  46 import jtreg.SkippedException;

  47 
  48 public class Connect implements Runnable {
  49 
  50     static int success = 0;
  51     static int LIMIT = 30;
  52     static SocketChannel sc;
  53     static InetSocketAddress isa;
  54     static boolean connected;
  55     
  56     public static void main(String[] args) throws Exception {
  57         if (!RsocketTest.isRsocketAvailable())
  58             throw new SkippedException("rsocket is not available");
  59 
  60         try (TestServers.DayTimeServer daytimeServer
  61                 = TestServers.DayTimeServer.startNewServer(50)) {
  62             scaleTest(daytimeServer);
  63         }
  64     }
  65 
  66     static void scaleTest(TestServers.DayTimeServer daytimeServer)
  67         throws Exception
  68     {
  69         InetAddress myAddress = daytimeServer.getAddress();
  70         isa = new InetSocketAddress(myAddress, daytimeServer.getPort());
  71 
  72         for (int j=0; j<LIMIT; j++) {
  73             sc = RdmaSockets.openSocketChannel(StandardProtocolFamily.INET);
  74             sc.configureBlocking(false);


  75 
  76             Thread t = new Thread (new Connect());
  77             t.start();
  78             t.join();
  79             if (!connected) {
  80                 Selector RSelector = RdmaSockets.openSelector();
  81                 SelectionKey RKey = sc.register (RSelector, SelectionKey.OP_CONNECT);
  82                 while (!connected) {
  83                     int keysAdded = RSelector.select(100);
  84                     if (keysAdded > 0) {
  85                         Set<SelectionKey> readyKeys = RSelector.selectedKeys();
  86                         Iterator<SelectionKey> i = readyKeys.iterator();
  87                         while (i.hasNext()) {
  88                             SelectionKey sk = i.next();
  89                             SocketChannel nextReady = (SocketChannel)sk.channel();
  90                             connected = nextReady.finishConnect();
  91                         }
  92                         readyKeys.clear();
  93                     }
  94                 }
  95                 RSelector.close();
  96             }
  97             readAndClose(sc);
  98         }
  99     }
 100 
 101     static void readAndClose(SocketChannel sc) throws Exception {
 102         ByteBuffer bb = ByteBuffer.allocateDirect(100);
 103         int n = 0;
 104         while (n == 0) // Note this is not a rigorous check for done reading
 105             n = sc.read(bb);
 106         sc.close();
 107         success++;
 108         System.out.println("success count = " + success);
 109     }
 110 
 111     public void run() {
 112         try {
 113             connected = sc.connect(isa);
 114             System.out.println("connected = " + connected);
 115         } catch (Exception e) {
 116             e.printStackTrace();
 117             throw new RuntimeException("Test Failed!");
 118         }
 119     }
 120 }


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 8195160
  26  * @summary Test making lots of Selectors
  27  * @requires (os.family == "linux")
  28  * @library .. /test/lib
  29  * @build jdk.test.lib.Utils TestServers
  30  * @build RsocketTest
  31  * @run main/othervm Connect
  32  */
  33 
  34 import java.net.InetAddress;
  35 import java.net.InetSocketAddress;

  36 import java.nio.ByteBuffer;
  37 import java.nio.channels.SelectionKey;
  38 import java.nio.channels.Selector;
  39 import java.nio.channels.SocketChannel;

  40 import java.util.Iterator;
  41 import java.util.Set;
  42 import jdk.net.RdmaSockets;

  43 import jtreg.SkippedException;
  44 import static java.net.StandardProtocolFamily.INET;
  45 
  46 public class Connect {
  47 
  48     static int success = 0;
  49     static final int LIMIT = 30;



  50 
  51     public static void main(String[] args) throws Exception {
  52         if (!RsocketTest.isRsocketAvailable())
  53             throw new SkippedException("rsocket is not available");
  54 
  55         try (TestServers.DayTimeServer daytimeServer
  56                 = TestServers.DayTimeServer.startNewServer(50)) {
  57             scaleTest(daytimeServer);
  58         }
  59     }
  60 
  61     static void scaleTest(TestServers.DayTimeServer daytimeServer)
  62         throws Exception
  63     {
  64         InetAddress myAddress = daytimeServer.getAddress();
  65         InetSocketAddress isa = new InetSocketAddress(myAddress, daytimeServer.getPort());
  66 
  67         for (int j=0; j<LIMIT; j++) {
  68             SocketChannel sc = RdmaSockets.openSocketChannel(INET);
  69             sc.configureBlocking(false);
  70             boolean connected = sc.connect(isa);
  71             System.out.println("connected = " + connected);
  72 



  73             if (!connected) {
  74                 Selector selector = RdmaSockets.openSelector();
  75                 sc.register(selector, SelectionKey.OP_CONNECT);
  76                 while (!connected) {
  77                     int keysAdded = selector.select(100);
  78                     if (keysAdded > 0) {
  79                         Set<SelectionKey> readyKeys = selector.selectedKeys();
  80                         Iterator<SelectionKey> i = readyKeys.iterator();
  81                         while (i.hasNext()) {
  82                             SelectionKey sk = i.next();
  83                             SocketChannel nextReady = (SocketChannel)sk.channel();
  84                             connected = nextReady.finishConnect();
  85                         }
  86                         readyKeys.clear();
  87                     }
  88                 }
  89                 selector.close();
  90             }
  91             readAndClose(sc);
  92         }
  93     }
  94 
  95     static void readAndClose(SocketChannel sc) throws Exception {
  96         ByteBuffer bb = ByteBuffer.allocateDirect(100);
  97         int n = 0;
  98         while (n == 0) // Note this is not a rigorous check for done reading
  99             n = sc.read(bb);
 100         sc.close();
 101         success++;
 102         System.out.println("success count = " + success);










 103     }
 104 }
< prev index next >