test/jdk/java/net/httpclient/websocket/MockListener.java
branchhttp-client-branch
changeset 56688 0b633bdb7010
parent 56451 9585061fdb04
child 56795 03ece2518428
--- a/test/jdk/java/net/httpclient/websocket/MockListener.java	Wed Jun 06 15:01:02 2018 +0100
+++ b/test/jdk/java/net/httpclient/websocket/MockListener.java	Thu Jun 07 10:45:30 2018 +0100
@@ -39,11 +39,15 @@
     private final Predicate<? super Invocation> collectUntil;
 
     public MockListener() {
-        this(i -> i instanceof OnClose || i instanceof OnError);
+        this(1, MockListener::closeOrError);
+    }
+
+    public MockListener(long bufferSize) {
+        this(bufferSize, MockListener::closeOrError);
     }
 
     public MockListener(Predicate<? super Invocation> collectUntil) {
-        this(2, collectUntil);
+        this(1, collectUntil);
     }
 
     /*
@@ -59,6 +63,10 @@
         this.collectUntil = collectUntil;
     }
 
+    private static boolean closeOrError(Invocation i) {
+        return i instanceof OnClose || i instanceof OnError;
+    }
+
     @Override
     public void onOpen(WebSocket webSocket) {
         System.out.printf("onOpen(%s)%n", webSocket);
@@ -73,7 +81,9 @@
     }
 
     protected void onOpen0(WebSocket webSocket) {
-        replenish(webSocket);
+        count = bufferSize - bufferSize / 2;
+        System.out.printf("request(%d)%n", bufferSize);
+        webSocket.request(bufferSize);
     }
 
     @Override
@@ -209,8 +219,9 @@
     protected void replenish(WebSocket webSocket) {
         if (--count <= 0) {
             count = bufferSize - bufferSize / 2;
+            webSocket.request(count);
+            System.out.printf("request(%d)%n", count);
         }
-        webSocket.request(count);
     }
 
     public abstract static class Invocation {