Skip to content

Commit da7be63

Browse files
committed
Added optional printlnDebug mode
1 parent 57f7ded commit da7be63

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
organization in ThisBuild := "org.reactivestreams"
22

3-
version in ThisBuild := "0.4.0.M1-ktoso"
3+
version in ThisBuild := "0.4.0.M1"
44

55
scalaVersion in ThisBuild := "2.10.3"
66

tck/src/main/java/org/reactivestreams/tck/TestEnvironment.java

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class TestEnvironment {
2020
public static final int TEST_BUFFER_SIZE = 16;
2121

2222
private final long defaultTimeoutMillis;
23+
private final boolean printlnDebug;
2324

2425
private CopyOnWriteArrayList<Throwable> asyncErrors = new CopyOnWriteArrayList<Throwable>();
2526

@@ -30,11 +31,27 @@ public class TestEnvironment {
3031
* run the tests.
3132
*
3233
* @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.
3336
*/
34-
public TestEnvironment(long defaultTimeoutMillis) {
37+
public TestEnvironment(long defaultTimeoutMillis, boolean printlnDebug) {
3538
this.defaultTimeoutMillis = defaultTimeoutMillis;
39+
this.printlnDebug = printlnDebug;
3640
}
3741

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+
3855
// keeping method around
3956
public long defaultTimeoutMillis() {
4057
return defaultTimeoutMillis;
@@ -231,9 +248,7 @@ public T nextElement(String errorMsg) throws InterruptedException {
231248
}
232249

233250
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);
237252
}
238253

239254
public Optional<T> nextElementOrEndOfStream() throws InterruptedException {
@@ -337,7 +352,7 @@ public ManualSubscriberWithSubscriptionSupport(TestEnvironment env) {
337352

338353
@Override
339354
public void onNext(T element) {
340-
System.out.println("onNext(" + element + ")");
355+
debug("onNext(" + element + ")");
341356
if (subscription.isCompleted()) {
342357
super.onNext(element);
343358
} else {
@@ -347,7 +362,7 @@ public void onNext(T element) {
347362

348363
@Override
349364
public void onComplete() {
350-
System.out.println("onComplete");
365+
debug("onComplete");
351366
if (subscription.isCompleted()) {
352367
super.onComplete();
353368
} else {
@@ -357,7 +372,7 @@ public void onComplete() {
357372

358373
@Override
359374
public void onSubscribe(Subscription s) {
360-
System.out.println("onSubscribe(" + s + ")");
375+
debug("onSubscribe(" + s + ")");
361376
if (!subscription.isCompleted()) {
362377
subscription.complete(s);
363378
} else {
@@ -367,13 +382,19 @@ public void onSubscribe(Subscription s) {
367382

368383
@Override
369384
public void onError(Throwable cause) {
370-
System.out.println("onError(" + cause+")");
385+
debug("onError(" + cause + ")");
371386
if (subscription.isCompleted()) {
372387
super.onError(cause);
373388
} else {
374389
env.flop(cause, "Subscriber::onError(" + cause + ") called before Subscriber::onSubscribe");
375390
}
376391
}
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+
}
377398
}
378399

379400
public static class TestSubscriber<T> implements Subscriber<T> {
@@ -602,12 +623,16 @@ public boolean isCompleted() {
602623
}
603624

604625

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+
*/
606629
public void complete(T value) {
607630
abq.add(value);
608631
}
609632

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+
*/
611636
public void completeImmediatly(T value) {
612637
_value = value;
613638
}

0 commit comments

Comments
 (0)