提交 f5d53f78 编写于 作者: A alanb

6961630: TEST_BUG: Several SocketChannel and Selector tests can fail with "address already in use"

Reviewed-by: chegar
上级 101a96ea
......@@ -740,9 +740,6 @@ com/sun/nio/sctp/SctpChannel/Shutdown.java generic-all
# at SetLastModified.main(SetLastModified.java:107)
java/io/File/SetLastModified.java generic-all
# Fails on Fedora 9 x86, address in use
java/nio/channels/Selector/SelectWrite.java generic-all
# Fails on Windows 2000, times out
java/nio/channels/FileChannel/Transfer.java generic-all
......@@ -756,9 +753,6 @@ com/sun/nio/sctp/SctpChannel/Receive.java generic-all
# Triggers a hotspot crash on Fedora 9 32bit -server and Windows X64 samevm
sun/nio/cs/TestUTF8.java generic-all
# Solaris sparc, socket timeout
java/nio/channels/spi/SelectorProvider/inheritedChannel/run_tests.sh generic-all
# Runtime exception on windows X64, samevm mode
java/nio/channels/Selector/WakeupNow.java generic-all
......@@ -818,15 +812,6 @@ java/nio/channels/ServerSocketChannel/AdaptServerSocket.java windows-all
java/nio/channels/SocketChannel/ConnectState.java windows-all
java/nio/channels/SocketChannel/FinishConnect.java windows-all
# Gets java.net.BindException alot (static port number?)
java/nio/channels/SocketChannel/VectorIO.java generic-all
# Solaris i586 java.net.BindExceptions
java/nio/channels/SocketChannel/VectorParams.java solaris-all
# Linux i586 address already in use, samevm issues
java/nio/channels/SocketChannel/Write.java generic-all
# Fails on all platforms due to overlap of JDK jar file contents:
sun/nio/cs/Test4200310.sh generic-all
......
......@@ -33,7 +33,6 @@ import java.net.ServerSocket;
public class ByteServer {
public static final int PORT = 31415;
public static final String LOCALHOST = "localhost";
private int bytecount;
private Socket socket;
......@@ -43,7 +42,11 @@ public class ByteServer {
public ByteServer(int bytecount) throws Exception{
this.bytecount = bytecount;
serversocket = new ServerSocket(PORT);
serversocket = new ServerSocket(0);
}
public int port() {
return serversocket.getLocalPort();
}
public void start() {
......
......@@ -32,17 +32,19 @@ import java.nio.channels.*;
public class CloseThenRegister {
public static void main (String [] args) throws Exception {
Selector sel = Selector.open();
sel.close();
ServerSocketChannel ssc = ServerSocketChannel.open();
try {
Selector s = Selector.open();
s.close();
ServerSocketChannel c = ServerSocketChannel.open();
c.socket().bind(new InetSocketAddress(40000));
c.configureBlocking(false);
c.register(s, SelectionKey.OP_ACCEPT);
ssc.bind(new InetSocketAddress(0));
ssc.configureBlocking(false);
ssc.register(sel, SelectionKey.OP_ACCEPT);
throw new RuntimeException("register after close does not cause CSE!");
} catch (ClosedSelectorException cse) {
return;
// expected
} finally {
ssc.close();
}
throw new RuntimeException("register after close does not cause CSE!");
}
}
......@@ -37,7 +37,7 @@ public class ReadAfterConnect {
ByteServer server = new ByteServer(0); // server: accept connection and do nothing
server.start();
InetSocketAddress isa = new InetSocketAddress(
InetAddress.getByName(ByteServer.LOCALHOST), ByteServer.PORT);
InetAddress.getByName(ByteServer.LOCALHOST), server.port());
Selector sel = Selector.open();
SocketChannel sc = SocketChannel.open();
sc.connect(isa);
......
......@@ -37,14 +37,14 @@ public class SelectAfterRead {
final static int TIMEOUT = 1000;
public static void main(String[] argv) throws Exception {
InetAddress lh = InetAddress.getByName(ByteServer.LOCALHOST);
// server: accept connection and write one byte
ByteServer server = new ByteServer(1);
server.start();
InetSocketAddress isa = new InetSocketAddress(
InetAddress.getByName(ByteServer.LOCALHOST), ByteServer.PORT);
Selector sel = Selector.open();
SocketChannel sc = SocketChannel.open();
sc.connect(isa);
sc.connect(new InetSocketAddress(lh, server.port()));
sc.read(ByteBuffer.allocate(1));
sc.configureBlocking(false);
sc.register(sel, SelectionKey.OP_READ);
......@@ -61,7 +61,7 @@ public class SelectAfterRead {
server = new ByteServer(2);
server.start();
sc = SocketChannel.open();
sc.connect(isa);
sc.connect(new InetSocketAddress(lh, server.port()));
sc.configureBlocking(false);
sel = Selector.open();
sc.register(sel, SelectionKey.OP_READ);
......
......@@ -39,7 +39,7 @@ public class SelectWrite {
// server: accept connection and do nothing
server.start();
InetSocketAddress isa = new InetSocketAddress(
InetAddress.getByName(ByteServer.LOCALHOST), ByteServer.PORT);
InetAddress.getByName(ByteServer.LOCALHOST), server.port());
Selector sel = Selector.open();
SocketChannel sc = SocketChannel.open();
sc.connect(isa);
......
......@@ -32,7 +32,6 @@ import java.nio.channels.*;
public class BigReadWrite {
static int port = 40170;
static int testSize = 15;
public static void main(String[] args) throws Exception {
......
......@@ -36,8 +36,6 @@ import sun.misc.*;
public class VectorIO {
static int port = 40170;
static Random generator = new Random();
static int testSize;
......@@ -55,20 +53,12 @@ public class VectorIO {
System.err.println("Length " + testSize);
Server sv = new Server(testSize);
sv.start();
do {
try {
Thread.currentThread().sleep(200);
} catch (InterruptedException x) {
if (sv.finish(8000) == 0)
throw new Exception("Failed: Error in server thread");
}
} while (!sv.ready);
bufferTest();
bufferTest(sv.port());
if (sv.finish(8000) == 0)
throw new Exception("Failed: Length = " + testSize);
}
static void bufferTest() throws Exception {
static void bufferTest(int port) throws Exception {
ByteBuffer[] bufs = new ByteBuffer[testSize];
for(int i=0; i<testSize; i++) {
String source = "buffer" + i;
......@@ -105,17 +95,19 @@ public class VectorIO {
static class Server
extends TestThread
{
static int port = 40170;
static Random generator = new Random();
int testSize;
volatile boolean ready = false;
final int testSize;
final ServerSocketChannel ssc;
Server(int testSize) {
Server(int testSize) throws IOException {
super("Server " + testSize);
this.testSize = testSize;
this.ssc = ServerSocketChannel.open().bind(new InetSocketAddress(0));
}
int port() {
return ssc.socket().getLocalPort();
}
void go() throws Exception {
......@@ -133,16 +125,11 @@ public class VectorIO {
}
// Get a connection from client
ServerSocketChannel ssc = ServerSocketChannel.open();
SocketChannel sc = null;
try {
ssc.configureBlocking(false);
InetAddress lh = InetAddress.getLocalHost();
InetSocketAddress isa = new InetSocketAddress(lh, port);
ssc.socket().bind(isa);
ready = true;
for (;;) {
sc = ssc.accept();
......
......@@ -37,8 +37,6 @@ import sun.misc.*;
public class Write {
static int port = 40170;
static Random generator = new Random();
static int testSize = 15;
......@@ -46,20 +44,12 @@ public class Write {
public static void main(String[] args) throws Exception {
WriteServer sv = new WriteServer();
sv.start();
do {
try {
Thread.currentThread().sleep(200);
} catch (InterruptedException x) {
if (sv.finish(8000) == 0)
throw new Exception("Failed: Error in server thread");
}
} while (!sv.ready);
bufferTest();
bufferTest(sv.port());
if (sv.finish(8000) == 0)
throw new Exception("Failed" );
}
static void bufferTest() throws Exception {
static void bufferTest(int port) throws Exception {
ByteBuffer[] bufs = new ByteBuffer[testSize];
for(int i=0; i<testSize; i++) {
String source =
......@@ -94,14 +84,18 @@ public class Write {
class WriteServer extends TestThread {
static int port = 40170;
static Random generator = new Random();
volatile boolean ready = false;
WriteServer() {
final ServerSocketChannel ssc;
WriteServer() throws IOException {
super("WriteServer");
this.ssc = ServerSocketChannel.open().bind(new InetSocketAddress(0));
}
int port() {
return ssc.socket().getLocalPort();
}
void go() throws Exception {
......@@ -112,15 +106,10 @@ class WriteServer extends TestThread {
ByteBuffer buf = ByteBuffer.allocateDirect(5);
// Get a connection from client
ServerSocketChannel ssc = ServerSocketChannel.open();
SocketChannel sc = null;
try {
ssc.configureBlocking(false);
InetAddress lh = InetAddress.getLocalHost();
InetSocketAddress isa = new InetSocketAddress(lh, port);
ssc.socket().bind(isa);
ready = true;
for (;;) {
sc = ssc.accept();
......
......@@ -141,7 +141,7 @@ public class EchoTest {
// and receive the echo
byte b[] = new byte[msg.length() + 100];
DatagramPacket pkt2 = new DatagramPacket(b, b.length);
dc.socket().setSoTimeout(2000);
dc.socket().setSoTimeout(5000);
dc.socket().receive(pkt2);
if (pkt2.getLength() != msg.length()) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册