test/jdk/net/Sockets/Test.java

Print this page




  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 /*
  25  * @test
  26  * @bug 8032808
  27  * @run main/othervm -Xcheck:jni Test
  28  * @run main/othervm/policy=policy.fail -Xcheck:jni Test fail
  29  * @run main/othervm/policy=policy.success -Xcheck:jni Test success
  30  */
  31 
  32 import java.net.*;
  33 import java.nio.channels.*;
  34 import java.util.concurrent.*;

  35 import jdk.net.*;
  36 
  37 public class Test {
  38 
  39     static boolean security;
  40     static boolean success;
  41 
  42     interface Runner {
  43         public void run() throws Exception;
  44     }
  45 
  46     public static void main(String[] args) throws Exception {
  47 
  48         // quick check to see if supportedOptions() working before
  49         // creating any sockets and libnet loaded
  50 
  51         Sockets.supportedOptions(Socket.class);
  52 
  53         security = System.getSecurityManager() != null;
  54         success = security && args[0].equals("success");


  57         // Doesn't matter if current system does not support the option
  58         // and currently setting the option with the loopback interface
  59         // doesn't work either
  60 
  61         System.out.println ("Security Manager enabled: " + security);
  62         if (security) {
  63             System.out.println ("Success expected: " + success);
  64         }
  65 
  66         final SocketFlow flowIn = SocketFlow.create()
  67             .bandwidth(1000)
  68             .priority(SocketFlow.HIGH_PRIORITY);
  69 
  70         ServerSocket ss = new ServerSocket(0);
  71         int tcp_port = ss.getLocalPort();
  72         final InetAddress loop = InetAddress.getByName("127.0.0.1");
  73         final InetSocketAddress loopad = new InetSocketAddress(loop, tcp_port);
  74 
  75         DatagramSocket dg = new DatagramSocket(0);
  76         final int udp_port = dg.getLocalPort();







  77 
  78         final Socket s = new Socket("127.0.0.1", tcp_port);
  79         final SocketChannel sc = SocketChannel.open();
  80         sc.connect (new InetSocketAddress("127.0.0.1", tcp_port));
  81 
  82         doTest(()->{
  83             Sockets.setOption(s, ExtendedSocketOptions.SO_FLOW_SLA, flowIn);
  84         });
  85         doTest(()->{
  86             Sockets.getOption(s, ExtendedSocketOptions.SO_FLOW_SLA);
  87         });
  88         doTest(()->{
  89             sc.setOption(ExtendedSocketOptions.SO_FLOW_SLA, flowIn);
  90         });
  91         doTest(()->{
  92             sc.getOption(ExtendedSocketOptions.SO_FLOW_SLA);
  93         });
  94         doTest(()->{
  95             DatagramSocket dg1 = new DatagramSocket(0);
  96             dg1.connect(loop, udp_port);




  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 /*
  25  * @test
  26  * @bug 8032808
  27  * @run main/othervm -Xcheck:jni Test
  28  * @run main/othervm/policy=policy.fail -Xcheck:jni Test fail
  29  * @run main/othervm/policy=policy.success -Xcheck:jni Test success
  30  */
  31 
  32 import java.net.*;
  33 import java.nio.channels.*;
  34 import java.util.concurrent.*;
  35 import java.util.Set;
  36 import jdk.net.*;
  37 
  38 public class Test {
  39 
  40     static boolean security;
  41     static boolean success;
  42 
  43     interface Runner {
  44         public void run() throws Exception;
  45     }
  46 
  47     public static void main(String[] args) throws Exception {
  48 
  49         // quick check to see if supportedOptions() working before
  50         // creating any sockets and libnet loaded
  51 
  52         Sockets.supportedOptions(Socket.class);
  53 
  54         security = System.getSecurityManager() != null;
  55         success = security && args[0].equals("success");


  58         // Doesn't matter if current system does not support the option
  59         // and currently setting the option with the loopback interface
  60         // doesn't work either
  61 
  62         System.out.println ("Security Manager enabled: " + security);
  63         if (security) {
  64             System.out.println ("Success expected: " + success);
  65         }
  66 
  67         final SocketFlow flowIn = SocketFlow.create()
  68             .bandwidth(1000)
  69             .priority(SocketFlow.HIGH_PRIORITY);
  70 
  71         ServerSocket ss = new ServerSocket(0);
  72         int tcp_port = ss.getLocalPort();
  73         final InetAddress loop = InetAddress.getByName("127.0.0.1");
  74         final InetSocketAddress loopad = new InetSocketAddress(loop, tcp_port);
  75 
  76         DatagramSocket dg = new DatagramSocket(0);
  77         final int udp_port = dg.getLocalPort();
  78 
  79         // If option not available, end test
  80         Set<SocketOption<?>> options = dg.supportedOptions();
  81         if (!options.contains(ExtendedSocketOptions.SO_FLOW_SLA)) {
  82             System.out.println("SO_FLOW_SLA not supported");
  83             return;
  84         }
  85 
  86         final Socket s = new Socket("127.0.0.1", tcp_port);
  87         final SocketChannel sc = SocketChannel.open();
  88         sc.connect (new InetSocketAddress("127.0.0.1", tcp_port));
  89 
  90         doTest(()->{
  91             Sockets.setOption(s, ExtendedSocketOptions.SO_FLOW_SLA, flowIn);
  92         });
  93         doTest(()->{
  94             Sockets.getOption(s, ExtendedSocketOptions.SO_FLOW_SLA);
  95         });
  96         doTest(()->{
  97             sc.setOption(ExtendedSocketOptions.SO_FLOW_SLA, flowIn);
  98         });
  99         doTest(()->{
 100             sc.getOption(ExtendedSocketOptions.SO_FLOW_SLA);
 101         });
 102         doTest(()->{
 103             DatagramSocket dg1 = new DatagramSocket(0);
 104             dg1.connect(loop, udp_port);