19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
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 |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 import jdk.net.ExtendedSocketOptions; |
|
25 |
|
26 import java.io.IOException; |
24 import java.io.IOException; |
|
25 import java.lang.reflect.Field; |
27 import java.net.*; |
26 import java.net.*; |
|
27 import java.util.ArrayList; |
|
28 import java.util.List; |
28 |
29 |
29 /* |
30 /* |
30 * @test |
31 * @test |
31 * @bug 8143554 |
32 * @bug 8143554 8044773 |
32 * @run main UnsupportedOptionsTest |
|
33 * @summary Test checks that UnsupportedOperationException for unsupported |
33 * @summary Test checks that UnsupportedOperationException for unsupported |
34 * SOCKET_OPTIONS is thrown by both getOption() and setOption() methods. |
34 * SOCKET_OPTIONS is thrown by both getOption() and setOption() methods. |
|
35 * @run main UnsupportedOptionsTest |
|
36 * @run main/othervm -Djdk.launcher.limitmods=java.base UnsupportedOptionsTest |
35 */ |
37 */ |
|
38 |
36 public class UnsupportedOptionsTest { |
39 public class UnsupportedOptionsTest { |
37 |
40 |
38 private static final SocketOption[] SOCKET_OPTIONS = { |
41 private static final List<SocketOption<?>> socketOptions = new ArrayList<>(); |
39 StandardSocketOptions.IP_MULTICAST_IF, |
42 |
40 StandardSocketOptions.IP_MULTICAST_LOOP, |
43 static { |
41 StandardSocketOptions.IP_MULTICAST_TTL, |
44 socketOptions.add(StandardSocketOptions.IP_MULTICAST_IF); |
42 StandardSocketOptions.IP_TOS, |
45 socketOptions.add(StandardSocketOptions.IP_MULTICAST_LOOP); |
43 StandardSocketOptions.SO_BROADCAST, |
46 socketOptions.add(StandardSocketOptions.IP_MULTICAST_TTL); |
44 StandardSocketOptions.SO_KEEPALIVE, |
47 socketOptions.add(StandardSocketOptions.IP_TOS); |
45 StandardSocketOptions.SO_LINGER, |
48 socketOptions.add(StandardSocketOptions.SO_BROADCAST); |
46 StandardSocketOptions.SO_RCVBUF, |
49 socketOptions.add(StandardSocketOptions.SO_KEEPALIVE); |
47 StandardSocketOptions.SO_REUSEADDR, |
50 socketOptions.add(StandardSocketOptions.SO_LINGER); |
48 StandardSocketOptions.SO_SNDBUF, |
51 socketOptions.add(StandardSocketOptions.SO_RCVBUF); |
49 StandardSocketOptions.TCP_NODELAY, |
52 socketOptions.add(StandardSocketOptions.SO_REUSEADDR); |
50 ExtendedSocketOptions.SO_FLOW_SLA |
53 socketOptions.add(StandardSocketOptions.SO_SNDBUF); |
51 }; |
54 socketOptions.add(StandardSocketOptions.TCP_NODELAY); |
|
55 |
|
56 try { |
|
57 Class<?> c = Class.forName("jdk.net.ExtendedSocketOptions"); |
|
58 Field field = c.getField("SO_FLOW_SLA"); |
|
59 socketOptions.add((SocketOption<?>)field.get(null)); |
|
60 } catch (ClassNotFoundException e) { |
|
61 // ignore, jdk.net module not present |
|
62 } catch (ReflectiveOperationException e) { |
|
63 throw new AssertionError(e); |
|
64 } |
|
65 } |
52 |
66 |
53 public static void main(String[] args) throws IOException { |
67 public static void main(String[] args) throws IOException { |
54 Socket s = new Socket(); |
68 Socket s = new Socket(); |
55 ServerSocket ss = new ServerSocket(); |
69 ServerSocket ss = new ServerSocket(); |
56 DatagramSocket ds = new DatagramSocket(); |
70 DatagramSocket ds = new DatagramSocket(); |
57 MulticastSocket ms = new MulticastSocket(); |
71 MulticastSocket ms = new MulticastSocket(); |
58 |
72 |
59 for (SocketOption option : SOCKET_OPTIONS) { |
73 for (SocketOption option : socketOptions) { |
60 if (!s.supportedOptions().contains(option)) { |
74 if (!s.supportedOptions().contains(option)) { |
61 testUnsupportedSocketOption(s, option); |
75 testUnsupportedSocketOption(s, option); |
62 } |
76 } |
63 |
77 |
64 if (!ss.supportedOptions().contains(option)) { |
78 if (!ss.supportedOptions().contains(option)) { |