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:
Trustin Lee 2014-05-28 09:38:42 +09:00
parent 0b5e1ced97
commit ba92cd4c3e

View File

@ -24,11 +24,13 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
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];