Skip to content
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

Fix for issue #73: Allow ScopeManager.active().close() and let it be a no-op #74

Merged
merged 1 commit into from
Apr 11, 2018
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
5 changes: 2 additions & 3 deletions src/main/java/brave/opentracing/BraveScopeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ public final class BraveScopeManager implements ScopeManager {
/**
* This api's only purpose is to retrieve the {@link Scope#span() span}.
*
* @throws IllegalStateException if you attempt to close the resulting scope.
* Calling {@link Scope#close() close } on the returned scope has no effect on the active span
*/
@Override public Scope active() {
BraveSpan span = currentSpan();
if (span == null) return null;
return new Scope() {
@Override public void close() {
throw new IllegalStateException(
"Scope should not be closed via ScopeManager.active().close()");
// no-op
}

@Override public Span span() {
Expand Down
14 changes: 5 additions & 9 deletions src/test/java/brave/opentracing/BraveScopeManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;

public class BraveScopeManagerTest {

Expand Down Expand Up @@ -74,15 +73,12 @@ public class BraveScopeManagerTest {
}
}

@Test public void scopeManagerActiveClose_unsupported() {
BraveSpan span = opentracing.buildSpan("spanA").start();
try (Scope scopeA = opentracing.scopeManager().activate(span, false)) {
@Test public void scopeManagerActiveClose() {
BraveSpan spanA = opentracing.buildSpan("spanA").start();
try (Scope scopeA = opentracing.scopeManager().activate(spanA, false)) {
Scope scopeB = opentracing.scopeManager().active();
try {
scopeB.close();
failBecauseExceptionWasNotThrown(IllegalStateException.class);
} catch (IllegalStateException e) {
}

scopeB.close();
}
}

Expand Down