7
7
package netty ;
8
8
9
9
import java .io .InputStream ;
10
+ import java .net .Inet6Address ;
11
+ import java .nio .channels .UnsupportedAddressTypeException ;
12
+ import java .nio .channels .spi .SelectorProvider ;
10
13
import java .time .Duration ;
11
14
import java .util .Objects ;
12
15
import java .util .concurrent .atomic .AtomicReference ;
56
59
import io .netty .util .CharsetUtil ;
57
60
import org .awaitility .Awaitility ;
58
61
import org .hamcrest .CoreMatchers ;
62
+ import org .junit .jupiter .api .Assertions ;
63
+ import org .junit .jupiter .api .Assumptions ;
59
64
import org .junit .jupiter .api .Test ;
60
65
66
+ import static io .netty .channel .socket .InternetProtocolFamily .IPv4 ;
67
+ import static io .netty .util .NetUtil .LOCALHOST ;
68
+
61
69
public class NettyTests {
62
70
private static final int PORT = 8080 ;
63
71
@@ -71,6 +79,36 @@ public void noSsl() throws Exception {
71
79
test (false );
72
80
}
73
81
82
+ @ Test
83
+ void testNioSocketChannel () {
84
+ Assumptions .assumeTrue (LOCALHOST instanceof Inet6Address );
85
+
86
+ EventLoopGroup group = new NioEventLoopGroup ();
87
+ try {
88
+ Bootstrap b = new Bootstrap ().group (group )
89
+ .channelFactory (() -> new NioSocketChannel (SelectorProvider .provider (), IPv4 ))
90
+ .handler (new LoggingHandler ());
91
+ Assertions .assertThrows (UnsupportedAddressTypeException .class , () -> b .bind (LOCALHOST , 7777 ).sync ().channel ());
92
+ } finally {
93
+ group .shutdownGracefully ();
94
+ }
95
+ }
96
+
97
+ @ Test
98
+ void testNioServerSocketChannel () {
99
+ Assumptions .assumeTrue (LOCALHOST instanceof Inet6Address );
100
+
101
+ EventLoopGroup group = new NioEventLoopGroup ();
102
+ try {
103
+ Bootstrap b = new Bootstrap ().group (group )
104
+ .channelFactory (() -> new NioServerSocketChannel (SelectorProvider .provider (), IPv4 ))
105
+ .handler (new LoggingHandler ());
106
+ Assertions .assertThrows (UnsupportedAddressTypeException .class , () -> b .bind (LOCALHOST , 7777 ).sync ().channel ());
107
+ } finally {
108
+ group .shutdownGracefully ();
109
+ }
110
+ }
111
+
74
112
private void test (boolean ssl ) throws Exception {
75
113
EventLoopGroup bossGroup = new NioEventLoopGroup (1 );
76
114
EventLoopGroup workerGroup = new NioEventLoopGroup ();
0 commit comments