equal
deleted
inserted
replaced
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 8036979 8072384 |
26 * @bug 8036979 8072384 8044773 |
27 * @run main/othervm -Xcheck:jni OptionsTest |
27 * @run main/othervm -Xcheck:jni OptionsTest |
28 * @run main/othervm -Xcheck:jni -Djava.net.preferIPv4Stack=true OptionsTest |
28 * @run main/othervm -Xcheck:jni -Djava.net.preferIPv4Stack=true OptionsTest |
|
29 * @run main/othervm -Djdk.launcher.limitmods=java.base OptionsTest |
29 */ |
30 */ |
30 |
31 |
|
32 import java.lang.reflect.Method; |
31 import java.net.*; |
33 import java.net.*; |
32 import java.util.*; |
34 import java.util.*; |
33 |
35 |
34 public class OptionsTest { |
36 public class OptionsTest { |
35 |
37 |
41 static Test create (SocketOption<?> option, Object testValue) { |
43 static Test create (SocketOption<?> option, Object testValue) { |
42 return new Test(option, testValue); |
44 return new Test(option, testValue); |
43 } |
45 } |
44 Object option; |
46 Object option; |
45 Object testValue; |
47 Object testValue; |
46 }; |
48 } |
47 |
49 |
48 // The tests set the option using the new API, read back the set value |
50 // The tests set the option using the new API, read back the set value |
49 // which could be diferent, and then use the legacy get API to check |
51 // which could be diferent, and then use the legacy get API to check |
50 // these values are the same |
52 // these values are the same |
51 |
53 |
221 } else if (option.equals(StandardSocketOptions.SO_REUSEADDR)) { |
223 } else if (option.equals(StandardSocketOptions.SO_REUSEADDR)) { |
222 return Boolean.valueOf(socket.getReuseAddress()); |
224 return Boolean.valueOf(socket.getReuseAddress()); |
223 } else if (option.equals(StandardSocketOptions.SO_REUSEPORT) && reuseport) { |
225 } else if (option.equals(StandardSocketOptions.SO_REUSEPORT) && reuseport) { |
224 return Boolean.valueOf(socket.getOption(StandardSocketOptions.SO_REUSEPORT)); |
226 return Boolean.valueOf(socket.getOption(StandardSocketOptions.SO_REUSEPORT)); |
225 } else if (option.equals(StandardSocketOptions.IP_TOS)) { |
227 } else if (option.equals(StandardSocketOptions.IP_TOS)) { |
226 return Integer.valueOf(jdk.net.Sockets.getOption( |
228 return getServerSocketTrafficClass(socket); |
227 socket, StandardSocketOptions.IP_TOS)); |
|
228 } else { |
229 } else { |
229 throw new RuntimeException("unexecpted socket option"); |
230 throw new RuntimeException("unexecpted socket option"); |
230 } |
231 } |
231 } else if (type.equals(DatagramSocket.class)) { |
232 } else if (type.equals(DatagramSocket.class)) { |
232 DatagramSocket socket = (DatagramSocket)s; |
233 DatagramSocket socket = (DatagramSocket)s; |
279 doSocketTests(); |
280 doSocketTests(); |
280 doServerSocketTests(); |
281 doServerSocketTests(); |
281 doDgSocketTests(); |
282 doDgSocketTests(); |
282 doMcSocketTests(); |
283 doMcSocketTests(); |
283 } |
284 } |
|
285 |
|
286 // Reflectively access jdk.net.Sockets.getOption so that the test can run |
|
287 // without the jdk.net module. |
|
288 static Object getServerSocketTrafficClass(ServerSocket ss) throws Exception { |
|
289 try { |
|
290 Class<?> c = Class.forName("jdk.net.Sockets"); |
|
291 Method m = c.getDeclaredMethod("getOption", ServerSocket.class, SocketOption.class); |
|
292 return m.invoke(null, ss, StandardSocketOptions.IP_TOS); |
|
293 } catch (ClassNotFoundException e) { |
|
294 // Ok, jdk.net module not present, just fall back |
|
295 System.out.println("jdk.net module not present, falling back."); |
|
296 return Integer.valueOf(ss.getOption(StandardSocketOptions.IP_TOS)); |
|
297 } catch (ReflectiveOperationException e) { |
|
298 throw new AssertionError(e); |
|
299 } |
|
300 } |
284 } |
301 } |