--- 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);