|
13 | 13 | */
|
14 | 14 | package zipkin.internal;
|
15 | 15 |
|
| 16 | +import java.nio.ByteBuffer; |
16 | 17 | import org.junit.Test;
|
17 | 18 | import zipkin.Annotation;
|
18 | 19 | import zipkin.BinaryAnnotation;
|
| 20 | +import zipkin.BinaryAnnotation.Type; |
19 | 21 | import zipkin.Constants;
|
20 | 22 | import zipkin.Endpoint;
|
21 | 23 | import zipkin.Span;
|
@@ -722,4 +724,41 @@ public class Span2ConverterTest {
|
722 | 724 | assertThat(Span2Converter.fromSpan(shared))
|
723 | 725 | .containsExactly(first, second);
|
724 | 726 | }
|
| 727 | + |
| 728 | + // test converted from stackdriver-zipkin |
| 729 | + @Test public void convertBinaryAnnotations() { |
| 730 | + byte[] boolBuffer = ByteBuffer.allocate(1).put((byte) 1).array(); |
| 731 | + byte[] shortBuffer = ByteBuffer.allocate(2).putShort((short) 20).array(); |
| 732 | + byte[] intBuffer = ByteBuffer.allocate(4).putInt(32800).array(); |
| 733 | + byte[] longBuffer = ByteBuffer.allocate(8).putLong(2147483700L).array(); |
| 734 | + byte[] doubleBuffer = ByteBuffer.allocate(8).putDouble(3.1415).array(); |
| 735 | + byte[] bytesBuffer = "any carnal pleasure".getBytes(Util.UTF_8); |
| 736 | + Span span = Span.builder() |
| 737 | + .traceId(1) |
| 738 | + .name("test") |
| 739 | + .id(2) |
| 740 | + .addBinaryAnnotation(BinaryAnnotation.create("bool", boolBuffer, Type.BOOL, frontend)) |
| 741 | + .addBinaryAnnotation(BinaryAnnotation.create("short", shortBuffer, Type.I16, frontend)) |
| 742 | + .addBinaryAnnotation(BinaryAnnotation.create("int", intBuffer, Type.I32, frontend)) |
| 743 | + .addBinaryAnnotation(BinaryAnnotation.create("long", longBuffer, Type.I64, frontend)) |
| 744 | + .addBinaryAnnotation(BinaryAnnotation.create("double", doubleBuffer, Type.DOUBLE, frontend)) |
| 745 | + .addBinaryAnnotation(BinaryAnnotation.create("bytes", bytesBuffer, Type.BYTES, frontend)) |
| 746 | + .build(); |
| 747 | + |
| 748 | + Span2 span2 = Span2.builder() |
| 749 | + .traceId(1) |
| 750 | + .name("test") |
| 751 | + .id(2) |
| 752 | + .localEndpoint(frontend) |
| 753 | + .putTag("bool", "true") |
| 754 | + .putTag("short", "20") |
| 755 | + .putTag("int", "32800") |
| 756 | + .putTag("long", "2147483700") |
| 757 | + .putTag("double", "3.1415") |
| 758 | + .putTag("bytes", "YW55IGNhcm5hbCBwbGVhc3VyZQ==") // from https://en.wikipedia.org/wiki/Base64 |
| 759 | + .build(); |
| 760 | + |
| 761 | + assertThat(Span2Converter.fromSpan(span)) |
| 762 | + .containsExactly(span2); |
| 763 | + } |
725 | 764 | }
|
0 commit comments