< prev index next >

test/java/nio/channels/Selector/SelectAfterRead.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2016, 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.

@@ -20,32 +20,41 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
 /* @test
- * @bug 4639943
+ * @bug 4639943 8085792
  * @summary  Checks that Windows behavior matches Solaris for
  *           various read/select combinations.
  * @author kladko
  */
 
+import java.net.SocketTimeoutException;
 import java.nio.ByteBuffer;
 import java.nio.channels.Selector;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.SocketChannel;
 
 public class SelectAfterRead {
 
     private static final int TIMEOUT = 1000;
+    private static final int SERVER_ACCEPT_TIMEOUT = 100;
 
     public static void main(String[] argv) throws Exception {
 
+        while (true) {
         // server: accept connection and write one byte
         try (ByteServer server = new ByteServer();
              SocketChannel sc = SocketChannel.open(server.address())) {
 
+                server.setTimeout(SERVER_ACCEPT_TIMEOUT);
+                try {
             server.acceptConnection();
+                } catch (SocketTimeoutException ex) {
+                    System.err.println("accept connection(write one byte) timeout...");
+                    continue;
+                }
             server.write(1);
 
             try (Selector sel = Selector.open()) {
                 sc.read(ByteBuffer.allocate(1));
                 sc.configureBlocking(false);

@@ -54,17 +63,27 @@
                 // nothing to read
                 if (sel.selectNow() != 0)
                     throw new Exception("Select returned nonzero value");
             }
         }
+            System.out.println("Test(write one byte) successes.");
+            break;
+        }
 
+        while (true) {
         // Now we will test a two reads combination
         // server: accept connection and write two bytes
         try (ByteServer server = new ByteServer();
              SocketChannel sc = SocketChannel.open(server.address())) {
 
+                server.setTimeout(SERVER_ACCEPT_TIMEOUT);
+                try {
             server.acceptConnection();
+                } catch (SocketTimeoutException ex) {
+                    System.err.println("accept connection(write two bytes) timeout...");
+                    continue;
+                }
             server.write(2);
 
             try (Selector sel = Selector.open()) {
                 sc.configureBlocking(false);
                 sc.register(sel, SelectionKey.OP_READ);

@@ -83,7 +102,10 @@
                     throw new Exception("One byte expected");
                 if (sel.selectNow() != 0)
                     throw new Exception("Select returned nonzero value");
             }
         }
+            System.out.println("Test(write two bytes) successes.");
+            break;
+        }
     }
 }
< prev index next >