author | bpb |
Wed, 06 Feb 2019 11:54:19 -0800 | |
branch | rsocket-branch |
changeset 57154 | 4fdc05fd6996 |
parent 57115 | 512e7cc6ccce |
child 57156 | 81e4a12fd1a4 |
permissions | -rw-r--r-- |
57115 | 1 |
/* |
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
import java.io.IOException; |
|
25 |
import java.net.StandardProtocolFamily; |
|
26 |
import java.net.ServerSocket; |
|
27 |
import java.net.Socket; |
|
28 |
import java.net.SocketOption; |
|
29 |
import java.net.StandardSocketOptions; |
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.List; |
|
32 |
import jdk.net.RdmaSockets; |
|
33 |
import jdk.net.RdmaSocketOptions; |
|
34 |
||
35 |
import jtreg.SkippedException; |
|
36 |
||
37 |
/* @test |
|
38 |
* @bug 8195160 |
|
39 |
* @summary Test checks that UnsupportedOperationException for unsupported |
|
40 |
* SOCKET_OPTIONS is thrown by both getOption() and setOption() methods. |
|
41 |
* @requires (os.family == "linux") |
|
42 |
* @requires !vm.graal.enabled |
|
43 |
* @library .. /test/lib |
|
44 |
* @build RsocketTest |
|
45 |
* @run main/othervm UnsupportedOptionsTest |
|
46 |
*/ |
|
47 |
public class UnsupportedOptionsTest { |
|
48 |
||
49 |
private static final List<SocketOption<?>> socketOptions = new ArrayList<>(); |
|
50 |
||
51 |
static { |
|
57154
4fdc05fd6996
rsocket-branch: test options that neither Socket nor ServerSocket support
bpb
parents:
57115
diff
changeset
|
52 |
socketOptions.add(StandardSocketOptions.SO_KEEPALIVE); // Unsupported |
4fdc05fd6996
rsocket-branch: test options that neither Socket nor ServerSocket support
bpb
parents:
57115
diff
changeset
|
53 |
socketOptions.add(StandardSocketOptions.SO_LINGER); // Unsupported |
57115 | 54 |
socketOptions.add(StandardSocketOptions.SO_RCVBUF); |
55 |
socketOptions.add(StandardSocketOptions.SO_REUSEADDR); |
|
57154
4fdc05fd6996
rsocket-branch: test options that neither Socket nor ServerSocket support
bpb
parents:
57115
diff
changeset
|
56 |
socketOptions.add(StandardSocketOptions.SO_SNDBUF); // Socket only |
4fdc05fd6996
rsocket-branch: test options that neither Socket nor ServerSocket support
bpb
parents:
57115
diff
changeset
|
57 |
socketOptions.add(StandardSocketOptions.TCP_NODELAY); // Socket only |
57115 | 58 |
socketOptions.add(RdmaSocketOptions.RDMA_SQSIZE); |
59 |
socketOptions.add(RdmaSocketOptions.RDMA_RQSIZE); |
|
60 |
socketOptions.add(RdmaSocketOptions.RDMA_INLINE); |
|
61 |
} |
|
62 |
||
63 |
public static void main(String[] args) throws IOException { |
|
64 |
if (!RsocketTest.isRsocketAvailable()) |
|
65 |
throw new SkippedException("rsocket is not available"); |
|
66 |
||
67 |
Socket s = RdmaSockets.openSocket(StandardProtocolFamily.INET); |
|
68 |
ServerSocket ss = RdmaSockets.openServerSocket( |
|
69 |
StandardProtocolFamily.INET); |
|
70 |
||
71 |
for (SocketOption option : socketOptions) { |
|
72 |
if (!s.supportedOptions().contains(option)) { |
|
73 |
testUnsupportedSocketOption(s, option); |
|
74 |
} |
|
75 |
||
76 |
if (!ss.supportedOptions().contains(option)) { |
|
77 |
testUnsupportedSocketOption(ss, option); |
|
78 |
} |
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
/* |
|
83 |
* Check that UnsupportedOperationException for unsupported option is |
|
84 |
* thrown from both getOption() and setOption() methods. |
|
85 |
*/ |
|
86 |
private static void testUnsupportedSocketOption(Object socket, |
|
87 |
SocketOption option) { |
|
88 |
testSet(socket, option); |
|
89 |
testGet(socket, option); |
|
90 |
} |
|
91 |
||
92 |
private static void testSet(Object socket, SocketOption option) { |
|
93 |
try { |
|
94 |
setOption(socket, option); |
|
95 |
} catch (UnsupportedOperationException e) { |
|
96 |
System.out.println("UnsupportedOperationException was throw " + |
|
97 |
"as expected. Socket: " + socket + " Option: " + option); |
|
98 |
return; |
|
99 |
} catch (Exception e) { |
|
100 |
throw new RuntimeException("FAIL. Unexpected exception.", e); |
|
101 |
} |
|
102 |
throw new RuntimeException("FAIL. UnsupportedOperationException " + |
|
103 |
"hasn't been thrown. Socket: " + socket + " Option: " + option); |
|
104 |
} |
|
105 |
||
106 |
private static void testGet(Object socket, SocketOption option) { |
|
107 |
try { |
|
108 |
getOption(socket, option); |
|
109 |
} catch (UnsupportedOperationException e) { |
|
110 |
System.out.println("UnsupportedOperationException was throw " + |
|
111 |
"as expected. Socket: " + socket + " Option: " + option); |
|
112 |
return; |
|
113 |
} catch (Exception e) { |
|
114 |
throw new RuntimeException("FAIL. Unexpected exception.", e); |
|
115 |
} |
|
116 |
throw new RuntimeException("FAIL. UnsupportedOperationException " + |
|
117 |
"hasn't been thrown. Socket: " + socket + " Option: " + option); |
|
118 |
} |
|
119 |
||
120 |
private static void getOption(Object socket, |
|
121 |
SocketOption option) throws IOException { |
|
122 |
if (socket instanceof Socket) { |
|
123 |
((Socket) socket).getOption(option); |
|
124 |
} else if (socket instanceof ServerSocket) { |
|
125 |
((ServerSocket) socket).getOption(option); |
|
126 |
} else { |
|
127 |
throw new RuntimeException("Unsupported socket type"); |
|
128 |
} |
|
129 |
} |
|
130 |
||
131 |
private static void setOption(Object socket, |
|
132 |
SocketOption option) throws IOException { |
|
133 |
if (socket instanceof Socket) { |
|
134 |
((Socket) socket).setOption(option, null); |
|
135 |
} else if (socket instanceof ServerSocket) { |
|
136 |
((ServerSocket) socket).setOption(option, null); |
|
137 |
} else { |
|
138 |
throw new RuntimeException("Unsupported socket type"); |
|
139 |
} |
|
140 |
} |
|
141 |
} |