author | chegar |
Mon, 20 Nov 2017 18:36:57 +0000 | |
branch | http-client-branch |
changeset 55841 | 5f0b66e83dfa |
parent 55828 | ac0c821cc75c |
child 55846 | 2a7e2724a422 |
permissions | -rw-r--r-- |
55763 | 1 |
/* |
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
import java.nio.ByteBuffer; |
|
25 |
import java.util.List; |
|
26 |
import java.util.Random; |
|
27 |
import java.util.concurrent.CompletableFuture; |
|
28 |
import java.util.concurrent.CompletionStage; |
|
29 |
import java.util.concurrent.Executor; |
|
30 |
import java.util.concurrent.ExecutorService; |
|
31 |
import java.util.concurrent.Executors; |
|
32 |
import java.util.concurrent.Flow; |
|
33 |
import java.util.concurrent.Flow.Subscription; |
|
34 |
import java.util.concurrent.SubmissionPublisher; |
|
35 |
import jdk.incubator.http.HttpResponse.BodyHandler; |
|
36 |
import jdk.incubator.http.HttpResponse.BodySubscriber; |
|
37 |
import jdk.test.lib.RandomFactory; |
|
38 |
import org.testng.annotations.DataProvider; |
|
39 |
import org.testng.annotations.Test; |
|
40 |
import static java.lang.Long.MAX_VALUE; |
|
41 |
import static java.lang.System.out; |
|
42 |
import static java.util.concurrent.CompletableFuture.delayedExecutor; |
|
43 |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
|
44 |
import static org.testng.Assert.*; |
|
45 |
||
46 |
/* |
|
47 |
* @test |
|
48 |
* @bug 8184285 |
|
49 |
* @summary Direct test for HttpResponse.BodySubscriber.buffering() API |
|
50 |
* @key randomness |
|
51 |
* @library /test/lib |
|
52 |
* @build jdk.test.lib.RandomFactory |
|
53 |
* @run testng/othervm -Djdk.internal.httpclient.debug=true BufferingSubscriberTest |
|
54 |
*/ |
|
55 |
||
56 |
public class BufferingSubscriberTest { |
|
57 |
||
58 |
static final Random random = RandomFactory.getRandom(); |
|
55828
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
59 |
static final long start = System.nanoTime(); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
60 |
static final String START = "start"; |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
61 |
static final String END = "end "; |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
62 |
static long elapsed() { return (System.nanoTime() - start)/1000_000;} |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
63 |
static void printStamp(String what, String fmt, Object... args) { |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
64 |
long elapsed = elapsed(); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
65 |
long sec = elapsed/1000; |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
66 |
long ms = elapsed % 1000; |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
67 |
String time = sec > 0 ? sec + "sec " : ""; |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
68 |
time = time + ms + "ms"; |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
69 |
out.println(what + "\t ["+time+"]\t "+ String.format(fmt,args)); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
70 |
} |
55763 | 71 |
@DataProvider(name = "negatives") |
72 |
public Object[][] negatives() { |
|
73 |
return new Object[][] { { 0 }, { -1 }, { -1000 } }; |
|
74 |
} |
|
75 |
||
76 |
@Test(dataProvider = "negatives", expectedExceptions = IllegalArgumentException.class) |
|
77 |
public void subscriberThrowsIAE(int bufferSize) { |
|
55828
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
78 |
printStamp(START, "subscriberThrowsIAE(%d)", bufferSize); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
79 |
try { |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
80 |
BodySubscriber<?> bp = BodySubscriber.asByteArray(); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
81 |
BodySubscriber.buffering(bp, bufferSize); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
82 |
} finally { |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
83 |
printStamp(END, "subscriberThrowsIAE(%d)", bufferSize); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
84 |
} |
55763 | 85 |
} |
86 |
||
87 |
@Test(dataProvider = "negatives", expectedExceptions = IllegalArgumentException.class) |
|
88 |
public void handlerThrowsIAE(int bufferSize) { |
|
55828
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
89 |
printStamp(START, "handlerThrowsIAE(%d)", bufferSize); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
90 |
try { |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
91 |
BodyHandler<?> bp = BodyHandler.asByteArray(); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
92 |
BodyHandler.buffering(bp, bufferSize); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
93 |
} finally { |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
94 |
printStamp(END, "handlerThrowsIAE(%d)", bufferSize); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
95 |
} |
55763 | 96 |
} |
97 |
||
98 |
// --- |
|
99 |
||
100 |
@DataProvider(name = "config") |
|
101 |
public Object[][] config() { |
|
102 |
return new Object[][] { |
|
103 |
// iterations delayMillis numBuffers bufferSize maxBufferSize minBufferSize |
|
104 |
{ 1, 0, 1, 1, 2, 1 }, |
|
105 |
{ 1, 0, 1, 10, 1000, 1 }, |
|
106 |
{ 1, 10, 1, 10, 1000, 1 }, |
|
55841
5f0b66e83dfa
http-client-branch: remove some degenerate test cases from BufferingSubscriberTest
chegar
parents:
55828
diff
changeset
|
107 |
{ 1, 0, 1, 1000, 1000, 10 }, |
5f0b66e83dfa
http-client-branch: remove some degenerate test cases from BufferingSubscriberTest
chegar
parents:
55828
diff
changeset
|
108 |
{ 1, 0, 10, 1000, 1000, 50 }, |
55763 | 109 |
{ 1, 0, 1000, 10 , 1000, 50 }, |
55841
5f0b66e83dfa
http-client-branch: remove some degenerate test cases from BufferingSubscriberTest
chegar
parents:
55828
diff
changeset
|
110 |
{ 1, 100, 1, 1000 * 4, 1000, 50 }, |
55763 | 111 |
{ 100, 0, 1000, 1, 2, 1 }, |
55841
5f0b66e83dfa
http-client-branch: remove some degenerate test cases from BufferingSubscriberTest
chegar
parents:
55828
diff
changeset
|
112 |
{ 3, 0, 4, 5006, 1000, 50 }, |
55763 | 113 |
{ 20, 0, 100, 4888, 1000, 100 }, |
114 |
{ 16, 10, 1000, 50 , 1000, 100 }, |
|
115 |
}; |
|
116 |
} |
|
117 |
||
118 |
@Test(dataProvider = "config") |
|
119 |
public void test(int iterations, |
|
120 |
int delayMillis, |
|
121 |
int numBuffers, |
|
122 |
int bufferSize, |
|
123 |
int maxBufferSize, |
|
124 |
int minbufferSize) { |
|
125 |
for (long perRequestAmount : new long[] { 1L, MAX_VALUE }) |
|
126 |
test(iterations, |
|
127 |
delayMillis, |
|
128 |
numBuffers, |
|
129 |
bufferSize, |
|
130 |
maxBufferSize, |
|
131 |
minbufferSize, |
|
132 |
perRequestAmount); |
|
133 |
} |
|
134 |
||
135 |
public void test(int iterations, |
|
136 |
int delayMillis, |
|
137 |
int numBuffers, |
|
138 |
int bufferSize, |
|
139 |
int maxBufferSize, |
|
140 |
int minBufferSize, |
|
141 |
long requestAmount) { |
|
142 |
ExecutorService executor = Executors.newFixedThreadPool(1); |
|
143 |
try { |
|
144 |
out.printf("Iterations %d\n", iterations); |
|
145 |
for (int i=0; i<iterations; i++ ) { |
|
55828
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
146 |
printStamp(START, "Iteration %d", i); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
147 |
try { |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
148 |
SubmissionPublisher<List<ByteBuffer>> publisher = |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
149 |
new SubmissionPublisher<>(executor, 1); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
150 |
CompletableFuture<?> cf = sink(publisher, |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
151 |
delayMillis, |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
152 |
numBuffers * bufferSize, |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
153 |
requestAmount, |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
154 |
maxBufferSize, |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
155 |
minBufferSize); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
156 |
source(publisher, numBuffers, bufferSize); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
157 |
publisher.close(); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
158 |
cf.join(); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
159 |
} finally { |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
160 |
printStamp(END, "Iteration %d\n", i); |
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
161 |
} |
55763 | 162 |
} |
163 |
out.println("OK"); |
|
164 |
} finally { |
|
165 |
executor.shutdown(); |
|
166 |
} |
|
167 |
} |
|
168 |
||
169 |
static int accumulatedDataSize(List<ByteBuffer> bufs) { |
|
170 |
return bufs.stream().mapToInt(ByteBuffer::remaining).sum(); |
|
171 |
} |
|
172 |
||
173 |
/** Returns a new BB with its contents set to monotonically increasing |
|
174 |
* values, staring at the given start index and wrapping every 100. */ |
|
175 |
static ByteBuffer allocateBuffer(int size, int startIdx) { |
|
176 |
ByteBuffer b = ByteBuffer.allocate(size); |
|
177 |
for (int i=0; i<size; i++) |
|
178 |
b.put((byte)((startIdx + i) % 100)); |
|
179 |
b.position(0); |
|
180 |
return b; |
|
181 |
} |
|
182 |
||
183 |
static class TestSubscriber implements BodySubscriber<Integer> { |
|
184 |
final int delayMillis; |
|
185 |
final int bufferSize; |
|
186 |
final int expectedTotalSize; |
|
187 |
final long requestAmount; |
|
188 |
final CompletableFuture<Integer> completion; |
|
189 |
final Executor delayedExecutor; |
|
190 |
volatile Flow.Subscription subscription; |
|
191 |
||
192 |
TestSubscriber(int bufferSize, |
|
193 |
int delayMillis, |
|
194 |
int expectedTotalSize, |
|
195 |
long requestAmount) { |
|
196 |
this.bufferSize = bufferSize; |
|
197 |
this.completion = new CompletableFuture<>(); |
|
198 |
this.delayMillis = delayMillis; |
|
199 |
this.delayedExecutor = delayedExecutor(delayMillis, MILLISECONDS); |
|
200 |
this.expectedTotalSize = expectedTotalSize; |
|
201 |
this.requestAmount = requestAmount; |
|
202 |
} |
|
203 |
||
204 |
/** |
|
205 |
* Example of a factory method which would decorate a buffering |
|
206 |
* subscriber to create a new subscriber dependent on buffering capability. |
|
207 |
* |
|
208 |
* The integer type parameter simulates the body just by counting the |
|
209 |
* number of bytes in the body. |
|
210 |
*/ |
|
211 |
static BodySubscriber<Integer> createSubscriber(int bufferSize, |
|
212 |
int delay, |
|
213 |
int expectedTotalSize, |
|
214 |
long requestAmount) { |
|
215 |
TestSubscriber s = new TestSubscriber(bufferSize, |
|
216 |
delay, |
|
217 |
expectedTotalSize, |
|
218 |
requestAmount); |
|
219 |
return BodySubscriber.buffering(s, bufferSize); |
|
220 |
} |
|
221 |
||
222 |
private void requestMore() { subscription.request(requestAmount); } |
|
223 |
||
224 |
@Override |
|
225 |
public void onSubscribe(Subscription subscription) { |
|
226 |
assertNull(this.subscription); |
|
227 |
this.subscription = subscription; |
|
228 |
if (delayMillis > 0) |
|
229 |
delayedExecutor.execute(this::requestMore); |
|
230 |
else |
|
231 |
requestMore(); |
|
232 |
} |
|
233 |
||
234 |
volatile int wrongSizes; |
|
235 |
volatile int totalBytesReceived; |
|
236 |
volatile int onNextInvocations; |
|
237 |
volatile int lastSeenSize = -1; |
|
238 |
volatile boolean noMoreOnNext; // false |
|
239 |
volatile int index; // 0 |
|
240 |
||
241 |
@Override |
|
242 |
public void onNext(List<ByteBuffer> items) { |
|
243 |
long sz = accumulatedDataSize(items); |
|
244 |
onNextInvocations++; |
|
245 |
assertNotEquals(sz, 0L, "Unexpected empty buffers"); |
|
246 |
items.stream().forEach(b -> assertEquals(b.position(), 0)); |
|
247 |
assertFalse(noMoreOnNext); |
|
248 |
||
249 |
if (sz != bufferSize) { |
|
250 |
String msg = sz + ", should be less than bufferSize, " + bufferSize; |
|
251 |
assertTrue(sz < bufferSize, msg); |
|
252 |
assertTrue(lastSeenSize == -1 || lastSeenSize == bufferSize); |
|
253 |
noMoreOnNext = true; |
|
254 |
wrongSizes++; |
|
255 |
} else { |
|
256 |
assertEquals(sz, bufferSize, "Expected to receive exactly bufferSize"); |
|
257 |
} |
|
258 |
||
259 |
// Ensure expected contents |
|
260 |
for (ByteBuffer b : items) { |
|
261 |
while (b.hasRemaining()) { |
|
262 |
assertEquals(b.get(), (byte) (index % 100)); |
|
263 |
index++; |
|
264 |
} |
|
265 |
} |
|
266 |
||
267 |
totalBytesReceived += sz; |
|
268 |
assertEquals(totalBytesReceived, index ); |
|
269 |
if (delayMillis > 0) |
|
270 |
delayedExecutor.execute(this::requestMore); |
|
271 |
else |
|
272 |
requestMore(); |
|
273 |
} |
|
274 |
||
275 |
@Override |
|
276 |
public void onError(Throwable throwable) { |
|
277 |
completion.completeExceptionally(throwable); |
|
278 |
} |
|
279 |
||
280 |
@Override |
|
281 |
public void onComplete() { |
|
282 |
if (wrongSizes > 1) { // allow just the final item to be smaller |
|
283 |
String msg = "Wrong sizes. Expected no more than 1. [" + this + "]"; |
|
284 |
completion.completeExceptionally(new Throwable(msg)); |
|
285 |
} |
|
286 |
if (totalBytesReceived != expectedTotalSize) { |
|
287 |
String msg = "Wrong number of bytes. [" + this + "]"; |
|
288 |
completion.completeExceptionally(new Throwable(msg)); |
|
289 |
} else { |
|
290 |
completion.complete(totalBytesReceived); |
|
291 |
} |
|
292 |
} |
|
293 |
||
294 |
@Override |
|
295 |
public CompletionStage<Integer> getBody() { return completion; } |
|
296 |
||
297 |
@Override |
|
298 |
public String toString() { |
|
299 |
StringBuilder sb = new StringBuilder(); |
|
300 |
sb.append(super.toString()); |
|
301 |
sb.append(", bufferSize=").append(bufferSize); |
|
302 |
sb.append(", onNextInvocations=").append(onNextInvocations); |
|
303 |
sb.append(", totalBytesReceived=").append(totalBytesReceived); |
|
304 |
sb.append(", expectedTotalSize=").append(expectedTotalSize); |
|
305 |
sb.append(", requestAmount=").append(requestAmount); |
|
306 |
sb.append(", lastSeenSize=").append(lastSeenSize); |
|
307 |
sb.append(", wrongSizes=").append(wrongSizes); |
|
308 |
sb.append(", index=").append(index); |
|
309 |
return sb.toString(); |
|
310 |
} |
|
311 |
} |
|
312 |
||
313 |
/** |
|
314 |
* Publishes data, through the given publisher, using the main thread. |
|
315 |
* |
|
316 |
* Note: The executor supplied when creating the SubmissionPublisher provides |
|
317 |
* the threads for executing the Subscribers. |
|
318 |
* |
|
319 |
* @param publisher the publisher |
|
320 |
* @param numBuffers the number of buffers to send ( before splitting in two ) |
|
321 |
* @param bufferSize the total size of the data to send ( before splitting in two ) |
|
322 |
*/ |
|
323 |
static void source(SubmissionPublisher<List<ByteBuffer>> publisher, |
|
324 |
int numBuffers, |
|
325 |
int bufferSize) { |
|
55828
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
326 |
printStamp("source","Publishing %d buffers of size %d each", numBuffers, bufferSize); |
55763 | 327 |
int index = 0; |
328 |
for (int i=0; i<numBuffers; i++) { |
|
329 |
int chunkSize = random.nextInt(bufferSize); |
|
330 |
ByteBuffer buf1 = allocateBuffer(chunkSize, index); |
|
331 |
index += chunkSize; |
|
332 |
ByteBuffer buf2 = allocateBuffer(bufferSize - chunkSize, index); |
|
333 |
index += bufferSize - chunkSize; |
|
334 |
publisher.submit(List.of(buf1, buf2)); |
|
335 |
} |
|
55828
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
336 |
printStamp("source", "complete"); |
55763 | 337 |
} |
338 |
||
339 |
/** |
|
340 |
* Creates and subscribes Subscribers that receive data from the given |
|
341 |
* publisher. |
|
342 |
* |
|
343 |
* @param publisher the publisher |
|
344 |
* @param delayMillis time, in milliseconds, to delay the Subscription |
|
345 |
* requesting more bytes ( for simulating slow consumption ) |
|
346 |
* @param expectedTotalSize the total number of bytes expected to be received |
|
347 |
* by the subscribers |
|
348 |
* @return a CompletableFuture which completes when the subscription is complete |
|
349 |
*/ |
|
350 |
static CompletableFuture<?> sink(SubmissionPublisher<List<ByteBuffer>> publisher, |
|
351 |
int delayMillis, |
|
352 |
int expectedTotalSize, |
|
353 |
long requestAmount, |
|
354 |
int maxBufferSize, |
|
355 |
int minBufferSize) { |
|
356 |
int bufferSize = random.nextInt(maxBufferSize - minBufferSize) + minBufferSize; |
|
357 |
BodySubscriber<Integer> sub = TestSubscriber.createSubscriber(bufferSize, |
|
358 |
delayMillis, |
|
359 |
expectedTotalSize, |
|
360 |
requestAmount); |
|
361 |
publisher.subscribe(sub); |
|
55828
ac0c821cc75c
http-client-branch: adding time information to BufferingSubscriberTest.java
dfuchs
parents:
55763
diff
changeset
|
362 |
printStamp("sink","Subscriber reads data with buffer size: %d", bufferSize); |
55763 | 363 |
out.printf("Subscription delay is %d msec\n", delayMillis); |
364 |
out.printf("Request amount is %d items\n", requestAmount); |
|
365 |
return sub.getBody().toCompletableFuture(); |
|
366 |
} |
|
367 |
||
368 |
// --- |
|
369 |
||
370 |
// TODO: Add a test for cancel |
|
371 |
||
372 |
// --- |
|
373 |
||
374 |
/* Main entry point for standalone testing of the main functional test. */ |
|
375 |
public static void main(String... args) { |
|
376 |
BufferingSubscriberTest t = new BufferingSubscriberTest(); |
|
377 |
for (Object[] objs : t.config()) |
|
378 |
t.test((int)objs[0], (int)objs[1], (int)objs[2], (int)objs[3], (int)objs[4], (int)objs[5]); |
|
379 |
} |
|
380 |
} |