提交 23e0c2a0 编写于 作者: A alanb

8151582: (ch) test java/nio/channels/AsyncCloseAndInterrupt.java failing due...

8151582: (ch) test java/nio/channels/AsyncCloseAndInterrupt.java failing due to "Connection succeeded"
Reviewed-by: bpb, rriggs, alanb
Contributed-by: huaming.li@oracle.com
上级 c64db578
/* /*
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
/* @test /* @test
* @bug 4460583 4470470 4840199 6419424 6710579 6596323 6824135 6395224 7142919 * @bug 4460583 4470470 4840199 6419424 6710579 6596323 6824135 6395224 7142919
* 8151582
* @run main/othervm AsyncCloseAndInterrupt * @run main/othervm AsyncCloseAndInterrupt
* @summary Comprehensive test of asynchronous closing and interruption * @summary Comprehensive test of asynchronous closing and interruption
* @author Mark Reinhold * @author Mark Reinhold
...@@ -89,7 +90,7 @@ public class AsyncCloseAndInterrupt { ...@@ -89,7 +90,7 @@ public class AsyncCloseAndInterrupt {
private static void initRefuser() throws IOException { private static void initRefuser() throws IOException {
refuser = ServerSocketChannel.open(); refuser = ServerSocketChannel.open();
refuser.socket().bind(wildcardAddress); refuser.bind(wildcardAddress, 1); // use minimum backlog
} }
// Dead pipe source and sink // Dead pipe source and sink
...@@ -349,7 +350,7 @@ public class AsyncCloseAndInterrupt { ...@@ -349,7 +350,7 @@ public class AsyncCloseAndInterrupt {
static final Op CONNECT = new Op("connect") { static final Op CONNECT = new Op("connect") {
void setup() { void setup() {
waitPump("connect wait for pumping refuser ..."); waitPump("connect waiting for pumping refuser ...");
} }
void doIO(InterruptibleChannel ich) throws IOException { void doIO(InterruptibleChannel ich) throws IOException {
SocketChannel sc = (SocketChannel)ich; SocketChannel sc = (SocketChannel)ich;
...@@ -361,7 +362,7 @@ public class AsyncCloseAndInterrupt { ...@@ -361,7 +362,7 @@ public class AsyncCloseAndInterrupt {
static final Op FINISH_CONNECT = new Op("finishConnect") { static final Op FINISH_CONNECT = new Op("finishConnect") {
void setup() { void setup() {
waitPump("finishConnect wait for pumping refuser ..."); waitPump("finishConnect waiting for pumping refuser ...");
} }
void doIO(InterruptibleChannel ich) throws IOException { void doIO(InterruptibleChannel ich) throws IOException {
SocketChannel sc = (SocketChannel)ich; SocketChannel sc = (SocketChannel)ich;
...@@ -498,12 +499,11 @@ public class AsyncCloseAndInterrupt { ...@@ -498,12 +499,11 @@ public class AsyncCloseAndInterrupt {
private static volatile boolean pumpReady = false; private static volatile boolean pumpReady = false;
private static void waitPump(String msg){ private static void waitPump(String msg){
pumpReady = false;
log.println(msg); log.println(msg);
while (!pumpReady){ while (!pumpReady){
sleep(200); sleep(200);
} }
log.println(msg + " done");
} }
// Create a pump thread dedicated to saturate refuser's connection backlog // Create a pump thread dedicated to saturate refuser's connection backlog
...@@ -520,28 +520,34 @@ public class AsyncCloseAndInterrupt { ...@@ -520,28 +520,34 @@ public class AsyncCloseAndInterrupt {
// Saturate the refuser's connection backlog so that further connection // Saturate the refuser's connection backlog so that further connection
// attempts will be blocked // attempts will be blocked
pumpReady = false;
while (!pumpDone) { while (!pumpDone) {
SocketChannel sc = SocketChannel.open(); SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false); sc.configureBlocking(false);
boolean connected = sc.connect(refuser.socket().getLocalSocketAddress()); boolean connected = sc.connect(refuser.socket().getLocalSocketAddress());
// Assume that the connection backlog is saturated if a // Assume that the connection backlog is saturated if a
// client cannot connect to the refuser within 50 miliseconds // client cannot connect to the refuser within 50 milliseconds
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
while (!connected && (System.currentTimeMillis() - start < 50)) { while (!pumpReady && !connected
&& (System.currentTimeMillis() - start < 50)) {
connected = sc.finishConnect(); connected = sc.finishConnect();
} }
if (connected) { if (connected) {
// Retain so that finalizer doesn't close // Retain so that finalizer doesn't close
refuserClients.add(sc); refuserClients.add(sc);
pumpReady = false;
} else { } else {
sc.close(); sc.close();
pumpReady = true; pumpReady = true;
} }
} }
for (SocketChannel sc : refuserClients) {
sc.close();
}
refuser.close();
log.println("Stop pumping refuser ..."); log.println("Stop pumping refuser ...");
return refuserClients.size(); return refuserClients.size();
} }
...@@ -565,8 +571,6 @@ public class AsyncCloseAndInterrupt { ...@@ -565,8 +571,6 @@ public class AsyncCloseAndInterrupt {
sleep(50); sleep(50);
} while (!t.ready); } while (!t.ready);
sleep(100);
switch (test) { switch (test) {
case TEST_INTR: case TEST_INTR:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册