Skip to content

Commit 3b1664b

Browse files
committed
Making debug message formatting disabled when debug is disabled
1 parent 2052c36 commit 3b1664b

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,9 @@ public Subscriber<T> createSubscriber(final SubscriberWhiteboxVerification.White
504504

505505
@Override
506506
public void onSubscribe(final Subscription subscription) {
507-
env.debug(String.format("whiteboxSubscriber::onSubscribe(%s)", subscription));
507+
if (env.debugEnabled()) {
508+
env.debug(String.format("whiteboxSubscriber::onSubscribe(%s)", subscription));
509+
}
508510
if (subs.isCompleted()) subscription.cancel(); // the Probe must also pass subscriber verification
509511

510512
probe.registerOnSubscribe(new SubscriberWhiteboxVerification.SubscriberPuppet() {
@@ -523,19 +525,25 @@ public void signalCancel() {
523525

524526
@Override
525527
public void onNext(T element) {
526-
env.debug(String.format("whiteboxSubscriber::onNext(%s)", element));
528+
if (env.debugEnabled()) {
529+
env.debug(String.format("whiteboxSubscriber::onNext(%s)", element));
530+
}
527531
probe.registerOnNext(element);
528532
}
529533

530534
@Override
531535
public void onComplete() {
532-
env.debug("whiteboxSubscriber::onComplete()");
536+
if (env.debugEnabled()) {
537+
env.debug("whiteboxSubscriber::onComplete()");
538+
}
533539
probe.registerOnComplete();
534540
}
535541

536542
@Override
537543
public void onError(Throwable cause) {
538-
env.debug(String.format("whiteboxSubscriber::onError(%s)", cause));
544+
if (env.debugEnabled()) {
545+
env.debug(String.format("whiteboxSubscriber::onError(%s)", cause));
546+
}
539547
probe.registerOnError(cause);
540548
}
541549
});

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,9 @@ public void onNext(T element) {
772772

773773
signalsReceived += 1;
774774
stackDepthCounter.set(stackDepthCounter.get() + 1);
775-
env.debug(String.format("%s(recursion depth: %d)::onNext(%s)", this, stackDepthCounter.get(), element));
775+
if (env.debugEnabled()) {
776+
env.debug(String.format("%s(recursion depth: %d)::onNext(%s)", this, stackDepthCounter.get(), element));
777+
}
776778

777779
final long callsUntilNow = stackDepthCounter.get();
778780
if (callsUntilNow > boundedDepthOfOnNextAndRequestRecursion()) {
@@ -1082,7 +1084,9 @@ public void required_spec317_mustNotSignalOnErrorWhenPendingAboveLongMaxValue()
10821084

10831085
@Override
10841086
public void onNext(T element) {
1085-
env.debug(String.format("%s::onNext(%s)", this, element));
1087+
if (env.debugEnabled()) {
1088+
env.debug(String.format("%s::onNext(%s)", this, element));
1089+
}
10861090
if (subscription.isCompleted()) {
10871091
if (callsCounter > 0) {
10881092
subscription.value().request(Long.MAX_VALUE - 1);

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

+21-6
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,13 @@ public void verifyNoAsyncErrorsNoDelay() {
320320

321321
/** If {@code TestEnvironment#printlnDebug} is true, print debug message to std out. */
322322
public void debug(String msg) {
323-
if (printlnDebug)
323+
if (debugEnabled()) {
324324
System.out.printf("[TCK-DEBUG] %s%n", msg);
325+
}
326+
}
327+
328+
public final boolean debugEnabled() {
329+
return printlnDebug;
325330
}
326331

327332
/**
@@ -578,7 +583,9 @@ public ManualSubscriberWithSubscriptionSupport(TestEnvironment env) {
578583

579584
@Override
580585
public void onNext(T element) {
581-
env.debug(String.format("%s::onNext(%s)", this, element));
586+
if (env.debugEnabled()) {
587+
env.debug(String.format("%s::onNext(%s)", this, element));
588+
}
582589
if (subscription.isCompleted()) {
583590
super.onNext(element);
584591
} else {
@@ -588,7 +595,9 @@ public void onNext(T element) {
588595

589596
@Override
590597
public void onComplete() {
591-
env.debug(this + "::onComplete()");
598+
if (env.debugEnabled()) {
599+
env.debug(this + "::onComplete()");
600+
}
592601
if (subscription.isCompleted()) {
593602
super.onComplete();
594603
} else {
@@ -598,7 +607,9 @@ public void onComplete() {
598607

599608
@Override
600609
public void onSubscribe(Subscription s) {
601-
env.debug(String.format("%s::onSubscribe(%s)", this, s));
610+
if (env.debugEnabled()) {
611+
env.debug(String.format("%s::onSubscribe(%s)", this, s));
612+
}
602613
if (!subscription.isCompleted()) {
603614
subscription.complete(s);
604615
} else {
@@ -608,7 +619,9 @@ public void onSubscribe(Subscription s) {
608619

609620
@Override
610621
public void onError(Throwable cause) {
611-
env.debug(String.format("%s::onError(%s)", this, cause));
622+
if (env.debugEnabled()) {
623+
env.debug(String.format("%s::onError(%s)", this, cause));
624+
}
612625
if (subscription.isCompleted()) {
613626
super.onError(cause);
614627
} else {
@@ -631,7 +644,9 @@ public BlackholeSubscriberWithSubscriptionSupport(TestEnvironment env) {
631644

632645
@Override
633646
public void onNext(T element) {
634-
env.debug(String.format("%s::onNext(%s)", this, element));
647+
if (env.debugEnabled()) {
648+
env.debug(String.format("%s::onNext(%s)", this, element));
649+
}
635650
if (!subscription.isCompleted()) {
636651
env.flop(String.format("Subscriber::onNext(%s) called before Subscriber::onSubscribe", element));
637652
}

0 commit comments

Comments
 (0)