aboutsummaryrefslogtreecommitdiff
path: root/test/java/nio/channels
diff options
context:
space:
mode:
authoralanb <none@none>2013-08-15 13:42:45 +0100
committeralanb <none@none>2013-08-15 13:42:45 +0100
commit9f4cf8c476e2c1d76faad2c7b55c2429c7610948 (patch)
tree84f65d5900104056586b0a5ac64d212995643edb /test/java/nio/channels
parent92674b7701e8c56a31641d3bc6085d722961c109 (diff)
8015765: TEST_BUG: java/nio/channels/ServerSocketChannel/AdaptServerSocket.java failing intermittently
Reviewed-by: chegar, dholmes, alanb Contributed-by: yiming.wang@oracle.com
Diffstat (limited to 'test/java/nio/channels')
-rw-r--r--test/java/nio/channels/ServerSocketChannel/AdaptServerSocket.java75
1 files changed, 37 insertions, 38 deletions
diff --git a/test/java/nio/channels/ServerSocketChannel/AdaptServerSocket.java b/test/java/nio/channels/ServerSocketChannel/AdaptServerSocket.java
index f45460135..a39549f2e 100644
--- a/test/java/nio/channels/ServerSocketChannel/AdaptServerSocket.java
+++ b/test/java/nio/channels/ServerSocketChannel/AdaptServerSocket.java
@@ -35,7 +35,7 @@ import java.nio.charset.*;
public class AdaptServerSocket {
static java.io.PrintStream out = System.out;
-
+ static volatile boolean clientStarted = false;
static volatile Exception clientException = null;
static volatile Thread client = null;
@@ -44,15 +44,14 @@ public class AdaptServerSocket {
{
Thread t = new Thread() {
public void run() {
- try {
- Socket so = new Socket();
+ try (Socket so = new Socket()) {
out.println("client: " + so);
+ clientStarted = true;
if (dally > 0)
Thread.sleep(dally);
so.connect(new InetSocketAddress(port));
if (Thread.interrupted()) {
out.println("client interrupted");
- so.close();
return;
}
out.println("client: " + so);
@@ -61,7 +60,6 @@ public class AdaptServerSocket {
a += 1;
so.getOutputStream().write(a);
out.println("client: wrote " + a);
- so.close();
} catch (Exception x) {
if (x instanceof InterruptedException)
return;
@@ -78,43 +76,44 @@ public class AdaptServerSocket {
static void test(int clientDally, int timeout, boolean shouldTimeout)
throws Exception
{
+ clientStarted = false;
out.println();
- ServerSocketChannel ssc = ServerSocketChannel.open();
- ServerSocket sso = ssc.socket();
- out.println("created: " + ssc);
- out.println(" " + sso);
- if (timeout != 0)
- sso.setSoTimeout(timeout);
- out.println("timeout: " + sso.getSoTimeout());
- sso.bind(null);
- out.println("bound: " + ssc);
- out.println(" " + sso);
- startClient(sso.getLocalPort(), clientDally);
- Thread.sleep(10);
-
- Socket so = null;
- try {
- so = sso.accept();
- } catch (SocketTimeoutException x) {
- if (shouldTimeout)
- out.println("Accept timed out, as expected");
- else
- throw x;
- }
- if (shouldTimeout && (so != null))
- throw new Exception("Accept did not time out");
+ try (ServerSocketChannel ssc = ServerSocketChannel.open();
+ ServerSocket sso = ssc.socket()) {
+ out.println("created: " + ssc);
+ out.println(" " + sso);
+ if (timeout != 0)
+ sso.setSoTimeout(timeout);
+ out.println("timeout: " + sso.getSoTimeout());
+ sso.bind(null);
+ out.println("bound: " + ssc);
+ out.println(" " + sso);
+ startClient(sso.getLocalPort(), clientDally);
+ while (!clientStarted) {
+ Thread.sleep(20);
+ }
+ Socket so = null;
+ try {
+ so = sso.accept();
+ } catch (SocketTimeoutException x) {
+ if (shouldTimeout)
+ out.println("Accept timed out, as expected");
+ else
+ throw x;
+ }
+ if (shouldTimeout && (so != null))
+ throw new Exception("Accept did not time out");
- if (so != null) {
- int a = 42;
- so.getOutputStream().write(a);
- int b = so.getInputStream().read();
- if (b != a + 1)
- throw new Exception("Read incorrect data");
- out.println("server: read " + b);
- sso.close();
+ if (so != null) {
+ int a = 42;
+ so.getOutputStream().write(a);
+ int b = so.getInputStream().read();
+ if (b != a + 1)
+ throw new Exception("Read incorrect data");
+ out.println("server: read " + b);
+ }
}
-
client.interrupt();
client.join();
if (clientException != null)