author | chegar |
Wed, 29 May 2019 13:58:05 +0100 | |
changeset 55081 | dd321e3596c0 |
child 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 Basic test for NPE, UOE, and IAE for get/setOption |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
28 |
* @run testng NullsAndBadValues |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
29 |
* @run testng/othervm -Dsun.net.useExclusiveBind=false NullsAndBadValues |
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.net.DatagramSocket; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
33 |
import java.net.MulticastSocket; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
34 |
import java.net.ServerSocket; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
35 |
import java.net.Socket; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
36 |
import java.net.SocketOption; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
37 |
import java.nio.channels.DatagramChannel; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
38 |
import java.nio.channels.ServerSocketChannel; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
39 |
import java.nio.channels.SocketChannel; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
40 |
import java.util.ArrayList; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
41 |
import java.util.Arrays; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
42 |
import java.util.HashMap; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
43 |
import java.util.List; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
44 |
import java.util.Map; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
45 |
import java.util.stream.Stream; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
46 |
import org.testng.annotations.DataProvider; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
47 |
import org.testng.annotations.Test; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
48 |
import static java.lang.Boolean.*; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
49 |
import static java.net.StandardSocketOptions.*; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
50 |
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
|
51 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
52 |
public class NullsAndBadValues { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
53 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
54 |
static final Class<NullPointerException> NPE = NullPointerException.class; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
55 |
static final Class<IllegalArgumentException> IAE = IllegalArgumentException.class; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
56 |
static final Class<UnsupportedOperationException> UOE = UnsupportedOperationException.class; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
57 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
58 |
@Test |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
59 |
public void nulls() throws Exception { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
60 |
try (Socket s = new Socket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
61 |
expectThrows(NPE, () -> s.setOption(null, null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
62 |
expectThrows(NPE, () -> s.setOption(null, "")); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
63 |
expectThrows(NPE, () -> s.setOption(null, 1)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
64 |
expectThrows(NPE, () -> s.getOption(null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
65 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
66 |
try (ServerSocket ss = new ServerSocket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
67 |
expectThrows(NPE, () -> ss.setOption(null, null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
68 |
expectThrows(NPE, () -> ss.setOption(null, "")); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
69 |
expectThrows(NPE, () -> ss.setOption(null, 1)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
70 |
expectThrows(NPE, () -> ss.getOption(null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
71 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
72 |
try (DatagramSocket ds = new DatagramSocket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
73 |
expectThrows(NPE, () -> ds.setOption(null, null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
74 |
expectThrows(NPE, () -> ds.setOption(null, "")); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
75 |
expectThrows(NPE, () -> ds.setOption(null, 1)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
76 |
expectThrows(NPE, () -> ds.getOption(null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
77 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
78 |
try (MulticastSocket ms = new MulticastSocket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
79 |
expectThrows(NPE, () -> ms.setOption(null, null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
80 |
expectThrows(NPE, () -> ms.setOption(null, "")); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
81 |
expectThrows(NPE, () -> ms.setOption(null, 1)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
82 |
expectThrows(NPE, () -> ms.getOption(null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
83 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
84 |
try (Socket sa = SocketChannel.open().socket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
85 |
expectThrows(NPE, () -> sa.setOption(null, null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
86 |
expectThrows(NPE, () -> sa.setOption(null, "")); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
87 |
expectThrows(NPE, () -> sa.setOption(null, 1)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
88 |
expectThrows(NPE, () -> sa.getOption(null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
89 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
90 |
try (ServerSocket ssa = ServerSocketChannel.open().socket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
91 |
expectThrows(NPE, () -> ssa.setOption(null, null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
92 |
expectThrows(NPE, () -> ssa.setOption(null, "")); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
93 |
expectThrows(NPE, () -> ssa.setOption(null, 1)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
94 |
expectThrows(NPE, () -> ssa.getOption(null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
95 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
96 |
try (DatagramSocket dsa = DatagramChannel.open().socket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
97 |
expectThrows(NPE, () -> dsa.setOption(null, null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
98 |
expectThrows(NPE, () -> dsa.setOption(null, "")); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
99 |
expectThrows(NPE, () -> dsa.setOption(null, 1)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
100 |
expectThrows(NPE, () -> dsa.getOption(null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
101 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
102 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
103 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
104 |
static final SocketOption<Boolean> FAKE_SOCK_OPT = new SocketOption<>() { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
105 |
@Override public String name() { return "FAKE_SOCK_OPT"; } |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
106 |
@Override public Class<Boolean> type() { return Boolean.class; } |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
107 |
}; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
108 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
109 |
static final SocketOption RAW_SOCK_OPT = new SocketOption() { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
110 |
@Override public String name() { return "RAW_SOCK_OPT"; } |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
111 |
@Override public Class type() { return Boolean.class; } |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
112 |
}; |
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 |
@Test |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
115 |
public void uoe() throws Exception { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
116 |
try (Socket s = new Socket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
117 |
expectThrows(UOE, () -> s.setOption(FAKE_SOCK_OPT, null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
118 |
expectThrows(UOE, () -> s.setOption(FAKE_SOCK_OPT, TRUE)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
119 |
expectThrows(UOE, () -> s.setOption(FAKE_SOCK_OPT, FALSE)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
120 |
expectThrows(UOE, () -> s.setOption(RAW_SOCK_OPT, "")); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
121 |
expectThrows(UOE, () -> s.setOption(RAW_SOCK_OPT, 1)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
122 |
expectThrows(UOE, () -> s.getOption(FAKE_SOCK_OPT)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
123 |
expectThrows(UOE, () -> s.getOption(RAW_SOCK_OPT)); |
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 |
try (ServerSocket ss = new ServerSocket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
126 |
expectThrows(UOE, () -> ss.setOption(FAKE_SOCK_OPT, null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
127 |
expectThrows(UOE, () -> ss.setOption(FAKE_SOCK_OPT, TRUE)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
128 |
expectThrows(UOE, () -> ss.setOption(FAKE_SOCK_OPT, FALSE)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
129 |
expectThrows(UOE, () -> ss.setOption(RAW_SOCK_OPT, "")); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
130 |
expectThrows(UOE, () -> ss.setOption(RAW_SOCK_OPT, 1)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
131 |
expectThrows(UOE, () -> ss.getOption(FAKE_SOCK_OPT)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
132 |
expectThrows(UOE, () -> ss.getOption(RAW_SOCK_OPT)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
133 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
134 |
try (DatagramSocket ds = new DatagramSocket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
135 |
expectThrows(UOE, () -> ds.setOption(FAKE_SOCK_OPT, null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
136 |
expectThrows(UOE, () -> ds.setOption(FAKE_SOCK_OPT, TRUE)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
137 |
expectThrows(UOE, () -> ds.setOption(FAKE_SOCK_OPT, FALSE)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
138 |
expectThrows(UOE, () -> ds.setOption(RAW_SOCK_OPT, "")); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
139 |
expectThrows(UOE, () -> ds.setOption(RAW_SOCK_OPT, 1)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
140 |
expectThrows(UOE, () -> ds.getOption(FAKE_SOCK_OPT)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
141 |
expectThrows(UOE, () -> ds.getOption(RAW_SOCK_OPT)); |
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 |
try (MulticastSocket ms = new MulticastSocket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
144 |
expectThrows(UOE, () -> ms.setOption(FAKE_SOCK_OPT, null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
145 |
expectThrows(UOE, () -> ms.setOption(FAKE_SOCK_OPT, TRUE)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
146 |
expectThrows(UOE, () -> ms.setOption(FAKE_SOCK_OPT, FALSE)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
147 |
expectThrows(UOE, () -> ms.setOption(RAW_SOCK_OPT, "")); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
148 |
expectThrows(UOE, () -> ms.setOption(RAW_SOCK_OPT, 1)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
149 |
expectThrows(UOE, () -> ms.getOption(FAKE_SOCK_OPT)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
150 |
expectThrows(UOE, () -> ms.getOption(RAW_SOCK_OPT)); |
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 |
try (Socket sa = SocketChannel.open().socket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
153 |
expectThrows(UOE, () -> sa.setOption(FAKE_SOCK_OPT, null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
154 |
expectThrows(UOE, () -> sa.setOption(FAKE_SOCK_OPT, TRUE)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
155 |
expectThrows(UOE, () -> sa.setOption(FAKE_SOCK_OPT, FALSE)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
156 |
expectThrows(UOE, () -> sa.setOption(RAW_SOCK_OPT, "")); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
157 |
expectThrows(UOE, () -> sa.setOption(RAW_SOCK_OPT, 1)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
158 |
expectThrows(UOE, () -> sa.getOption(FAKE_SOCK_OPT)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
159 |
expectThrows(UOE, () -> sa.getOption(RAW_SOCK_OPT)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
160 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
161 |
try (ServerSocket ssa = ServerSocketChannel.open().socket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
162 |
expectThrows(UOE, () -> ssa.setOption(FAKE_SOCK_OPT, null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
163 |
expectThrows(UOE, () -> ssa.setOption(FAKE_SOCK_OPT, TRUE)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
164 |
expectThrows(UOE, () -> ssa.setOption(FAKE_SOCK_OPT, FALSE)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
165 |
expectThrows(UOE, () -> ssa.setOption(RAW_SOCK_OPT, "")); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
166 |
expectThrows(UOE, () -> ssa.setOption(RAW_SOCK_OPT, 1)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
167 |
expectThrows(UOE, () -> ssa.getOption(FAKE_SOCK_OPT)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
168 |
expectThrows(UOE, () -> ssa.getOption(RAW_SOCK_OPT)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
169 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
170 |
try (DatagramSocket dsa = DatagramChannel.open().socket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
171 |
expectThrows(UOE, () -> dsa.setOption(FAKE_SOCK_OPT, null)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
172 |
expectThrows(UOE, () -> dsa.setOption(FAKE_SOCK_OPT, TRUE)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
173 |
expectThrows(UOE, () -> dsa.setOption(FAKE_SOCK_OPT, FALSE)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
174 |
expectThrows(UOE, () -> dsa.setOption(RAW_SOCK_OPT, "")); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
175 |
expectThrows(UOE, () -> dsa.setOption(RAW_SOCK_OPT, 1)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
176 |
expectThrows(UOE, () -> dsa.getOption(FAKE_SOCK_OPT)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
177 |
expectThrows(UOE, () -> dsa.getOption(RAW_SOCK_OPT)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
178 |
} |
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 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
181 |
static Map<SocketOption<?>,List<Object>> BAD_OPTION_VALUES = badOptionValues(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
182 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
183 |
static Map<SocketOption<?>,List<Object>> badOptionValues() { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
184 |
Map<SocketOption<?>,List<Object>> map = new HashMap<>(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
185 |
map.put(IP_MULTICAST_IF, listOf(null) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
186 |
map.put(IP_MULTICAST_LOOP, listOf(null) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
187 |
map.put(IP_MULTICAST_TTL, listOf(null, -1, 256)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
188 |
map.put(IP_TOS, listOf(null, -1, 256)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
189 |
map.put(SO_BROADCAST, listOf(null) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
190 |
map.put(SO_KEEPALIVE, listOf(null) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
191 |
map.put(SO_LINGER, listOf(null) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
192 |
map.put(SO_RCVBUF, listOf(null, -1) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
193 |
map.put(SO_REUSEADDR, listOf(null) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
194 |
map.put(SO_REUSEPORT, listOf(null) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
195 |
map.put(SO_SNDBUF, listOf(null, -1) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
196 |
map.put(TCP_NODELAY, listOf(null) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
197 |
// extended options, not in the map, will get a null value |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
198 |
return map; |
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 |
// -- Socket |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
202 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
203 |
@DataProvider(name = "socketBadOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
204 |
public Object[][] socketBadOptionValues() throws Exception { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
205 |
try (Socket s = new Socket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
206 |
return s.supportedOptions().stream() |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
207 |
.flatMap(NullsAndBadValues::socketOptionToBadValues) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
208 |
.toArray(Object[][]::new); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
209 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
210 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
211 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
212 |
@Test(dataProvider = "socketBadOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
213 |
public <T> void socket(SocketOption<T> option, T value) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
214 |
throws Exception |
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 |
try (Socket s = new Socket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
217 |
expectThrows(IAE, () -> s.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
218 |
} |
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 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
221 |
@Test(dataProvider = "socketBadOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
222 |
public <T> void socketAdapter(SocketOption<T> option, T value) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
223 |
throws Exception |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
224 |
{ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
225 |
try (Socket s = SocketChannel.open().socket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
226 |
expectThrows(IAE, () -> s.setOption(option, value)); |
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 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
230 |
// -- ServerSocket |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
231 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
232 |
@DataProvider(name = "serverSocketBadOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
233 |
public Object[][] serverSocketBadOptionValues() throws Exception { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
234 |
try (ServerSocket ss = new ServerSocket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
235 |
return ss.supportedOptions().stream() |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
236 |
.flatMap(NullsAndBadValues::socketOptionToBadValues) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
237 |
.toArray(Object[][]::new); |
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 |
@Test(dataProvider = "serverSocketBadOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
242 |
public <T> void serverSocket(SocketOption<T> option, T value) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
243 |
throws Exception |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
244 |
{ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
245 |
try (ServerSocket ss = new ServerSocket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
246 |
expectThrows(IAE, () -> ss.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
247 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
248 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
249 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
250 |
@Test(dataProvider = "serverSocketBadOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
251 |
public <T> void serverSocketAdapter(SocketOption<T> option, T value) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
252 |
throws Exception |
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 |
if (option == IP_TOS) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
255 |
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
|
256 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
257 |
try (ServerSocket ss = ServerSocketChannel.open().socket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
258 |
expectThrows(IAE, () -> ss.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
259 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
260 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
261 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
262 |
// -- DatagramSocket |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
263 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
264 |
@DataProvider(name = "datagramSocketBadOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
265 |
public Object[][] datagramSocketBadOptionValues() throws Exception { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
266 |
try (DatagramSocket ds = new DatagramSocket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
267 |
return ds.supportedOptions().stream() |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
268 |
.flatMap(NullsAndBadValues::socketOptionToBadValues) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
269 |
.toArray(Object[][]::new); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
270 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
271 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
272 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
273 |
@Test(dataProvider = "datagramSocketBadOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
274 |
public <T> void datagramSocket(SocketOption<T> option, T value) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
275 |
throws Exception |
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 |
try (DatagramSocket ds = new DatagramSocket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
278 |
expectThrows(IAE, () -> ds.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
279 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
280 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
281 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
282 |
@Test(dataProvider = "datagramSocketBadOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
283 |
public <T> void datagramSocketAdapter(SocketOption<T> option, T value) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
284 |
throws Exception |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
285 |
{ |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
286 |
try (DatagramSocket ds = DatagramChannel.open().socket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
287 |
expectThrows(IAE, () -> ds.setOption(option, value)); |
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 |
// -- MulticastSocket |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
292 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
293 |
@DataProvider(name = "multicastSocketBadOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
294 |
public Object[][] multicastSocketBadOptionValues() throws Exception { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
295 |
try (MulticastSocket ms = new MulticastSocket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
296 |
return ms.supportedOptions().stream() |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
297 |
.flatMap(NullsAndBadValues::socketOptionToBadValues) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
298 |
.toArray(Object[][]::new); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
299 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
300 |
} |
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 |
@Test(dataProvider = "multicastSocketBadOptionValues") |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
303 |
public <T> void multicastSocket(SocketOption<T> option, T value) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
304 |
throws Exception |
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 |
try (MulticastSocket ms = new MulticastSocket()) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
307 |
expectThrows(IAE, () -> ms.setOption(option, value)); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
308 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
309 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
310 |
|
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 |
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
|
314 |
List<Object> l = new ArrayList<>(); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
315 |
if (objs == null) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
316 |
l.add(null); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
317 |
else |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
318 |
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
|
319 |
return l; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
320 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
321 |
|
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
322 |
static Stream<Object[]> socketOptionToBadValues(SocketOption<?> socketOption) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
323 |
List<Object> values = BAD_OPTION_VALUES.get(socketOption); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
324 |
if (values == null) { |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
325 |
Object[][] a = new Object[][] { new Object[] { socketOption, null } }; |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
326 |
return Stream.of(a); |
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 |
return values.stream() |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
329 |
.flatMap(v -> Stream.of(new Object[][] { new Object[] { socketOption, v } }) ); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
330 |
} |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
diff
changeset
|
331 |
} |