Skip to content

Making debug message formatting disabled when debug is disabled #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ public Subscriber<T> 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() {
Expand All @@ -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);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down
27 changes: 21 additions & 6 deletions tck/src/main/java/org/reactivestreams/tck/TestEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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));
}
Expand Down