4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
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 import jdk.net.ExtendedSocketOptions;
25
26 import java.io.IOException;
27 import java.net.*;
28
29 /*
30 * @test
31 * @bug 8143554
32 * @run main UnsupportedOptionsTest
33 * @summary Test checks that UnsupportedOperationException for unsupported
34 * SOCKET_OPTIONS is thrown by both getOption() and setOption() methods.
35 */
36 public class UnsupportedOptionsTest {
37
38 private static final SocketOption[] SOCKET_OPTIONS = {
39 StandardSocketOptions.IP_MULTICAST_IF,
40 StandardSocketOptions.IP_MULTICAST_LOOP,
41 StandardSocketOptions.IP_MULTICAST_TTL,
42 StandardSocketOptions.IP_TOS,
43 StandardSocketOptions.SO_BROADCAST,
44 StandardSocketOptions.SO_KEEPALIVE,
45 StandardSocketOptions.SO_LINGER,
46 StandardSocketOptions.SO_RCVBUF,
47 StandardSocketOptions.SO_REUSEADDR,
48 StandardSocketOptions.SO_SNDBUF,
49 StandardSocketOptions.TCP_NODELAY,
50 ExtendedSocketOptions.SO_FLOW_SLA
51 };
52
53 public static void main(String[] args) throws IOException {
54 Socket s = new Socket();
55 ServerSocket ss = new ServerSocket();
56 DatagramSocket ds = new DatagramSocket();
57 MulticastSocket ms = new MulticastSocket();
58
59 for (SocketOption option : SOCKET_OPTIONS) {
60 if (!s.supportedOptions().contains(option)) {
61 testUnsupportedSocketOption(s, option);
62 }
63
64 if (!ss.supportedOptions().contains(option)) {
65 testUnsupportedSocketOption(ss, option);
66 }
67
68 if (!ms.supportedOptions().contains(option)) {
69 testUnsupportedSocketOption(ms, option);
70 }
71
72 if (!ds.supportedOptions().contains(option)) {
73 testUnsupportedSocketOption(ds, option);
74 }
75 }
76 }
77
78 /*
79 * Check that UnsupportedOperationException for unsupported option is
|
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
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 import java.io.IOException;
25 import java.lang.reflect.Field;
26 import java.net.*;
27 import java.util.ArrayList;
28 import java.util.List;
29
30 /*
31 * @test
32 * @bug 8143554 8044773
33 * @summary Test checks that UnsupportedOperationException for unsupported
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
37 */
38
39 public class UnsupportedOptionsTest {
40
41 private static final List<SocketOption<?>> socketOptions = new ArrayList<>();
42
43 static {
44 socketOptions.add(StandardSocketOptions.IP_MULTICAST_IF);
45 socketOptions.add(StandardSocketOptions.IP_MULTICAST_LOOP);
46 socketOptions.add(StandardSocketOptions.IP_MULTICAST_TTL);
47 socketOptions.add(StandardSocketOptions.IP_TOS);
48 socketOptions.add(StandardSocketOptions.SO_BROADCAST);
49 socketOptions.add(StandardSocketOptions.SO_KEEPALIVE);
50 socketOptions.add(StandardSocketOptions.SO_LINGER);
51 socketOptions.add(StandardSocketOptions.SO_RCVBUF);
52 socketOptions.add(StandardSocketOptions.SO_REUSEADDR);
53 socketOptions.add(StandardSocketOptions.SO_SNDBUF);
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 }
66
67 public static void main(String[] args) throws IOException {
68 Socket s = new Socket();
69 ServerSocket ss = new ServerSocket();
70 DatagramSocket ds = new DatagramSocket();
71 MulticastSocket ms = new MulticastSocket();
72
73 for (SocketOption option : socketOptions) {
74 if (!s.supportedOptions().contains(option)) {
75 testUnsupportedSocketOption(s, option);
76 }
77
78 if (!ss.supportedOptions().contains(option)) {
79 testUnsupportedSocketOption(ss, option);
80 }
81
82 if (!ms.supportedOptions().contains(option)) {
83 testUnsupportedSocketOption(ms, option);
84 }
85
86 if (!ds.supportedOptions().contains(option)) {
87 testUnsupportedSocketOption(ds, option);
88 }
89 }
90 }
91
92 /*
93 * Check that UnsupportedOperationException for unsupported option is
|