Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Enabling NOOP classes to work with pre-existing production code #263

Merged
merged 1 commit into from
Mar 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Scope activate(Span span, boolean finishOnClose) {

@Override
public Scope active() {
return null;
return NoopScope.INSTANCE;
}

static class NoopScopeImpl implements NoopScopeManager.NoopScope {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ScopeManager scopeManager() {

@Override
public Span activeSpan() {
return null;
return NoopSpanImpl.INSTANCE;
}

@Override
Expand Down
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");
}
}
}
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");
}
}
}