提交 cd0823d7 编写于 作者: M michaelm

8028581: [TESTBUG] java/net/Socket/LingerTest.java failing

Reviewed-by: alanb
上级 679bbc46
...@@ -68,20 +68,21 @@ public class LingerTest { ...@@ -68,20 +68,21 @@ public class LingerTest {
} }
} }
static class Another implements Runnable { static class Other implements Runnable {
int port; int port;
long delay; long delay;
boolean connected = false; boolean connected = false;
public Another(int port, long delay) { public Other(int port, long delay) {
this.port = port; this.port = port;
this.delay = delay; this.delay = delay;
} }
public void run() { public void run() {
System.out.println ("Another starts"); System.out.println ("Other starts: sleep " + delay);
try { try {
Thread.sleep(delay); Thread.sleep(delay);
System.out.println ("Other opening socket");
Socket s = new Socket("localhost", port); Socket s = new Socket("localhost", port);
synchronized (this) { synchronized (this) {
connected = true; connected = true;
...@@ -91,7 +92,7 @@ public class LingerTest { ...@@ -91,7 +92,7 @@ public class LingerTest {
catch (Exception ioe) { catch (Exception ioe) {
ioe.printStackTrace(); ioe.printStackTrace();
} }
System.out.println ("Another ends"); System.out.println ("Other ends");
} }
public synchronized boolean connected() { public synchronized boolean connected() {
...@@ -115,27 +116,29 @@ public class LingerTest { ...@@ -115,27 +116,29 @@ public class LingerTest {
Thread thr = new Thread(new Sender(s1)); Thread thr = new Thread(new Sender(s1));
thr.start(); thr.start();
// another thread that will connect after 5 seconds. // other thread that will connect after 5 seconds.
Another another = new Another(ss.getLocalPort(), 5000); Other other = new Other(ss.getLocalPort(), 5000);
thr = new Thread(another); thr = new Thread(other);
thr.start(); thr.start();
// give sender time to queue the data // give sender time to queue the data
System.out.println ("Main sleep 1000");
Thread.sleep(1000); Thread.sleep(1000);
System.out.println ("Main continue");
// close the socket asynchronously // close the socket asynchronously
(new Thread(new Closer(s1))).start(); (new Thread(new Closer(s1))).start();
// give another time to run System.out.println ("Main sleep 15000");
Thread.sleep(10000); // give other time to run
Thread.sleep(15000);
System.out.println ("Main closing serversocket");
ss.close(); ss.close();
// check that another is done // check that other is done
if (!another.connected()) { if (!other.connected()) {
throw new RuntimeException("Another thread is blocked"); throw new RuntimeException("Other thread is blocked");
} }
System.out.println ("Main ends"); System.out.println ("Main ends");
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册