Skip to content

Commit

Permalink
Allow ScopeManager.active().close() and let it be a no-op
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders Hanson authored and adriancole committed Apr 11, 2018
1 parent 9485f11 commit 51d7fb9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
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

0 comments on commit 51d7fb9

Please sign in to comment.