Work around the system configuration issue that causes NioSocketChannelTest to fail
Motivation: On some ill-configured systems, InetAddress.getLocalHost() fails. NioSocketChannelTest calls java.net.Socket.connect() and it internally invoked InetAddress.getLocalHost(), which causes the test failures in NioSocketChannelTes on such an ill-configured system. Modifications: Use NetUtil.LOCALHOST explicitly. Result: NioSocketChannelTest should not fail anymore.
This commit is contained in:
parent
e044fc3e56
commit
d90207b3ac
@ -24,11 +24,13 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import io.netty.util.NetUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
@ -68,8 +70,7 @@ public class NioSocketChannelTest {
|
||||
|
||||
SocketAddress address = sb.bind(0).sync().channel().localAddress();
|
||||
|
||||
Socket s = new Socket();
|
||||
s.connect(address);
|
||||
Socket s = new Socket(NetUtil.LOCALHOST, ((InetSocketAddress) address).getPort());
|
||||
|
||||
InputStream in = s.getInputStream();
|
||||
byte[] buf = new byte[8192];
|
||||
@ -127,8 +128,7 @@ public class NioSocketChannelTest {
|
||||
|
||||
SocketAddress address = sb.bind(0).sync().channel().localAddress();
|
||||
|
||||
Socket s = new Socket();
|
||||
s.connect(address);
|
||||
Socket s = new Socket(NetUtil.LOCALHOST, ((InetSocketAddress) address).getPort());
|
||||
|
||||
DataInput in = new DataInputStream(s.getInputStream());
|
||||
byte[] buf = new byte[3];
|
||||
|
Loading…
Reference in New Issue
Block a user