Skip to content

Commit 201dc6c

Browse files
committed
Making debug message formatting disabled when debug is disabled
1 parent 2052c36 commit 201dc6c

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,8 @@ 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));
508509
if (subs.isCompleted()) subscription.cancel(); // the Probe must also pass subscriber verification
509510

510511
probe.registerOnSubscribe(new SubscriberWhiteboxVerification.SubscriberPuppet() {
@@ -523,19 +524,22 @@ public void signalCancel() {
523524

524525
@Override
525526
public void onNext(T element) {
526-
env.debug(String.format("whiteboxSubscriber::onNext(%s)", element));
527+
if (env.debugEnabled())
528+
env.debug(String.format("whiteboxSubscriber::onNext(%s)", element));
527529
probe.registerOnNext(element);
528530
}
529531

530532
@Override
531533
public void onComplete() {
532-
env.debug("whiteboxSubscriber::onComplete()");
534+
if (env.debugEnabled())
535+
env.debug("whiteboxSubscriber::onComplete()");
533536
probe.registerOnComplete();
534537
}
535538

536539
@Override
537540
public void onError(Throwable cause) {
538-
env.debug(String.format("whiteboxSubscriber::onError(%s)", cause));
541+
if (env.debugEnabled())
542+
env.debug(String.format("whiteboxSubscriber::onError(%s)", cause));
539543
probe.registerOnError(cause);
540544
}
541545
});

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,8 @@ 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));
776777

777778
final long callsUntilNow = stackDepthCounter.get();
778779
if (callsUntilNow > boundedDepthOfOnNextAndRequestRecursion()) {
@@ -1082,7 +1083,8 @@ public void required_spec317_mustNotSignalOnErrorWhenPendingAboveLongMaxValue()
10821083

10831084
@Override
10841085
public void onNext(T element) {
1085-
env.debug(String.format("%s::onNext(%s)", this, element));
1086+
if (env.debugEnabled())
1087+
env.debug(String.format("%s::onNext(%s)", this, element));
10861088
if (subscription.isCompleted()) {
10871089
if (callsCounter > 0) {
10881090
subscription.value().request(Long.MAX_VALUE - 1);

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

+15-6
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,14 @@ 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);
325325
}
326326

327+
public final boolean debugEnabled() {
328+
return printlnDebug;
329+
}
330+
327331
/**
328332
* Looks for given {@code method} method in stack trace.
329333
* Can be used to answer questions like "was this method called from onComplete?".
@@ -578,7 +582,8 @@ public ManualSubscriberWithSubscriptionSupport(TestEnvironment env) {
578582

579583
@Override
580584
public void onNext(T element) {
581-
env.debug(String.format("%s::onNext(%s)", this, element));
585+
if (env.debugEnabled())
586+
env.debug(String.format("%s::onNext(%s)", this, element));
582587
if (subscription.isCompleted()) {
583588
super.onNext(element);
584589
} else {
@@ -588,7 +593,8 @@ public void onNext(T element) {
588593

589594
@Override
590595
public void onComplete() {
591-
env.debug(this + "::onComplete()");
596+
if (env.debugEnabled())
597+
env.debug(this + "::onComplete()");
592598
if (subscription.isCompleted()) {
593599
super.onComplete();
594600
} else {
@@ -598,7 +604,8 @@ public void onComplete() {
598604

599605
@Override
600606
public void onSubscribe(Subscription s) {
601-
env.debug(String.format("%s::onSubscribe(%s)", this, s));
607+
if (env.debugEnabled())
608+
env.debug(String.format("%s::onSubscribe(%s)", this, s));
602609
if (!subscription.isCompleted()) {
603610
subscription.complete(s);
604611
} else {
@@ -608,7 +615,8 @@ public void onSubscribe(Subscription s) {
608615

609616
@Override
610617
public void onError(Throwable cause) {
611-
env.debug(String.format("%s::onError(%s)", this, cause));
618+
if (env.debugEnabled())
619+
env.debug(String.format("%s::onError(%s)", this, cause));
612620
if (subscription.isCompleted()) {
613621
super.onError(cause);
614622
} else {
@@ -631,7 +639,8 @@ public BlackholeSubscriberWithSubscriptionSupport(TestEnvironment env) {
631639

632640
@Override
633641
public void onNext(T element) {
634-
env.debug(String.format("%s::onNext(%s)", this, element));
642+
if (env.debugEnabled())
643+
env.debug(String.format("%s::onNext(%s)", this, element));
635644
if (!subscription.isCompleted()) {
636645
env.flop(String.format("Subscriber::onNext(%s) called before Subscriber::onSubscribe", element));
637646
}

0 commit comments

Comments
 (0)