author | pconcannon |
Thu, 14 Nov 2019 10:49:20 +0000 | |
changeset 59092 | 625262261ef2 |
parent 55288 | ae41e1037bde |
permissions | -rw-r--r-- |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
1 |
/* |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
4 |
* |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
8 |
* |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
13 |
* accompanied this code). |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
14 |
* |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
18 |
* |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
21 |
* questions. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
22 |
*/ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
23 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
24 |
/* |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
25 |
* @test |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
26 |
* @bug 8224477 |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
27 |
* @summary Ensures that IOException is thrown after the socket is closed |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
28 |
* @run testng AfterClose |
55288
ae41e1037bde
8225424: Add jdk.net.usePlainSocketImpl runs to a couple of tests
chegar
parents:
55081
diff
changeset
|
29 |
* @run testng/othervm -Djdk.net.usePlainSocketImpl AfterClose |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
30 |
*/ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
31 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
32 |
import java.io.IOException; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
33 |
import java.lang.reflect.Field; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
34 |
import java.lang.reflect.Method; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
35 |
import java.net.DatagramSocket; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
36 |
import java.net.MulticastSocket; |
59092
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
37 |
import java.net.NetworkInterface; |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
38 |
import java.net.ServerSocket; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
39 |
import java.net.Socket; |
59092
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
40 |
import java.net.SocketException; |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
41 |
import java.net.SocketOption; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
42 |
import java.nio.channels.DatagramChannel; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
43 |
import java.nio.channels.ServerSocketChannel; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
44 |
import java.nio.channels.SocketChannel; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
45 |
import java.util.ArrayList; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
46 |
import java.util.Arrays; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
47 |
import java.util.HashMap; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
48 |
import java.util.List; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
49 |
import java.util.Map; |
59092
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
50 |
import java.util.stream.Collectors; |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
51 |
import org.testng.annotations.DataProvider; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
52 |
import org.testng.annotations.Test; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
53 |
import static java.lang.Boolean.*; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
54 |
import static java.net.StandardSocketOptions.*; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
55 |
import static org.testng.Assert.expectThrows; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
56 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
57 |
public class AfterClose { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
58 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
59 |
static final Class<IOException> IOE = IOException.class; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
60 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
61 |
static Map<SocketOption<?>,List<Object>> OPTION_VALUES_MAP = optionValueMap(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
62 |
|
59092
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
63 |
static boolean supportsMulticast(NetworkInterface ni) { |
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
64 |
try { |
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
65 |
return ni.supportsMulticast(); |
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
66 |
} catch (SocketException e) { |
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
67 |
return false; |
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
68 |
} |
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
69 |
} |
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
70 |
|
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
71 |
static List<Object> listNetworkInterfaces() { |
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
72 |
try { |
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
73 |
return NetworkInterface.networkInterfaces() |
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
74 |
.filter(AfterClose::supportsMulticast) |
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
75 |
.collect(Collectors.toList()); |
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
76 |
} catch (Exception e) { } |
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
77 |
return List.of(); |
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
78 |
} |
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
79 |
|
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
80 |
static Map<SocketOption<?>,List<Object>> optionValueMap() { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
81 |
Map<SocketOption<?>,List<Object>> map = new HashMap<>(); |
59092
625262261ef2
8233860: AfterClose.java test incorrectly handles IP_MULTICAST_IF
pconcannon
parents:
55288
diff
changeset
|
82 |
map.put(IP_MULTICAST_IF, listNetworkInterfaces() ); |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
83 |
map.put(IP_MULTICAST_LOOP, listOf(TRUE, FALSE) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
84 |
map.put(IP_MULTICAST_TTL, listOf(0, 100, 255) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
85 |
map.put(IP_TOS, listOf(0, 101, 255) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
86 |
map.put(SO_BROADCAST, listOf(TRUE, FALSE) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
87 |
map.put(SO_KEEPALIVE, listOf(TRUE, FALSE) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
88 |
map.put(SO_LINGER, listOf(0, 5, 15) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
89 |
map.put(SO_RCVBUF, listOf(1, 100, 1000)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
90 |
map.put(SO_REUSEADDR, listOf(TRUE, FALSE) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
91 |
map.put(SO_REUSEPORT, listOf(TRUE, FALSE) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
92 |
map.put(SO_SNDBUF, listOf(1, 100, 1000)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
93 |
map.put(TCP_NODELAY, listOf(TRUE, FALSE) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
94 |
// extended options |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
95 |
try { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
96 |
Class<?> c = Class.forName("jdk.net.ExtendedSocketOptions"); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
97 |
Field field = c.getField("SO_FLOW_SLA"); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
98 |
map.put((SocketOption<?>)field.get(null), listOf(createSocketFlow())); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
99 |
field = c.getField("TCP_QUICKACK"); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
100 |
map.put((SocketOption<?>)field.get(null), listOf(TRUE, FALSE)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
101 |
field = c.getField("TCP_KEEPIDLE"); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
102 |
map.put((SocketOption<?>)field.get(null), listOf(10, 100)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
103 |
field = c.getField("TCP_KEEPINTERVAL"); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
104 |
map.put((SocketOption<?>)field.get(null), listOf(10, 100)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
105 |
field = c.getField("TCP_KEEPCOUNT"); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
106 |
map.put((SocketOption<?>)field.get(null), listOf(10, 100)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
107 |
} catch (ClassNotFoundException e) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
108 |
// ignore, jdk.net module not present |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
109 |
} catch (ReflectiveOperationException e) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
110 |
throw new AssertionError(e); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
111 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
112 |
return map; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
113 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
114 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
115 |
// -- Socket |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
116 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
117 |
@DataProvider(name = "socketOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
118 |
public Object[][] socketOptionValues() throws Exception { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
119 |
try (Socket s = new Socket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
120 |
return s.supportedOptions().stream() |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
121 |
.map(so -> new Object[] {so, OPTION_VALUES_MAP.get(so)}) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
122 |
.toArray(Object[][]::new); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
123 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
124 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
125 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
126 |
@Test(dataProvider = "socketOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
127 |
public <T> void closedSocketImplUncreated(SocketOption<T> option, List<T> values) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
128 |
throws IOException |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
129 |
{ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
130 |
Socket socket = createClosedSocketImplUncreated(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
131 |
for (int i=0; i<3; i++); { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
132 |
for (T value : values) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
133 |
expectThrows(IOE, () -> socket.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
134 |
expectThrows(IOE, () -> socket.getOption(option)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
135 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
136 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
137 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
138 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
139 |
@Test(dataProvider = "socketOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
140 |
public <T> void closedSocketImplCreated(SocketOption<T> option, List<T> values) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
141 |
throws IOException |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
142 |
{ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
143 |
Socket socket = createClosedSocketImplCreated(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
144 |
for (int i=0; i<3; i++); { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
145 |
for (T value : values) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
146 |
expectThrows(IOE, () -> socket.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
147 |
expectThrows(IOE, () -> socket.getOption(option)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
148 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
149 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
150 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
151 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
152 |
@Test(dataProvider = "socketOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
153 |
public <T> void closedSocketAdapter(SocketOption<T> option, List<T> values) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
154 |
throws IOException |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
155 |
{ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
156 |
Socket socket = createClosedSocketFromAdapter(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
157 |
for (int i=0; i<3; i++); { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
158 |
for (T value : values) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
159 |
expectThrows(IOE, () -> socket.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
160 |
expectThrows(IOE, () -> socket.getOption(option)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
161 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
162 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
163 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
164 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
165 |
// -- ServerSocket |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
166 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
167 |
@DataProvider(name = "serverSocketOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
168 |
public Object[][] serverSocketOptionValues() throws Exception { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
169 |
try (ServerSocket ss = new ServerSocket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
170 |
return ss.supportedOptions().stream() |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
171 |
.map(so -> new Object[] {so, OPTION_VALUES_MAP.get(so)}) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
172 |
.toArray(Object[][]::new); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
173 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
174 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
175 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
176 |
@Test(dataProvider = "serverSocketOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
177 |
public <T> void closedServerSocketImplUncreated(SocketOption<T> option, List<T> values) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
178 |
throws IOException |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
179 |
{ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
180 |
ServerSocket serverSocket = createClosedServerSocketImplUncreated(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
181 |
for (int i=0; i<3; i++); { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
182 |
for (T value : values) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
183 |
expectThrows(IOE, () -> serverSocket.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
184 |
expectThrows(IOE, () -> serverSocket.getOption(option)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
185 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
186 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
187 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
188 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
189 |
@Test(dataProvider = "serverSocketOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
190 |
public <T> void closedServerSocketImplCreated(SocketOption<T> option, List<T> values) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
191 |
throws IOException |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
192 |
{ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
193 |
ServerSocket serverSocket = createClosedServerSocketImplCreated(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
194 |
for (int i=0; i<3; i++); { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
195 |
for (T value : values) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
196 |
expectThrows(IOE, () -> serverSocket.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
197 |
expectThrows(IOE, () -> serverSocket.getOption(option)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
198 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
199 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
200 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
201 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
202 |
@Test(dataProvider = "serverSocketOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
203 |
public <T> void closedServerSocketAdapter(SocketOption<T> option, List<T> values) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
204 |
throws IOException |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
205 |
{ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
206 |
if (option == IP_TOS) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
207 |
return; // SSC does not support IP_TOS |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
208 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
209 |
ServerSocket serverSocket = createClosedServerSocketFromAdapter(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
210 |
for (int i=0; i<3; i++); { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
211 |
for (T value : values) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
212 |
expectThrows(IOE, () -> serverSocket.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
213 |
expectThrows(IOE, () -> serverSocket.getOption(option)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
214 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
215 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
216 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
217 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
218 |
// -- DatagramSocket |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
219 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
220 |
@DataProvider(name = "datagramSocketOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
221 |
public Object[][] datagramSocketOptionValues() throws Exception { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
222 |
try (DatagramSocket ds = new DatagramSocket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
223 |
return ds.supportedOptions().stream() |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
224 |
.map(so -> new Object[] {so, OPTION_VALUES_MAP.get(so)}) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
225 |
.toArray(Object[][]::new); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
226 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
227 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
228 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
229 |
@Test(dataProvider = "datagramSocketOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
230 |
public <T> void closedUnboundDatagramSocket(SocketOption<T> option, List<T> values) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
231 |
throws IOException |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
232 |
{ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
233 |
DatagramSocket datagramSocket = createClosedUnboundDatagramSocket(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
234 |
for (int i=0; i<3; i++); { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
235 |
for (T value : values) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
236 |
expectThrows(IOE, () -> datagramSocket.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
237 |
expectThrows(IOE, () -> datagramSocket.getOption(option)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
238 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
239 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
240 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
241 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
242 |
@Test(dataProvider = "datagramSocketOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
243 |
public <T> void closedBoundDatagramSocket(SocketOption<T> option, List<T> values) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
244 |
throws IOException |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
245 |
{ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
246 |
DatagramSocket datagramSocket = createClosedBoundDatagramSocket(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
247 |
for (int i=0; i<3; i++); { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
248 |
for (T value : values) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
249 |
expectThrows(IOE, () -> datagramSocket.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
250 |
expectThrows(IOE, () -> datagramSocket.getOption(option)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
251 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
252 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
253 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
254 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
255 |
@Test(dataProvider = "datagramSocketOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
256 |
public <T> void closedDatagramAdapter(SocketOption<T> option, List<T> values) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
257 |
throws IOException |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
258 |
{ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
259 |
DatagramSocket datagramSocket = createClosedBoundDatagramSocket(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
260 |
for (int i=0; i<3; i++); { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
261 |
for (T value : values) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
262 |
expectThrows(IOE, () -> datagramSocket.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
263 |
expectThrows(IOE, () -> datagramSocket.getOption(option)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
264 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
265 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
266 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
267 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
268 |
// -- MulticastSocket |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
269 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
270 |
@DataProvider(name = "multicastSocketOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
271 |
public Object[][] multicastSocketOptionValues() throws Exception { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
272 |
try (MulticastSocket ms = new MulticastSocket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
273 |
return ms.supportedOptions().stream() |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
274 |
.map(so -> new Object[] {so, OPTION_VALUES_MAP.get(so)}) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
275 |
.toArray(Object[][]::new); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
276 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
277 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
278 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
279 |
@Test(dataProvider = "multicastSocketOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
280 |
public <T> void closedUnboundMulticastSocket(SocketOption<T> option, List<T> values) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
281 |
throws IOException |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
282 |
{ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
283 |
MulticastSocket multicastSocket = createClosedUnboundMulticastSocket(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
284 |
for (int i=0; i<3; i++); { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
285 |
for (T value : values) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
286 |
expectThrows(IOE, () -> multicastSocket.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
287 |
expectThrows(IOE, () -> multicastSocket.getOption(option)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
288 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
289 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
290 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
291 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
292 |
@Test(dataProvider = "multicastSocketOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
293 |
public <T> void closedBoundMulticastSocket(SocketOption<T> option, List<T> values) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
294 |
throws IOException |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
295 |
{ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
296 |
MulticastSocket multicastSocket = createClosedBoundMulticastSocket(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
297 |
for (int i=0; i<3; i++); { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
298 |
for (T value : values) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
299 |
expectThrows(IOE, () -> multicastSocket.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
300 |
expectThrows(IOE, () -> multicastSocket.getOption(option)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
301 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
302 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
303 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
304 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
305 |
// -- |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
306 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
307 |
static List<Object> listOf(Object... objs) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
308 |
List<Object> l = new ArrayList<>(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
309 |
Arrays.stream(objs).forEachOrdered(l::add); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
310 |
return l; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
311 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
312 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
313 |
// Returns a closed Socket that has an impl whose `create` method has NOT been invoked. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
314 |
static Socket createClosedSocketImplUncreated() throws IOException { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
315 |
Socket s = new Socket(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
316 |
s.close(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
317 |
return s; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
318 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
319 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
320 |
// Returns a closed Socket that has an impl whose `create` method has been invoked. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
321 |
static Socket createClosedSocketImplCreated() throws IOException { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
322 |
Socket s = new Socket(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
323 |
s.bind(null); // binding causes impl::create to be invoked |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
324 |
s.close(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
325 |
return s; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
326 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
327 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
328 |
// Returns a closed Socket created from a SocketChannel's adapter. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
329 |
static Socket createClosedSocketFromAdapter() throws IOException { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
330 |
SocketChannel sc = SocketChannel.open(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
331 |
sc.close(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
332 |
return sc.socket(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
333 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
334 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
335 |
// Returns a closed ServerSocket that has an impl whose `create` method has NOT been invoked. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
336 |
static ServerSocket createClosedServerSocketImplUncreated() throws IOException { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
337 |
ServerSocket ss = new ServerSocket(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
338 |
ss.close(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
339 |
return ss; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
340 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
341 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
342 |
// Returns a closed ServerSocket that has an impl whose `create` method has been invoked. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
343 |
static ServerSocket createClosedServerSocketImplCreated() throws IOException { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
344 |
ServerSocket ss = new ServerSocket(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
345 |
ss.bind(null); // binding causes impl::create to be invoked |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
346 |
ss.close(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
347 |
return ss; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
348 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
349 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
350 |
// Returns a closed ServerSocket created from a ServerSocketChannel's adapter. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
351 |
static ServerSocket createClosedServerSocketFromAdapter() throws IOException { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
352 |
ServerSocketChannel ssc = ServerSocketChannel.open(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
353 |
ssc.close(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
354 |
return ssc.socket(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
355 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
356 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
357 |
// Returns a closed unbound DatagramSocket. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
358 |
static DatagramSocket createClosedUnboundDatagramSocket() throws IOException { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
359 |
DatagramSocket ds = new DatagramSocket(null); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
360 |
assert ds.isBound() == false; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
361 |
ds.close(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
362 |
return ds; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
363 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
364 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
365 |
// Returns a closed bound DatagramSocket. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
366 |
static DatagramSocket createClosedBoundDatagramSocket() throws IOException { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
367 |
DatagramSocket ds = new DatagramSocket(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
368 |
assert ds.isBound() == true; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
369 |
ds.close(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
370 |
return ds; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
371 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
372 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
373 |
// Returns a closed DatagramSocket that created from a DatagramChannel's adapter. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
374 |
static DatagramSocket createClosedDatagramSocketFromAdapter() throws IOException { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
375 |
DatagramChannel dc = DatagramChannel.open(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
376 |
dc.close(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
377 |
return dc.socket(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
378 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
379 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
380 |
// Returns a closed unbound MulticastSocket. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
381 |
static MulticastSocket createClosedUnboundMulticastSocket() throws IOException { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
382 |
MulticastSocket ms = new MulticastSocket(null); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
383 |
assert ms.isBound() == false; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
384 |
ms.close(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
385 |
return ms; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
386 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
387 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
388 |
// Returns a closed bound MulticastSocket. |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
389 |
static MulticastSocket createClosedBoundMulticastSocket() throws IOException { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
390 |
MulticastSocket ms = new MulticastSocket(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
391 |
assert ms.isBound() == true; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
392 |
ms.close(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
393 |
return ms; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
394 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
395 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
396 |
static Object createSocketFlow() { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
397 |
try { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
398 |
Class<?> c = Class.forName("jdk.net.SocketFlow"); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
399 |
Method method = c.getDeclaredMethod("create"); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
400 |
return method.invoke(null); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
401 |
} catch (ReflectiveOperationException e) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
402 |
throw new AssertionError(e); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
403 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
404 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
405 |
} |