77package netty ;
88
99import java .io .InputStream ;
10+ import java .net .Inet6Address ;
11+ import java .nio .channels .UnsupportedAddressTypeException ;
12+ import java .nio .channels .spi .SelectorProvider ;
1013import java .time .Duration ;
1114import java .util .Objects ;
1215import java .util .concurrent .atomic .AtomicReference ;
5659import io .netty .util .CharsetUtil ;
5760import org .awaitility .Awaitility ;
5861import org .hamcrest .CoreMatchers ;
62+ import org .junit .jupiter .api .Assertions ;
63+ import org .junit .jupiter .api .Assumptions ;
5964import org .junit .jupiter .api .Test ;
6065
66+ import static io .netty .channel .socket .InternetProtocolFamily .IPv4 ;
67+ import static io .netty .util .NetUtil .LOCALHOST ;
68+
6169public class NettyTests {
6270 private static final int PORT = 8080 ;
6371
@@ -71,6 +79,36 @@ public void noSsl() throws Exception {
7179 test (false );
7280 }
7381
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+
74112 private void test (boolean ssl ) throws Exception {
75113 EventLoopGroup bossGroup = new NioEventLoopGroup (1 );
76114 EventLoopGroup workerGroup = new NioEventLoopGroup ();
0 commit comments