< prev index next >

test/jdk/jdk/net/RdmaSockets/rsocket/RsocketTest.java

Print this page




  33  * @run main/native RsocketTest
  34  */
  35 
  36 import java.io.IOException;
  37 
  38 public class RsocketTest {
  39     private static boolean supported;
  40     private static boolean checked;
  41 
  42     static {
  43         System.loadLibrary("RsocketTest");
  44     }
  45 
  46     public static boolean isRsocketAvailable()
  47             throws IOException {
  48         if (!checked) {
  49             checked = true;
  50             supported = isRsocketAvailable0();
  51         }
  52         if (!supported) {







  53             checkThrowsUOE(jdk.net.RdmaSockets::openSocket);
  54             checkThrowsUOE(jdk.net.RdmaSockets::openServerSocket);
  55             checkThrowsUOE(jdk.net.RdmaSockets::openSocketChannel);
  56             checkThrowsUOE(jdk.net.RdmaSockets::openServerSocketChannel);
  57             checkThrowsUOE(jdk.net.RdmaSockets::openSelector);
  58         }
  59         return supported;
  60     }
  61 
  62     static void checkThrowsUOE(ThrowingRunnable runnable) throws IOException {
  63         try {
  64             runnable.run();
  65             throw new RuntimeException("Unexpected creation");
  66         } catch (UnsupportedOperationException expected) { }
  67     }
  68     interface ThrowingRunnable { void run() throws IOException; }
  69 
  70     private static native boolean isRsocketAvailable0();
  71 
  72     public static void main(String[] args) throws Exception {
  73          System.out.println("testing rsocket!");
  74     }
  75 }


  33  * @run main/native RsocketTest
  34  */
  35 
  36 import java.io.IOException;
  37 
  38 public class RsocketTest {
  39     private static boolean supported;
  40     private static boolean checked;
  41 
  42     static {
  43         System.loadLibrary("RsocketTest");
  44     }
  45 
  46     public static boolean isRsocketAvailable()
  47             throws IOException {
  48         if (!checked) {
  49             checked = true;
  50             supported = isRsocketAvailable0();
  51         }
  52         if (!supported) {
  53             checkUnsupported();
  54         }
  55         return supported;
  56     }
  57 
  58     static void checkUnsupported() throws IOException {
  59         for (int i=0; i<3; i++) {
  60             checkThrowsUOE(jdk.net.RdmaSockets::openSocket);
  61             checkThrowsUOE(jdk.net.RdmaSockets::openServerSocket);
  62             checkThrowsUOE(jdk.net.RdmaSockets::openSocketChannel);
  63             checkThrowsUOE(jdk.net.RdmaSockets::openServerSocketChannel);
  64             checkThrowsUOE(jdk.net.RdmaSockets::openSelector);
  65         }

  66     }
  67 
  68     static void checkThrowsUOE(ThrowingRunnable runnable) throws IOException {
  69         try {
  70             runnable.run();
  71             throw new RuntimeException("Unexpected creation");
  72         } catch (UnsupportedOperationException expected) { }
  73     }
  74     interface ThrowingRunnable { void run() throws IOException; }
  75 
  76     private static native boolean isRsocketAvailable0();
  77 
  78     public static void main(String[] args) throws Exception {
  79          System.out.println("testing rsocket!");
  80     }
  81 }
< prev index next >