@@ -20,6 +20,7 @@ public class TestEnvironment {
20
20
public static final int TEST_BUFFER_SIZE = 16 ;
21
21
22
22
private final long defaultTimeoutMillis ;
23
+ private final boolean printlnDebug ;
23
24
24
25
private CopyOnWriteArrayList <Throwable > asyncErrors = new CopyOnWriteArrayList <Throwable >();
25
26
@@ -30,11 +31,27 @@ public class TestEnvironment {
30
31
* run the tests.
31
32
*
32
33
* @param defaultTimeoutMillis default timeout to be used in all expect* methods
34
+ * @param printlnDebug if true, signals such as OnNext / Request / OnComplete etc will be printed to standard output,
35
+ * often helpful to pinpoint simple race conditions etc.
33
36
*/
34
- public TestEnvironment (long defaultTimeoutMillis ) {
37
+ public TestEnvironment (long defaultTimeoutMillis , boolean printlnDebug ) {
35
38
this .defaultTimeoutMillis = defaultTimeoutMillis ;
39
+ this .printlnDebug = printlnDebug ;
36
40
}
37
41
42
+ /**
43
+ * Tests must specify the timeout for expected outcome of asynchronous
44
+ * interactions. Longer timeout does not invalidate the correctness of
45
+ * the implementation, but can in some cases result in longer time to
46
+ * run the tests.
47
+ *
48
+ * @param defaultTimeoutMillis default timeout to be used in all expect* methods
49
+ */
50
+ public TestEnvironment (long defaultTimeoutMillis ) {
51
+ this (defaultTimeoutMillis , false );
52
+ }
53
+
54
+
38
55
// keeping method around
39
56
public long defaultTimeoutMillis () {
40
57
return defaultTimeoutMillis ;
@@ -231,9 +248,7 @@ public T nextElement(String errorMsg) throws InterruptedException {
231
248
}
232
249
233
250
public T nextElement (long timeoutMillis , String errorMsg ) throws InterruptedException {
234
- T got = received .next (timeoutMillis , errorMsg );
235
- System .out .println ("got = " + got );
236
- return got ;
251
+ return received .next (timeoutMillis , errorMsg );
237
252
}
238
253
239
254
public Optional <T > nextElementOrEndOfStream () throws InterruptedException {
@@ -337,7 +352,7 @@ public ManualSubscriberWithSubscriptionSupport(TestEnvironment env) {
337
352
338
353
@ Override
339
354
public void onNext (T element ) {
340
- System . out . println ("onNext(" + element + ")" );
355
+ debug ("onNext(" + element + ")" );
341
356
if (subscription .isCompleted ()) {
342
357
super .onNext (element );
343
358
} else {
@@ -347,7 +362,7 @@ public void onNext(T element) {
347
362
348
363
@ Override
349
364
public void onComplete () {
350
- System . out . println ("onComplete" );
365
+ debug ("onComplete" );
351
366
if (subscription .isCompleted ()) {
352
367
super .onComplete ();
353
368
} else {
@@ -357,7 +372,7 @@ public void onComplete() {
357
372
358
373
@ Override
359
374
public void onSubscribe (Subscription s ) {
360
- System . out . println ("onSubscribe(" + s + ")" );
375
+ debug ("onSubscribe(" + s + ")" );
361
376
if (!subscription .isCompleted ()) {
362
377
subscription .complete (s );
363
378
} else {
@@ -367,13 +382,19 @@ public void onSubscribe(Subscription s) {
367
382
368
383
@ Override
369
384
public void onError (Throwable cause ) {
370
- System . out . println ("onError(" + cause + ")" );
385
+ debug ("onError(" + cause + ")" );
371
386
if (subscription .isCompleted ()) {
372
387
super .onError (cause );
373
388
} else {
374
389
env .flop (cause , "Subscriber::onError(" + cause + ") called before Subscriber::onSubscribe" );
375
390
}
376
391
}
392
+
393
+ /** If {@code TestEnvironment#printlnDebug} is true, print debug message to std out. */
394
+ private void debug (String msg ) {
395
+ if (env .printlnDebug )
396
+ System .out .println (msg );
397
+ }
377
398
}
378
399
379
400
public static class TestSubscriber <T > implements Subscriber <T > {
@@ -602,12 +623,16 @@ public boolean isCompleted() {
602
623
}
603
624
604
625
605
- /** Allows using expectCompletion to await for completion of the value and complete it _then_ */
626
+ /**
627
+ * Allows using expectCompletion to await for completion of the value and complete it _then_
628
+ */
606
629
public void complete (T value ) {
607
630
abq .add (value );
608
631
}
609
632
610
- /** Completes the promise right away, it is not possible to expectCompletion on a Promise completed this way */
633
+ /**
634
+ * Completes the promise right away, it is not possible to expectCompletion on a Promise completed this way
635
+ */
611
636
public void completeImmediatly (T value ) {
612
637
_value = value ;
613
638
}
0 commit comments