< prev index next >

test/jdk/java/net/vthread/BlockingSocketOps.java

Print this page
*** 19,27 ***
   * 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 id=default
   * @bug 8284161
   * @summary Test virtual threads doing blocking I/O on java.net Sockets
   * @library /test/lib
   * @run junit BlockingSocketOps
   */
  
! /**
   * @test id=poller-modes
   * @requires (os.family == "linux") | (os.family == "mac")
   * @library /test/lib
   * @run junit/othervm -Djdk.pollerMode=1 BlockingSocketOps
   * @run junit/othervm -Djdk.pollerMode=2 BlockingSocketOps
   */
  
! /**
   * @test id=no-vmcontinuations
   * @requires vm.continuations
   * @library /test/lib
   * @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:-VMContinuations BlockingSocketOps
   */
--- 19,37 ---
   * 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 id=default
   * @bug 8284161
   * @summary Test virtual threads doing blocking I/O on java.net Sockets
   * @library /test/lib
   * @run junit BlockingSocketOps
   */
  
! /*
   * @test id=poller-modes
   * @requires (os.family == "linux") | (os.family == "mac")
   * @library /test/lib
   * @run junit/othervm -Djdk.pollerMode=1 BlockingSocketOps
   * @run junit/othervm -Djdk.pollerMode=2 BlockingSocketOps
+  * @run junit/othervm -Djdk.pollerMode=3 BlockingSocketOps
   */
  
! /*
+  * @test id=io_uring
+  * @requires os.family == "linux"
+  * @library /test/lib
+  * @run junit/othervm -Djdk.pollerMode=1 -Djdk.io_uring=true BlockingSocketOps
+  * @run junit/othervm -Djdk.pollerMode=2 -Djdk.io_uring=true BlockingSocketOps
+  * @run junit/othervm -Djdk.pollerMode=3 -Djdk.io_uring=true BlockingSocketOps
+  */
+ 
+ /*
   * @test id=no-vmcontinuations
   * @requires vm.continuations
   * @library /test/lib
   * @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:-VMContinuations BlockingSocketOps
   */

*** 210,11 ***
      /**
       * Socket close while virtual thread blocked in timed read.
       */
      @Test
      void testSocketReadAsyncClose2() throws Exception {
!         testSocketReadAsyncClose(0);
      }
  
      void testSocketReadAsyncClose(int timeout) throws Exception {
          VThreadRunner.run(() -> {
              try (var connection = new Connection()) {
--- 220,11 ---
      /**
       * Socket close while virtual thread blocked in timed read.
       */
      @Test
      void testSocketReadAsyncClose2() throws Exception {
!         testSocketReadAsyncClose(60_000);
      }
  
      void testSocketReadAsyncClose(int timeout) throws Exception {
          VThreadRunner.run(() -> {
              try (var connection = new Connection()) {

*** 233,10 ***
--- 243,49 ---
                  } catch (SocketException expected) { }
              }
          });
      }
  
+     /**
+      * Socket shutdownInput while virtual thread blocked in read.
+      */
+     @Test
+     void testSocketReadAsyncShutdownInput1() throws Exception {
+         testSocketReadAsyncShutdownInput(0);
+     }
+ 
+     /**
+      * Socket shutdownInput while virtual thread blocked in timed read.
+      */
+     @Test
+     void testSocketReadAsyncShutdownInput2() throws Exception {
+         testSocketReadAsyncShutdownInput(60_000);
+     }
+ 
+     void testSocketReadAsyncShutdownInput(int timeout) throws Exception {
+         VThreadRunner.run(() -> {
+             try (var connection = new Connection()) {
+                 Socket s = connection.socket1();
+ 
+                 // delayed shutdown of s
+                 runAfterParkedAsync(s::shutdownInput);
+ 
+                 // read from s should block, then throw
+                 if (timeout > 0) {
+                     s.setSoTimeout(timeout);
+                 }
+ 
+                 // -1 or SocketException
+                 try {
+                     int n = s.getInputStream().read();
+                     assertEquals(-1, n);
+                 } catch (SocketException e) { }
+                 assertFalse(s.isClosed());
+             }
+         });
+     }
+ 
      /**
       * Virtual thread interrupted while blocked in Socket read.
       */
      @Test
      void testSocketReadInterrupt1() throws Exception {

*** 283,11 ***
      void testSocketWriteAsyncClose() throws Exception {
          VThreadRunner.run(() -> {
              try (var connection = new Connection()) {
                  Socket s = connection.socket1();
  
!                 // delayedclose of s
                  runAfterParkedAsync(s::close);
  
                  // write to s should block, then throw
                  try {
                      byte[] ba = new byte[100*1024];
--- 332,11 ---
      void testSocketWriteAsyncClose() throws Exception {
          VThreadRunner.run(() -> {
              try (var connection = new Connection()) {
                  Socket s = connection.socket1();
  
!                 // delayed close of s
                  runAfterParkedAsync(s::close);
  
                  // write to s should block, then throw
                  try {
                      byte[] ba = new byte[100*1024];

*** 298,10 ***
--- 347,35 ---
                  } catch (SocketException expected) { }
              }
          });
      }
  
+     /**
+      * Socket shutdownOutput while virtual thread blocked in write.
+      */
+     @Test
+     void testSocketWriteAsyncShutdownOutput() throws Exception {
+         VThreadRunner.run(() -> {
+             try (var connection = new Connection()) {
+                 Socket s = connection.socket1();
+ 
+                 // delayed shutdown of s
+                 runAfterParkedAsync(s::shutdownOutput);
+ 
+                 // write to s should block, then throw
+                 try {
+                     byte[] ba = new byte[100*1024];
+                     OutputStream out = s.getOutputStream();
+                     for (;;) {
+                         out.write(ba);
+                     }
+                 } catch (SocketException expected) { }
+                 assertFalse(s.isClosed());
+             }
+         });
+     }
+ 
      /**
       * Virtual thread interrupted while blocked in Socket write.
       */
      @Test
      void testSocketWriteInterrupt() throws Exception {
< prev index next >