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
0b5e1ced97
commit
ba92cd4c3e
@ -24,11 +24,13 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
|
|||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
import io.netty.util.NetUtil;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.nio.channels.ClosedChannelException;
|
import java.nio.channels.ClosedChannelException;
|
||||||
@ -68,8 +70,7 @@ public class NioSocketChannelTest {
|
|||||||
|
|
||||||
SocketAddress address = sb.bind(0).sync().channel().localAddress();
|
SocketAddress address = sb.bind(0).sync().channel().localAddress();
|
||||||
|
|
||||||
Socket s = new Socket();
|
Socket s = new Socket(NetUtil.LOCALHOST, ((InetSocketAddress) address).getPort());
|
||||||
s.connect(address);
|
|
||||||
|
|
||||||
InputStream in = s.getInputStream();
|
InputStream in = s.getInputStream();
|
||||||
byte[] buf = new byte[8192];
|
byte[] buf = new byte[8192];
|
||||||
@ -127,8 +128,7 @@ public class NioSocketChannelTest {
|
|||||||
|
|
||||||
SocketAddress address = sb.bind(0).sync().channel().localAddress();
|
SocketAddress address = sb.bind(0).sync().channel().localAddress();
|
||||||
|
|
||||||
Socket s = new Socket();
|
Socket s = new Socket(NetUtil.LOCALHOST, ((InetSocketAddress) address).getPort());
|
||||||
s.connect(address);
|
|
||||||
|
|
||||||
DataInput in = new DataInputStream(s.getInputStream());
|
DataInput in = new DataInputStream(s.getInputStream());
|
||||||
byte[] buf = new byte[3];
|
byte[] buf = new byte[3];
|
||||||
|
Loading…
Reference in New Issue
Block a user