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.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException; import java.net.SocketException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousServerSocketChannel; import java.nio.channels.AsynchronousServerSocketChannel;
@ -389,42 +391,40 @@ public class IOTest
@Test @Test
public void testReset() throws Exception public void testReset() throws Exception
{ {
ServerSocket connector; try (ServerSocket connector = new ServerSocket(0);
Socket client; Socket client = new Socket("127.0.0.1", connector.getLocalPort());
Socket server; Socket server = connector.accept();)
{
client.setTcpNoDelay(true);
client.setSoLinger(true, 0);
server.setTcpNoDelay(true);
server.setSoLinger(true, 0);
connector = new ServerSocket(0); client.getOutputStream().write(1);
client = new Socket("127.0.0.1", connector.getLocalPort()); assertEquals(1, server.getInputStream().read());
server = connector.accept(); server.getOutputStream().write(1);
client.setTcpNoDelay(true); assertEquals(1, client.getInputStream().read());
client.setSoLinger(true, 0);
server.setTcpNoDelay(true);
server.setSoLinger(true, 0);
client.getOutputStream().write(1); // Server generator shutdowns output after non persistent sending response.
assertEquals(1, server.getInputStream().read()); server.shutdownOutput();
server.getOutputStream().write(1);
assertEquals(1, client.getInputStream().read());
// Server generator shutdowns output after non persistent sending response. // client endpoint reads EOF and shutdown input as result
server.shutdownOutput(); assertEquals(-1, client.getInputStream().read());
client.shutdownInput();
// client endpoint reads EOF and shutdown input as result // client connection see's EOF and shutsdown output as no more requests to be sent.
assertEquals(-1, client.getInputStream().read()); client.shutdownOutput();
client.shutdownInput();
// client connection see's EOF and shutsdown output as no more requests to be sent. // Since input already shutdown, client also closes socket.
client.shutdownOutput(); client.close();
// Since input already shutdown, client also closes socket. // Server reads the EOF from client oshut and shut's down it's input
client.close(); assertEquals(-1, server.getInputStream().read());
server.shutdownInput();
// Server reads the EOF from client oshut and shut's down it's input // Since output was already shutdown, server closes
assertEquals(-1, server.getInputStream().read()); server.close();
server.shutdownInput(); }
// Since output was already shutdown, server closes
server.close();
} }
@Test @Test
@ -432,10 +432,12 @@ public class IOTest
{ {
AsynchronousServerSocketChannel connector = AsynchronousServerSocketChannel.open(); AsynchronousServerSocketChannel connector = AsynchronousServerSocketChannel.open();
connector.bind(null); connector.bind(null);
InetSocketAddress addr=(InetSocketAddress)connector.getLocalAddress();
Future<AsynchronousSocketChannel> acceptor = connector.accept(); Future<AsynchronousSocketChannel> acceptor = connector.accept();
AsynchronousSocketChannel client = AsynchronousSocketChannel.open(); 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); AsynchronousSocketChannel server = acceptor.get(5, TimeUnit.SECONDS);