aboutsummaryrefslogtreecommitdiff
path: root/test/java/net/Socket/asyncClose/Socket_getOutputStream_write.java
diff options
context:
space:
mode:
authorDana Dahlstrom <dahlstrom@google.com>2020-01-30 12:00:00 -0800
committerDana Dahlstrom <dahlstrom@google.com>2020-02-10 12:00:00 -0800
commit48adcc45b3935045b1ff2013ecfd05e6f3bdb1cc (patch)
tree7e47ce0d2a402a9e765541e514aa969ef8325928 /test/java/net/Socket/asyncClose/Socket_getOutputStream_write.java
parente5752ae568d3c43497ae4f33d731fadf4ef165d4 (diff)
parent5b42bd7c94ffa67028549cac0264d79e24b2febd (diff)
downloadjdk8u_jdk-48adcc45b3935045b1ff2013ecfd05e6f3bdb1cc.tar.gz
Merge tag jb8u232-b1638.6
Change-Id: I5b42bd7c94ffa67028549cac0264d79e24b2febd
Diffstat (limited to 'test/java/net/Socket/asyncClose/Socket_getOutputStream_write.java')
-rw-r--r--test/java/net/Socket/asyncClose/Socket_getOutputStream_write.java62
1 files changed, 37 insertions, 25 deletions
diff --git a/test/java/net/Socket/asyncClose/Socket_getOutputStream_write.java b/test/java/net/Socket/asyncClose/Socket_getOutputStream_write.java
index 841861d919..78cbf45014 100644
--- a/test/java/net/Socket/asyncClose/Socket_getOutputStream_write.java
+++ b/test/java/net/Socket/asyncClose/Socket_getOutputStream_write.java
@@ -27,9 +27,16 @@
*/
import java.net.*;
import java.io.*;
+import java.util.concurrent.CountDownLatch;
public class Socket_getOutputStream_write extends AsyncCloseTest implements Runnable {
- Socket s;
+ private final Socket s;
+ private final CountDownLatch latch;
+
+ public Socket_getOutputStream_write() {
+ latch = new CountDownLatch(1);
+ s = new Socket();
+ }
public String description() {
return "Socket.getOutputStream().write()";
@@ -38,40 +45,45 @@ public class Socket_getOutputStream_write extends AsyncCloseTest implements Runn
public void run() {
try {
OutputStream out = s.getOutputStream();
+ byte b[] = new byte[8192];
+ latch.countDown();
for (;;) {
- byte b[] = new byte[8192];
out.write(b);
}
} catch (SocketException se) {
- closed();
+ if (latch.getCount() != 1) {
+ closed();
+ }
} catch (Exception e) {
failed(e.getMessage());
+ } finally {
+ if (latch.getCount() == 1) {
+ latch.countDown();
+ }
}
}
- public boolean go() throws Exception {
- ServerSocket ss = new ServerSocket(0);
-
- InetAddress lh = InetAddress.getLocalHost();
- s = new Socket();
- s.connect( new InetSocketAddress(lh, ss.getLocalPort()) );
-
- Socket s2 = ss.accept();
-
- Thread thr = new Thread(this);
- thr.start();
-
- Thread.currentThread().sleep(2000);
-
- s.close();
-
- Thread.currentThread().sleep(2000);
+ public AsyncCloseTest go() {
+ try {
+ ServerSocket ss = new ServerSocket(0);
+ InetAddress lh = InetAddress.getLocalHost();
+ s.connect( new InetSocketAddress(lh, ss.getLocalPort()) );
+ Socket s2 = ss.accept();
+ Thread thr = new Thread(this);
+ thr.start();
+ latch.await();
+ Thread.sleep(1000);
+ s.close();
+ thr.join();
- if (isClosed()) {
- return true;
- } else {
- failed("getOutputStream().write() wasn't preempted");
- return false;
+ if (isClosed()) {
+ return passed();
+ } else {
+ return failed("Socket.getOutputStream().write() wasn't preempted");
+ }
+ } catch (Exception x) {
+ failed(x.getMessage());
+ throw new RuntimeException(x);
}
}
}