aboutsummaryrefslogtreecommitdiff
path: root/api/src/test/java/io/opencensus
diff options
context:
space:
mode:
authorBogdan Drutu <bdrutu@google.com>2017-12-11 16:12:53 -0800
committerGitHub <noreply@github.com>2017-12-11 16:12:53 -0800
commit381e11c5168e5d31e09ec92840f908b42be647e6 (patch)
treeb4d69bd3f2e5b1c7ef903278be6960420d3aa737 /api/src/test/java/io/opencensus
parente2664fb9a41ea54394d4b111052ef2c3ab0d7b0c (diff)
downloadopencensus-java-381e11c5168e5d31e09ec92840f908b42be647e6.tar.gz
Add initial support for b3-propagation headers. (#889)
* Add initial support for b3-propagation headers. * Update tests and throw exception when missing span_id or trace_id. * Cleanup and add more tests. * Update comments. Update tests.
Diffstat (limited to 'api/src/test/java/io/opencensus')
-rw-r--r--api/src/test/java/io/opencensus/trace/SpanIdTest.java18
-rw-r--r--api/src/test/java/io/opencensus/trace/TraceIdTest.java19
-rw-r--r--api/src/test/java/io/opencensus/trace/TracerTest.java3
3 files changed, 33 insertions, 7 deletions
diff --git a/api/src/test/java/io/opencensus/trace/SpanIdTest.java b/api/src/test/java/io/opencensus/trace/SpanIdTest.java
index 36226da5..4a5bc2ae 100644
--- a/api/src/test/java/io/opencensus/trace/SpanIdTest.java
+++ b/api/src/test/java/io/opencensus/trace/SpanIdTest.java
@@ -28,7 +28,7 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class SpanIdTest {
private static final byte[] firstBytes = new byte[] {0, 0, 0, 0, 0, 0, 0, 'a'};
- private static final byte[] secondBytes = new byte[] {(byte) 0xFF, 0, 0, 0, 0, 0, 0, 0};
+ private static final byte[] secondBytes = new byte[] {(byte) 0xFF, 0, 0, 0, 0, 0, 0, 'A'};
private static final SpanId first = SpanId.fromBytes(firstBytes);
private static final SpanId second = SpanId.fromBytes(secondBytes);
@@ -45,6 +45,20 @@ public class SpanIdTest {
}
@Test
+ public void fromLowerBase16() {
+ assertThat(SpanId.fromLowerBase16("0000000000000000")).isEqualTo(SpanId.INVALID);
+ assertThat(SpanId.fromLowerBase16("0000000000000061")).isEqualTo(first);
+ assertThat(SpanId.fromLowerBase16("ff00000000000041")).isEqualTo(second);
+ }
+
+ @Test
+ public void toLowerBase16() {
+ assertThat(SpanId.INVALID.toLowerBase16()).isEqualTo("0000000000000000");
+ assertThat(first.toLowerBase16()).isEqualTo("0000000000000061");
+ assertThat(second.toLowerBase16()).isEqualTo("ff00000000000041");
+ }
+
+ @Test
public void getBytes() {
assertThat(first.getBytes()).isEqualTo(firstBytes);
assertThat(second.getBytes()).isEqualTo(secondBytes);
@@ -71,6 +85,6 @@ public class SpanIdTest {
public void traceId_ToString() {
assertThat(SpanId.INVALID.toString()).contains("0000000000000000");
assertThat(first.toString()).contains("0000000000000061");
- assertThat(second.toString()).contains("ff00000000000000");
+ assertThat(second.toString()).contains("ff00000000000041");
}
}
diff --git a/api/src/test/java/io/opencensus/trace/TraceIdTest.java b/api/src/test/java/io/opencensus/trace/TraceIdTest.java
index 8c1a1004..c8b5dc8f 100644
--- a/api/src/test/java/io/opencensus/trace/TraceIdTest.java
+++ b/api/src/test/java/io/opencensus/trace/TraceIdTest.java
@@ -30,7 +30,7 @@ public class TraceIdTest {
private static final byte[] firstBytes =
new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'a'};
private static final byte[] secondBytes =
- new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'A'};
+ new byte[] {(byte) 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'A'};
private static final TraceId first = TraceId.fromBytes(firstBytes);
private static final TraceId second = TraceId.fromBytes(secondBytes);
@@ -53,6 +53,21 @@ public class TraceIdTest {
}
@Test
+ public void fromLowerBase16() {
+ assertThat(TraceId.fromLowerBase16("00000000000000000000000000000000"))
+ .isEqualTo(TraceId.INVALID);
+ assertThat(TraceId.fromLowerBase16("00000000000000000000000000000061")).isEqualTo(first);
+ assertThat(TraceId.fromLowerBase16("ff000000000000000000000000000041")).isEqualTo(second);
+ }
+
+ @Test
+ public void toLowerBase16() {
+ assertThat(TraceId.INVALID.toLowerBase16()).isEqualTo("00000000000000000000000000000000");
+ assertThat(first.toLowerBase16()).isEqualTo("00000000000000000000000000000061");
+ assertThat(second.toLowerBase16()).isEqualTo("ff000000000000000000000000000041");
+ }
+
+ @Test
public void traceId_CompareTo() {
assertThat(first.compareTo(second)).isGreaterThan(0);
assertThat(second.compareTo(first)).isLessThan(0);
@@ -73,6 +88,6 @@ public class TraceIdTest {
public void traceId_ToString() {
assertThat(TraceId.INVALID.toString()).contains("00000000000000000000000000000000");
assertThat(first.toString()).contains("00000000000000000000000000000061");
- assertThat(second.toString()).contains("00000000000000000000000000000041");
+ assertThat(second.toString()).contains("ff000000000000000000000000000041");
}
}
diff --git a/api/src/test/java/io/opencensus/trace/TracerTest.java b/api/src/test/java/io/opencensus/trace/TracerTest.java
index 7c65742e..8f0ac64f 100644
--- a/api/src/test/java/io/opencensus/trace/TracerTest.java
+++ b/api/src/test/java/io/opencensus/trace/TracerTest.java
@@ -23,9 +23,7 @@ import static org.mockito.Mockito.when;
import io.grpc.Context;
import io.opencensus.common.Scope;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mock;
@@ -38,7 +36,6 @@ import org.mockito.MockitoAnnotations;
public class TracerTest {
private static final Tracer noopTracer = Tracer.getNoopTracer();
private static final String SPAN_NAME = "MySpanName";
- @Rule public ExpectedException thrown = ExpectedException.none();
@Mock private Tracer tracer;
@Mock private SpanBuilder spanBuilder;
@Mock private Span span;