http-client-branch: review comment - fix intermittently failing PendingXxx WebSocket tests
--- a/test/jdk/java/net/httpclient/websocket/PendingBinaryPingClose.java Wed Apr 11 00:55:41 2018 +0100
+++ b/test/jdk/java/net/httpclient/websocket/PendingBinaryPingClose.java Wed Apr 11 14:21:11 2018 +0100
@@ -42,39 +42,45 @@
public class PendingBinaryPingClose extends PendingOperations {
+ CompletableFuture<WebSocket> cfBinary;
+ CompletableFuture<WebSocket> cfPing;
+ CompletableFuture<WebSocket> cfClose;
+
@Test(dataProvider = "booleans")
public void pendingBinaryPingClose(boolean last) throws Exception {
- server = Support.notReadingServer();
- server.open();
- webSocket = newHttpClient().newWebSocketBuilder()
- .buildAsync(server.getURI(), new WebSocket.Listener() { })
- .join();
- ByteBuffer data = ByteBuffer.allocate(65536);
- CompletableFuture<WebSocket> cfBinary;
- for (int i = 0; ; i++) { // fill up the send buffer
- long start = System.currentTimeMillis();
- System.out.printf("begin cycle #%s at %s%n", i, start);
- cfBinary = webSocket.sendBinary(data, last);
- try {
- cfBinary.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
- data.clear();
- } catch (TimeoutException e) {
- break;
- } finally {
- long stop = System.currentTimeMillis();
- System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ repeatable(() -> {
+ server = Support.notReadingServer();
+ server.open();
+ webSocket = newHttpClient().newWebSocketBuilder()
+ .buildAsync(server.getURI(), new WebSocket.Listener() { })
+ .join();
+ ByteBuffer data = ByteBuffer.allocate(65536);
+ for (int i = 0; ; i++) { // fill up the send buffer
+ long start = System.currentTimeMillis();
+ System.out.printf("begin cycle #%s at %s%n", i, start);
+ cfBinary = webSocket.sendBinary(data, last);
+ try {
+ cfBinary.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
+ data.clear();
+ } catch (TimeoutException e) {
+ break;
+ } finally {
+ long stop = System.currentTimeMillis();
+ System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ }
}
- }
- assertFails(ISE, webSocket.sendText("", true));
- assertFails(ISE, webSocket.sendText("", false));
- assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), true));
- assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), false));
- CompletableFuture<WebSocket> cfPing = webSocket.sendPing(ByteBuffer.allocate(125));
- assertHangs(cfPing);
- assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
- assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
- CompletableFuture<WebSocket> cfClose = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
- assertHangs(cfClose);
+ assertFails(ISE, webSocket.sendText("", true));
+ assertFails(ISE, webSocket.sendText("", false));
+ assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), true));
+ assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), false));
+ cfPing = webSocket.sendPing(ByteBuffer.allocate(125));
+ assertHangs(cfPing);
+ assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
+ assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
+ cfClose = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
+ assertHangs(cfClose);
+ return null;
+ }, () -> cfBinary.isDone() ? true : false);
webSocket.abort();
assertFails(IOE, cfBinary);
assertFails(IOE, cfPing);
--- a/test/jdk/java/net/httpclient/websocket/PendingBinaryPongClose.java Wed Apr 11 00:55:41 2018 +0100
+++ b/test/jdk/java/net/httpclient/websocket/PendingBinaryPongClose.java Wed Apr 11 14:21:11 2018 +0100
@@ -42,39 +42,45 @@
public class PendingBinaryPongClose extends PendingOperations {
+ CompletableFuture<WebSocket> cfBinary;
+ CompletableFuture<WebSocket> cfPong;
+ CompletableFuture<WebSocket> cfClose;
+
@Test(dataProvider = "booleans")
public void pendingBinaryPongClose(boolean last) throws Exception {
- server = Support.notReadingServer();
- server.open();
- webSocket = newHttpClient().newWebSocketBuilder()
- .buildAsync(server.getURI(), new WebSocket.Listener() { })
- .join();
- ByteBuffer data = ByteBuffer.allocate(65536);
- CompletableFuture<WebSocket> cfBinary;
- for (int i = 0; ; i++) { // fill up the send buffer
- long start = System.currentTimeMillis();
- System.out.printf("begin cycle #%s at %s%n", i, start);
- cfBinary = webSocket.sendBinary(data, last);
- try {
- cfBinary.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
- data.clear();
- } catch (TimeoutException e) {
- break;
- } finally {
- long stop = System.currentTimeMillis();
- System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ repeatable(() -> {
+ server = Support.notReadingServer();
+ server.open();
+ webSocket = newHttpClient().newWebSocketBuilder()
+ .buildAsync(server.getURI(), new WebSocket.Listener() { })
+ .join();
+ ByteBuffer data = ByteBuffer.allocate(65536);
+ for (int i = 0; ; i++) { // fill up the send buffer
+ long start = System.currentTimeMillis();
+ System.out.printf("begin cycle #%s at %s%n", i, start);
+ cfBinary = webSocket.sendBinary(data, last);
+ try {
+ cfBinary.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
+ data.clear();
+ } catch (TimeoutException e) {
+ break;
+ } finally {
+ long stop = System.currentTimeMillis();
+ System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ }
}
- }
- assertFails(ISE, webSocket.sendText("", true));
- assertFails(ISE, webSocket.sendText("", false));
- assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), true));
- assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), false));
- CompletableFuture<WebSocket> cfPong = webSocket.sendPong(ByteBuffer.allocate(125));
- assertHangs(cfPong);
- assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
- assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
- CompletableFuture<WebSocket> cfClose = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
- assertHangs(cfClose);
+ assertFails(ISE, webSocket.sendText("", true));
+ assertFails(ISE, webSocket.sendText("", false));
+ assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), true));
+ assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), false));
+ cfPong = webSocket.sendPong(ByteBuffer.allocate(125));
+ assertHangs(cfPong);
+ assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
+ assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
+ cfClose = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
+ assertHangs(cfClose);
+ return null;
+ }, () -> cfBinary.isDone() ? true : false);
webSocket.abort();
assertFails(IOE, cfBinary);
assertFails(IOE, cfPong);
--- a/test/jdk/java/net/httpclient/websocket/PendingOperations.java Wed Apr 11 00:55:41 2018 +0100
+++ b/test/jdk/java/net/httpclient/websocket/PendingOperations.java Wed Apr 11 14:21:11 2018 +0100
@@ -26,7 +26,12 @@
import java.io.IOException;
import java.net.http.WebSocket;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
+import java.util.function.BooleanSupplier;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
/* Common infrastructure for tests that check pending operations */
public class PendingOperations {
@@ -63,4 +68,33 @@
public Object[][] booleans() {
return new Object[][]{{Boolean.TRUE}, {Boolean.FALSE}};
}
+
+ static boolean isMacOS() {
+ return System.getProperty("os.name").contains("OS X");
+ }
+
+ private static final int ITERATIONS = 3;
+
+ static void repeatable(Callable<Void> callable,
+ BooleanSupplier repeatCondition)
+ throws Exception
+ {
+ int iterations = 0;
+ do {
+ iterations++;
+ System.out.println("--- iteration " + iterations + " ---");
+ try {
+ callable.call();
+ break;
+ } catch (AssertionError e) {
+ if (isMacOS() && repeatCondition.getAsBoolean()) {
+ // ## This is loathsome, but necessary because of observed
+ // ## automagic socket buffer resizing on recent macOS platforms
+ continue;
+ } else {
+ throw e;
+ }
+ }
+ } while (iterations <= ITERATIONS);
+ }
}
--- a/test/jdk/java/net/httpclient/websocket/PendingPingBinaryClose.java Wed Apr 11 00:55:41 2018 +0100
+++ b/test/jdk/java/net/httpclient/websocket/PendingPingBinaryClose.java Wed Apr 11 14:21:11 2018 +0100
@@ -44,37 +44,41 @@
public class PendingPingBinaryClose extends PendingOperations {
+ CompletableFuture<WebSocket> cfBinary;
+ CompletableFuture<WebSocket> cfPing;
+ CompletableFuture<WebSocket> cfClose;
+
@Test(dataProvider = "booleans")
public void pendingPingBinaryClose(boolean last) throws Exception {
- server = Support.notReadingServer();
- server.open();
- webSocket = newHttpClient().newWebSocketBuilder()
- .buildAsync(server.getURI(), new WebSocket.Listener() { })
- .join();
- ByteBuffer data = ByteBuffer.allocate(125);
- CompletableFuture<WebSocket> cfPing;
- for (int i = 0; ; i++) { // fill up the send buffer
- long start = System.currentTimeMillis();
- System.out.printf("begin cycle #%s at %s%n", i, start);
- cfPing = webSocket.sendPing(data);
- try {
- cfPing.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
- data.clear();
- } catch (TimeoutException e) {
- break;
- } finally {
- long stop = System.currentTimeMillis();
- System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ repeatable( () -> {
+ server = Support.notReadingServer();
+ server.open();
+ webSocket = newHttpClient().newWebSocketBuilder()
+ .buildAsync(server.getURI(), new WebSocket.Listener() { })
+ .join();
+ ByteBuffer data = ByteBuffer.allocate(125);
+ for (int i = 0; ; i++) { // fill up the send buffer
+ long start = System.currentTimeMillis();
+ System.out.printf("begin cycle #%s at %s%n", i, start);
+ cfPing = webSocket.sendPing(data);
+ try {
+ cfPing.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
+ data.clear();
+ } catch (TimeoutException e) {
+ break;
+ } finally {
+ long stop = System.currentTimeMillis();
+ System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ }
}
- }
- assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
- assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
- CompletableFuture<WebSocket> cfBinary
- = webSocket.sendBinary(ByteBuffer.allocate(4), last);
- assertHangs(cfBinary);
- CompletableFuture<WebSocket> cfClose
- = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
- assertHangs(cfClose);
+ assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
+ assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
+ cfBinary = webSocket.sendBinary(ByteBuffer.allocate(4), last);
+ assertHangs(cfBinary);
+ cfClose = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
+ assertHangs(cfClose);
+ return null;
+ }, () -> cfPing.isDone() ? true : false);
webSocket.abort();
assertFails(IOE, cfPing);
assertFails(IOE, cfBinary);
--- a/test/jdk/java/net/httpclient/websocket/PendingPingTextClose.java Wed Apr 11 00:55:41 2018 +0100
+++ b/test/jdk/java/net/httpclient/websocket/PendingPingTextClose.java Wed Apr 11 14:21:11 2018 +0100
@@ -44,36 +44,41 @@
public class PendingPingTextClose extends PendingOperations {
+ CompletableFuture<WebSocket> cfText;
+ CompletableFuture<WebSocket> cfPing;
+ CompletableFuture<WebSocket> cfClose;
+
@Test(dataProvider = "booleans")
public void pendingPingTextClose(boolean last) throws Exception {
- server = Support.notReadingServer();
- server.open();
- webSocket = newHttpClient().newWebSocketBuilder()
- .buildAsync(server.getURI(), new WebSocket.Listener() { })
- .join();
- ByteBuffer data = ByteBuffer.allocate(125);
- CompletableFuture<WebSocket> cfPing;
- for (int i = 0; ; i++) { // fill up the send buffer
- long start = System.currentTimeMillis();
- System.out.printf("begin cycle #%s at %s%n", i, start);
- cfPing = webSocket.sendPing(data);
- try {
- cfPing.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
- data.clear();
- } catch (TimeoutException e) {
- break;
- } finally {
- long stop = System.currentTimeMillis();
- System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ repeatable( () -> {
+ server = Support.notReadingServer();
+ server.open();
+ webSocket = newHttpClient().newWebSocketBuilder()
+ .buildAsync(server.getURI(), new WebSocket.Listener() { })
+ .join();
+ ByteBuffer data = ByteBuffer.allocate(125);
+ for (int i = 0; ; i++) { // fill up the send buffer
+ long start = System.currentTimeMillis();
+ System.out.printf("begin cycle #%s at %s%n", i, start);
+ cfPing = webSocket.sendPing(data);
+ try {
+ cfPing.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
+ data.clear();
+ } catch (TimeoutException e) {
+ break;
+ } finally {
+ long stop = System.currentTimeMillis();
+ System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ }
}
- }
- assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
- assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
- CompletableFuture<WebSocket> cfText = webSocket.sendText("hello", last);
- assertHangs(cfText);
- CompletableFuture<WebSocket> cfClose
- = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
- assertHangs(cfClose);
+ assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
+ assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
+ cfText = webSocket.sendText("hello", last);
+ assertHangs(cfText);
+ cfClose = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
+ assertHangs(cfClose);
+ return null;
+ }, () -> cfPing.isDone() ? true : false);
webSocket.abort();
assertFails(IOE, cfPing);
assertFails(IOE, cfText);
--- a/test/jdk/java/net/httpclient/websocket/PendingPongBinaryClose.java Wed Apr 11 00:55:41 2018 +0100
+++ b/test/jdk/java/net/httpclient/websocket/PendingPongBinaryClose.java Wed Apr 11 14:21:11 2018 +0100
@@ -44,38 +44,41 @@
public class PendingPongBinaryClose extends PendingOperations {
+ CompletableFuture<WebSocket> cfBinary;
+ CompletableFuture<WebSocket> cfPong;
+ CompletableFuture<WebSocket> cfClose;
+
@Test(dataProvider = "booleans")
public void pendingPongBinaryClose(boolean last) throws Exception {
- server = Support.notReadingServer();
- server.open();
- webSocket = newHttpClient().newWebSocketBuilder()
- .buildAsync(server.getURI(), new WebSocket.Listener() { })
- .join();
-
- ByteBuffer data = ByteBuffer.allocate(125);
- CompletableFuture<WebSocket> cfPong;
- for (int i = 0; ; i++) { // fill up the send buffer
- long start = System.currentTimeMillis();
- System.out.printf("begin cycle #%s at %s%n", i, start);
- cfPong = webSocket.sendPong(data);
- try {
- cfPong.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
- data.clear();
- } catch (TimeoutException e) {
- break;
- } finally {
- long stop = System.currentTimeMillis();
- System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ repeatable( () -> {
+ server = Support.notReadingServer();
+ server.open();
+ webSocket = newHttpClient().newWebSocketBuilder()
+ .buildAsync(server.getURI(), new WebSocket.Listener() { })
+ .join();
+ ByteBuffer data = ByteBuffer.allocate(125);
+ for (int i = 0; ; i++) { // fill up the send buffer
+ long start = System.currentTimeMillis();
+ System.out.printf("begin cycle #%s at %s%n", i, start);
+ cfPong = webSocket.sendPong(data);
+ try {
+ cfPong.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
+ data.clear();
+ } catch (TimeoutException e) {
+ break;
+ } finally {
+ long stop = System.currentTimeMillis();
+ System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ }
}
- }
- assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
- assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
- CompletableFuture<WebSocket> cfBinary
- = webSocket.sendBinary(ByteBuffer.allocate(4), last);
- assertHangs(cfBinary);
- CompletableFuture<WebSocket> cfClose
- = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
- assertHangs(cfClose);
+ assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
+ assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
+ cfBinary = webSocket.sendBinary(ByteBuffer.allocate(4), last);
+ assertHangs(cfBinary);
+ cfClose = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
+ assertHangs(cfClose);
+ return null;
+ }, () -> cfPong.isDone() ? true : false);
webSocket.abort();
assertFails(IOE, cfPong);
assertFails(IOE, cfBinary);
--- a/test/jdk/java/net/httpclient/websocket/PendingPongTextClose.java Wed Apr 11 00:55:41 2018 +0100
+++ b/test/jdk/java/net/httpclient/websocket/PendingPongTextClose.java Wed Apr 11 14:21:11 2018 +0100
@@ -44,36 +44,41 @@
public class PendingPongTextClose extends PendingOperations {
+ CompletableFuture<WebSocket> cfText;
+ CompletableFuture<WebSocket> cfPong;
+ CompletableFuture<WebSocket> cfClose;
+
@Test(dataProvider = "booleans")
public void pendingPongTextClose(boolean last) throws Exception {
- server = Support.notReadingServer();
- server.open();
- webSocket = newHttpClient().newWebSocketBuilder()
- .buildAsync(server.getURI(), new WebSocket.Listener() { })
- .join();
- ByteBuffer data = ByteBuffer.allocate(125);
- CompletableFuture<WebSocket> cfPong;
- for (int i = 0; ; i++) { // fill up the send buffer
- long start = System.currentTimeMillis();
- System.out.printf("begin cycle #%s at %s%n", i, start);
- cfPong = webSocket.sendPong(data);
- try {
- cfPong.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
- data.clear();
- } catch (TimeoutException e) {
- break;
- } finally {
- long stop = System.currentTimeMillis();
- System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ repeatable( () -> {
+ server = Support.notReadingServer();
+ server.open();
+ webSocket = newHttpClient().newWebSocketBuilder()
+ .buildAsync(server.getURI(), new WebSocket.Listener() { })
+ .join();
+ ByteBuffer data = ByteBuffer.allocate(125);
+ for (int i = 0; ; i++) { // fill up the send buffer
+ long start = System.currentTimeMillis();
+ System.out.printf("begin cycle #%s at %s%n", i, start);
+ cfPong = webSocket.sendPong(data);
+ try {
+ cfPong.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
+ data.clear();
+ } catch (TimeoutException e) {
+ break;
+ } finally {
+ long stop = System.currentTimeMillis();
+ System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ }
}
- }
- assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
- assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
- CompletableFuture<WebSocket> cfText = webSocket.sendText("hello", last);
- assertHangs(cfText);
- CompletableFuture<WebSocket> cfClose
- = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
- assertHangs(cfClose);
+ assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
+ assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
+ cfText = webSocket.sendText("hello", last);
+ assertHangs(cfText);
+ cfClose = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
+ assertHangs(cfClose);
+ return null;
+ }, () -> cfPong.isDone() ? true : false);
webSocket.abort();
assertFails(IOE, cfPong);
assertFails(IOE, cfText);
--- a/test/jdk/java/net/httpclient/websocket/PendingTextPingClose.java Wed Apr 11 00:55:41 2018 +0100
+++ b/test/jdk/java/net/httpclient/websocket/PendingTextPingClose.java Wed Apr 11 14:21:11 2018 +0100
@@ -43,39 +43,45 @@
public class PendingTextPingClose extends PendingOperations {
+ CompletableFuture<WebSocket> cfText;
+ CompletableFuture<WebSocket> cfPing;
+ CompletableFuture<WebSocket> cfClose;
+
@Test(dataProvider = "booleans")
public void pendingTextPingClose(boolean last) throws Exception {
- server = Support.notReadingServer();
- server.open();
- webSocket = newHttpClient().newWebSocketBuilder()
- .buildAsync(server.getURI(), new WebSocket.Listener() { })
- .join();
- CharBuffer data = CharBuffer.allocate(65536);
- CompletableFuture<WebSocket> cfText;
- for (int i = 0; ; i++) { // fill up the send buffer
- long start = System.currentTimeMillis();
- System.out.printf("begin cycle #%s at %s%n", i, start);
- cfText = webSocket.sendText(data, last);
- try {
- cfText.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
- data.clear();
- } catch (TimeoutException e) {
- break;
- } finally {
- long stop = System.currentTimeMillis();
- System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ repeatable(() -> {
+ server = Support.notReadingServer();
+ server.open();
+ webSocket = newHttpClient().newWebSocketBuilder()
+ .buildAsync(server.getURI(), new WebSocket.Listener() { })
+ .join();
+ CharBuffer data = CharBuffer.allocate(65536);
+ for (int i = 0; ; i++) { // fill up the send buffer
+ long start = System.currentTimeMillis();
+ System.out.printf("begin cycle #%s at %s%n", i, start);
+ cfText = webSocket.sendText(data, last);
+ try {
+ cfText.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
+ data.clear();
+ } catch (TimeoutException e) {
+ break;
+ } finally {
+ long stop = System.currentTimeMillis();
+ System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ }
}
- }
- assertFails(ISE, webSocket.sendText("", true));
- assertFails(ISE, webSocket.sendText("", false));
- assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), true));
- assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), false));
- CompletableFuture<WebSocket> cfPing = webSocket.sendPing(ByteBuffer.allocate(125));
- assertHangs(cfPing);
- assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
- assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
- CompletableFuture<WebSocket> cfClose = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
- assertHangs(cfClose);
+ assertFails(ISE, webSocket.sendText("", true));
+ assertFails(ISE, webSocket.sendText("", false));
+ assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), true));
+ assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), false));
+ cfPing = webSocket.sendPing(ByteBuffer.allocate(125));
+ assertHangs(cfPing);
+ assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
+ assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
+ cfClose = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
+ assertHangs(cfClose);
+ return null;
+ }, () -> cfText.isDone() ? true : false);
webSocket.abort();
assertFails(IOE, cfText);
assertFails(IOE, cfPing);
--- a/test/jdk/java/net/httpclient/websocket/PendingTextPongClose.java Wed Apr 11 00:55:41 2018 +0100
+++ b/test/jdk/java/net/httpclient/websocket/PendingTextPongClose.java Wed Apr 11 14:21:11 2018 +0100
@@ -43,39 +43,45 @@
public class PendingTextPongClose extends PendingOperations {
+ CompletableFuture<WebSocket> cfText;
+ CompletableFuture<WebSocket> cfPong;
+ CompletableFuture<WebSocket> cfClose;
+
@Test(dataProvider = "booleans")
public void pendingTextPongClose(boolean last) throws Exception {
- server = Support.notReadingServer();
- server.open();
- webSocket = newHttpClient().newWebSocketBuilder()
- .buildAsync(server.getURI(), new WebSocket.Listener() { })
- .join();
- CharBuffer data = CharBuffer.allocate(65536);
- CompletableFuture<WebSocket> cfText;
- for (int i = 0; ; i++) { // fill up the send buffer
- long start = System.currentTimeMillis();
- System.out.printf("begin cycle #%s at %s%n", i, start);
- cfText = webSocket.sendText(data, last);
- try {
- cfText.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
- data.clear();
- } catch (TimeoutException e) {
- break;
- } finally {
- long stop = System.currentTimeMillis();
- System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ repeatable(() -> {
+ server = Support.notReadingServer();
+ server.open();
+ webSocket = newHttpClient().newWebSocketBuilder()
+ .buildAsync(server.getURI(), new WebSocket.Listener() { })
+ .join();
+ CharBuffer data = CharBuffer.allocate(65536);
+ for (int i = 0; ; i++) { // fill up the send buffer
+ long start = System.currentTimeMillis();
+ System.out.printf("begin cycle #%s at %s%n", i, start);
+ cfText = webSocket.sendText(data, last);
+ try {
+ cfText.get(MAX_WAIT_SEC, TimeUnit.SECONDS);
+ data.clear();
+ } catch (TimeoutException e) {
+ break;
+ } finally {
+ long stop = System.currentTimeMillis();
+ System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start);
+ }
}
- }
- assertFails(ISE, webSocket.sendText("", true));
- assertFails(ISE, webSocket.sendText("", false));
- assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), true));
- assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), false));
- CompletableFuture<WebSocket> cfPong = webSocket.sendPong(ByteBuffer.allocate(125));
- assertHangs(cfPong);
- assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
- assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
- CompletableFuture<WebSocket> cfClose = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
- assertHangs(cfClose);
+ assertFails(ISE, webSocket.sendText("", true));
+ assertFails(ISE, webSocket.sendText("", false));
+ assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), true));
+ assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), false));
+ cfPong = webSocket.sendPong(ByteBuffer.allocate(125));
+ assertHangs(cfPong);
+ assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125)));
+ assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125)));
+ cfClose = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok");
+ assertHangs(cfClose);
+ return null;
+ }, () -> cfText.isDone() ? true : false);
webSocket.abort();
assertFails(IOE, cfText);
assertFails(IOE, cfPong);