420572 IOTest explicitly uses 127.0.0.1

This commit is contained in:
Greg Wilkins 2013-11-01 12:17:30 +11:00
parent 466725e343
commit a76ddc1c6a
1 changed files with 33 additions and 31 deletions

View File

@ -26,8 +26,10 @@ import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousServerSocketChannel;
@ -389,13 +391,10 @@ public class IOTest
@Test
public void testReset() throws Exception
{
ServerSocket connector;
Socket client;
Socket server;
connector = new ServerSocket(0);
client = new Socket("127.0.0.1", connector.getLocalPort());
server = connector.accept();
try (ServerSocket connector = new ServerSocket(0);
Socket client = new Socket("127.0.0.1", connector.getLocalPort());
Socket server = connector.accept();)
{
client.setTcpNoDelay(true);
client.setSoLinger(true, 0);
server.setTcpNoDelay(true);
@ -426,16 +425,19 @@ public class IOTest
// Since output was already shutdown, server closes
server.close();
}
}
@Test
public void testAsyncSocketChannel() throws Exception
{
AsynchronousServerSocketChannel connector = AsynchronousServerSocketChannel.open();
connector.bind(null);
InetSocketAddress addr=(InetSocketAddress)connector.getLocalAddress();
Future<AsynchronousSocketChannel> acceptor = connector.accept();
AsynchronousSocketChannel client = AsynchronousSocketChannel.open();
client.connect(connector.getLocalAddress()).get(5, TimeUnit.SECONDS);
client.connect(new InetSocketAddress("127.0.0.1",addr.getPort())).get(5, TimeUnit.SECONDS);
AsynchronousSocketChannel server = acceptor.get(5, TimeUnit.SECONDS);