From 51d7fb9db4900638aec79d9cc67a673f1d5f09af Mon Sep 17 00:00:00 2001 From: Anders Hanson Date: Wed, 11 Apr 2018 10:15:58 +0200 Subject: [PATCH] Allow ScopeManager.active().close() and let it be a no-op --- .../java/brave/opentracing/BraveScopeManager.java | 5 ++--- .../brave/opentracing/BraveScopeManagerTest.java | 14 +++++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/brave/opentracing/BraveScopeManager.java b/src/main/java/brave/opentracing/BraveScopeManager.java index db9b30a..14ce9e7 100644 --- a/src/main/java/brave/opentracing/BraveScopeManager.java +++ b/src/main/java/brave/opentracing/BraveScopeManager.java @@ -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() { diff --git a/src/test/java/brave/opentracing/BraveScopeManagerTest.java b/src/test/java/brave/opentracing/BraveScopeManagerTest.java index 6734185..b0a4f8f 100644 --- a/src/test/java/brave/opentracing/BraveScopeManagerTest.java +++ b/src/test/java/brave/opentracing/BraveScopeManagerTest.java @@ -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 { @@ -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(); } }