From 3b1664b0cdbb6395151c3e6618eb8e3014282dbe Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Sun, 30 Dec 2018 16:25:07 +0100 Subject: [PATCH] Making debug message formatting disabled when debug is disabled --- .../tck/IdentityProcessorVerification.java | 16 ++++++++--- .../tck/PublisherVerification.java | 8 ++++-- .../reactivestreams/tck/TestEnvironment.java | 27 ++++++++++++++----- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/tck/src/main/java/org/reactivestreams/tck/IdentityProcessorVerification.java b/tck/src/main/java/org/reactivestreams/tck/IdentityProcessorVerification.java index 59142bd4..53b74d05 100644 --- a/tck/src/main/java/org/reactivestreams/tck/IdentityProcessorVerification.java +++ b/tck/src/main/java/org/reactivestreams/tck/IdentityProcessorVerification.java @@ -504,7 +504,9 @@ public Subscriber createSubscriber(final SubscriberWhiteboxVerification.White @Override public void onSubscribe(final Subscription subscription) { - env.debug(String.format("whiteboxSubscriber::onSubscribe(%s)", subscription)); + if (env.debugEnabled()) { + env.debug(String.format("whiteboxSubscriber::onSubscribe(%s)", subscription)); + } if (subs.isCompleted()) subscription.cancel(); // the Probe must also pass subscriber verification probe.registerOnSubscribe(new SubscriberWhiteboxVerification.SubscriberPuppet() { @@ -523,19 +525,25 @@ public void signalCancel() { @Override public void onNext(T element) { - env.debug(String.format("whiteboxSubscriber::onNext(%s)", element)); + if (env.debugEnabled()) { + env.debug(String.format("whiteboxSubscriber::onNext(%s)", element)); + } probe.registerOnNext(element); } @Override public void onComplete() { - env.debug("whiteboxSubscriber::onComplete()"); + if (env.debugEnabled()) { + env.debug("whiteboxSubscriber::onComplete()"); + } probe.registerOnComplete(); } @Override public void onError(Throwable cause) { - env.debug(String.format("whiteboxSubscriber::onError(%s)", cause)); + if (env.debugEnabled()) { + env.debug(String.format("whiteboxSubscriber::onError(%s)", cause)); + } probe.registerOnError(cause); } }); diff --git a/tck/src/main/java/org/reactivestreams/tck/PublisherVerification.java b/tck/src/main/java/org/reactivestreams/tck/PublisherVerification.java index 54badd61..56af3ddb 100644 --- a/tck/src/main/java/org/reactivestreams/tck/PublisherVerification.java +++ b/tck/src/main/java/org/reactivestreams/tck/PublisherVerification.java @@ -772,7 +772,9 @@ public void onNext(T element) { signalsReceived += 1; stackDepthCounter.set(stackDepthCounter.get() + 1); - env.debug(String.format("%s(recursion depth: %d)::onNext(%s)", this, stackDepthCounter.get(), element)); + if (env.debugEnabled()) { + env.debug(String.format("%s(recursion depth: %d)::onNext(%s)", this, stackDepthCounter.get(), element)); + } final long callsUntilNow = stackDepthCounter.get(); if (callsUntilNow > boundedDepthOfOnNextAndRequestRecursion()) { @@ -1082,7 +1084,9 @@ public void required_spec317_mustNotSignalOnErrorWhenPendingAboveLongMaxValue() @Override public void onNext(T element) { - env.debug(String.format("%s::onNext(%s)", this, element)); + if (env.debugEnabled()) { + env.debug(String.format("%s::onNext(%s)", this, element)); + } if (subscription.isCompleted()) { if (callsCounter > 0) { subscription.value().request(Long.MAX_VALUE - 1); diff --git a/tck/src/main/java/org/reactivestreams/tck/TestEnvironment.java b/tck/src/main/java/org/reactivestreams/tck/TestEnvironment.java index ce0a5b99..c44d483b 100644 --- a/tck/src/main/java/org/reactivestreams/tck/TestEnvironment.java +++ b/tck/src/main/java/org/reactivestreams/tck/TestEnvironment.java @@ -320,8 +320,13 @@ public void verifyNoAsyncErrorsNoDelay() { /** If {@code TestEnvironment#printlnDebug} is true, print debug message to std out. */ public void debug(String msg) { - if (printlnDebug) + if (debugEnabled()) { System.out.printf("[TCK-DEBUG] %s%n", msg); + } + } + + public final boolean debugEnabled() { + return printlnDebug; } /** @@ -578,7 +583,9 @@ public ManualSubscriberWithSubscriptionSupport(TestEnvironment env) { @Override public void onNext(T element) { - env.debug(String.format("%s::onNext(%s)", this, element)); + if (env.debugEnabled()) { + env.debug(String.format("%s::onNext(%s)", this, element)); + } if (subscription.isCompleted()) { super.onNext(element); } else { @@ -588,7 +595,9 @@ public void onNext(T element) { @Override public void onComplete() { - env.debug(this + "::onComplete()"); + if (env.debugEnabled()) { + env.debug(this + "::onComplete()"); + } if (subscription.isCompleted()) { super.onComplete(); } else { @@ -598,7 +607,9 @@ public void onComplete() { @Override public void onSubscribe(Subscription s) { - env.debug(String.format("%s::onSubscribe(%s)", this, s)); + if (env.debugEnabled()) { + env.debug(String.format("%s::onSubscribe(%s)", this, s)); + } if (!subscription.isCompleted()) { subscription.complete(s); } else { @@ -608,7 +619,9 @@ public void onSubscribe(Subscription s) { @Override public void onError(Throwable cause) { - env.debug(String.format("%s::onError(%s)", this, cause)); + if (env.debugEnabled()) { + env.debug(String.format("%s::onError(%s)", this, cause)); + } if (subscription.isCompleted()) { super.onError(cause); } else { @@ -631,7 +644,9 @@ public BlackholeSubscriberWithSubscriptionSupport(TestEnvironment env) { @Override public void onNext(T element) { - env.debug(String.format("%s::onNext(%s)", this, element)); + if (env.debugEnabled()) { + env.debug(String.format("%s::onNext(%s)", this, element)); + } if (!subscription.isCompleted()) { env.flop(String.format("Subscriber::onNext(%s) called before Subscriber::onSubscribe", element)); }