aboutsummaryrefslogtreecommitdiffstats
path: root/api/src/test
diff options
context:
space:
mode:
authorBogdan Drutu <bdrutu@google.com>2017-11-29 18:44:36 -0800
committerGitHub <noreply@github.com>2017-11-29 18:44:36 -0800
commit1cec10ed55408d525619d8c712e1d092def114ec (patch)
treea780133451dee735872e2aedbaf263b9f35b52ea /api/src/test
parentaa4e8c65140b0069192596b320d9e8d46644427b (diff)
downloadplatform_external_opencensus-java-1cec10ed55408d525619d8c712e1d092def114ec.tar.gz
platform_external_opencensus-java-1cec10ed55408d525619d8c712e1d092def114ec.tar.bz2
platform_external_opencensus-java-1cec10ed55408d525619d8c712e1d092def114ec.zip
Remove ScopedSpanHandle and make SpanInScope able to close the Span. (#848)
* Remove ScopedSpanHandle and make SpanInScope able to close the Span. * Fix extra ";". * Fix comments.
Diffstat (limited to 'api/src/test')
-rw-r--r--api/src/test/java/io/opencensus/trace/CurrentSpanUtilsTest.java23
-rw-r--r--api/src/test/java/io/opencensus/trace/ScopedSpanHandleTest.java54
2 files changed, 20 insertions, 57 deletions
diff --git a/api/src/test/java/io/opencensus/trace/CurrentSpanUtilsTest.java b/api/src/test/java/io/opencensus/trace/CurrentSpanUtilsTest.java
index afc7db63..8ba910b0 100644
--- a/api/src/test/java/io/opencensus/trace/CurrentSpanUtilsTest.java
+++ b/api/src/test/java/io/opencensus/trace/CurrentSpanUtilsTest.java
@@ -17,6 +17,9 @@
package io.opencensus.trace;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.same;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
import io.grpc.Context;
import io.opencensus.common.Scope;
@@ -57,21 +60,35 @@ public class CurrentSpanUtilsTest {
}
@Test
- public void withSpan() {
+ public void withSpan_CloseDetaches() {
assertThat(CurrentSpanUtils.getCurrentSpan()).isNull();
- Scope ws = CurrentSpanUtils.withSpan(span);
+ Scope ws = CurrentSpanUtils.withSpan(span, false);
try {
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
} finally {
ws.close();
}
assertThat(CurrentSpanUtils.getCurrentSpan()).isNull();
+ verifyZeroInteractions(span);
+ }
+
+ @Test
+ public void withSpan_CloseDetachesAndEndsSpan() {
+ assertThat(CurrentSpanUtils.getCurrentSpan()).isNull();
+ Scope ss = CurrentSpanUtils.withSpan(span, true);
+ try {
+ assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
+ } finally {
+ ss.close();
+ }
+ assertThat(CurrentSpanUtils.getCurrentSpan()).isNull();
+ verify(span).end(same(EndSpanOptions.DEFAULT));
}
@Test
public void propagationViaRunnable() {
Runnable runnable = null;
- Scope ws = CurrentSpanUtils.withSpan(span);
+ Scope ws = CurrentSpanUtils.withSpan(span, false);
try {
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
runnable =
diff --git a/api/src/test/java/io/opencensus/trace/ScopedSpanHandleTest.java b/api/src/test/java/io/opencensus/trace/ScopedSpanHandleTest.java
deleted file mode 100644
index a8c18819..00000000
--- a/api/src/test/java/io/opencensus/trace/ScopedSpanHandleTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2017, OpenCensus 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.opencensus.trace;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.same;
-import static org.mockito.Mockito.verify;
-
-import io.opencensus.common.Scope;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-/** Unit tests for {@link ScopedSpanHandle}. */
-@RunWith(JUnit4.class)
-public class ScopedSpanHandleTest {
- private static final Tracer tracer = Tracer.getNoopTracer();
- @Mock private Span span;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- }
-
- @Test
- public void initAttachesSpan_CloseDetachesAndEndsSpan() {
- assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
- Scope ss = new ScopedSpanHandle(span);
- try {
- assertThat(tracer.getCurrentSpan()).isSameAs(span);
- } finally {
- ss.close();
- }
- assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
- verify(span).end(same(EndSpanOptions.DEFAULT));
- }
-}