This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabling NOOP classes to work with pre-existing production code (#263)
In special circumstances, code may be written to automatically create spans, negating the need to always check if Tracer.activeSpan() is null. Under these circumstances, the Noop Tracer and ScopeManager will cause NPEs when they return null values when their `active` values are accessed from the GlobalTracer. This prevents code from running successfully when using Noop Tracers. This minor change allows users to depend that their code will genuinely Noop under all use cases.
- Loading branch information
1 parent
806b026
commit 943061e
Showing
4 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
opentracing-noop/src/test/java/io/opentracing/noop/NoopScopeManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2016-2018 The OpenTracing Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package io.opentracing.noop; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
|
||
import io.opentracing.Scope; | ||
|
||
public class NoopScopeManagerTest { | ||
|
||
@Test | ||
public void activeValueToleratesUseTest() { | ||
try{ | ||
final Scope active = NoopScopeManager.INSTANCE.active(); | ||
assertNotNull(active); | ||
active.close(); | ||
} catch (final NullPointerException e) { | ||
fail("NoopScopeManagerImpl.active() should return a usable scope"); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
opentracing-noop/src/test/java/io/opentracing/noop/NoopTracerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2016-2018 The OpenTracing Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package io.opentracing.noop; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
|
||
import io.opentracing.Span; | ||
import io.opentracing.tag.Tags; | ||
|
||
public class NoopTracerTest { | ||
|
||
@Test | ||
public void activeSpanValueToleratesUseTest() { | ||
try { | ||
final Span activeSpan = NoopTracerImpl.INSTANCE.activeSpan(); | ||
assertNotNull(activeSpan); | ||
Tags.ERROR.set(activeSpan, true); | ||
} catch (final NullPointerException e) { | ||
fail("NoopTracer.activeSpan() should return a usable span"); | ||
} | ||
} | ||
} |