@Test(expected = NullPointerException.class) public void fromDescription_NullDescription() { Annotation.fromDescription(null); }
@Test public void annotation_ToString() { Annotation annotation = Annotation.fromDescription("MyAnnotationText"); assertThat(annotation.toString()).contains("MyAnnotationText"); Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>(); attributes.put( "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue")); annotation = Annotation.fromDescriptionAndAttributes("MyAnnotationText2", attributes); assertThat(annotation.toString()).contains("MyAnnotationText2"); assertThat(annotation.toString()).contains(attributes.toString()); } }
@Test public void annotation_EqualsAndHashCode() { EqualsTester tester = new EqualsTester(); Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>(); attributes.put( "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue")); tester .addEqualityGroup( Annotation.fromDescription("MyAnnotationText"), Annotation.fromDescriptionAndAttributes( "MyAnnotationText", Collections.<String, AttributeValue>emptyMap())) .addEqualityGroup( Annotation.fromDescriptionAndAttributes("MyAnnotationText", attributes), Annotation.fromDescriptionAndAttributes("MyAnnotationText", attributes)) .addEqualityGroup(Annotation.fromDescription("MyAnnotationText2")); tester.testEquals(); }
@Test public void fromDescription() { Annotation annotation = Annotation.fromDescription("MyAnnotationText"); assertThat(annotation.getDescription()).isEqualTo("MyAnnotationText"); assertThat(annotation.getAttributes().size()).isEqualTo(0); }
span.putAttributes(attributes); testClock.advanceTime(Duration.create(0, 100)); span.addAnnotation(Annotation.fromDescription(ANNOTATION_DESCRIPTION)); testClock.advanceTime(Duration.create(0, 100)); span.addAnnotation(ANNOTATION_DESCRIPTION, attributes); .isEqualTo(timestamp.addNanos(100)); assertThat(spanData.getAnnotations().getEvents().get(0).getEvent()) .isEqualTo(Annotation.fromDescription(ANNOTATION_DESCRIPTION)); assertThat(spanData.getAnnotations().getEvents().get(1).getTimestamp()) .isEqualTo(timestamp.addNanos(200));
timestampConverter, testClock); Annotation annotation = Annotation.fromDescription(ANNOTATION_DESCRIPTION); for (int i = 0; i < 2 * maxNumberOfAnnotations; i++) { span.addAnnotation(annotation);
span.putAttributes(attributes); testClock.advanceTime(Duration.create(0, 100)); span.addAnnotation(Annotation.fromDescription(ANNOTATION_DESCRIPTION)); testClock.advanceTime(Duration.create(0, 100)); span.addAnnotation(ANNOTATION_DESCRIPTION, attributes); .isEqualTo(timestamp.addNanos(100)); assertThat(spanData.getAnnotations().getEvents().get(0).getEvent()) .isEqualTo(Annotation.fromDescription(ANNOTATION_DESCRIPTION)); assertThat(spanData.getAnnotations().getEvents().get(1).getTimestamp()) .isEqualTo(timestamp.addNanos(200));
@Test public void doNotCrash() { Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>(); attributes.put( "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue")); Map<String, AttributeValue> multipleAttributes = new HashMap<String, AttributeValue>(); multipleAttributes.put( "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue")); multipleAttributes.put("MyBooleanAttributeKey", AttributeValue.booleanAttributeValue(true)); multipleAttributes.put("MyLongAttributeKey", AttributeValue.longAttributeValue(123)); // Tests only that all the methods are not crashing/throwing errors. BlankSpan.INSTANCE.putAttribute( "MyStringAttributeKey2", AttributeValue.stringAttributeValue("MyStringAttributeValue2")); BlankSpan.INSTANCE.addAttributes(attributes); BlankSpan.INSTANCE.addAttributes(multipleAttributes); BlankSpan.INSTANCE.addAnnotation("MyAnnotation"); BlankSpan.INSTANCE.addAnnotation("MyAnnotation", attributes); BlankSpan.INSTANCE.addAnnotation("MyAnnotation", multipleAttributes); BlankSpan.INSTANCE.addAnnotation(Annotation.fromDescription("MyAnnotation")); BlankSpan.INSTANCE.addNetworkEvent(NetworkEvent.builder(NetworkEvent.Type.SENT, 1L).build()); BlankSpan.INSTANCE.addMessageEvent(MessageEvent.builder(MessageEvent.Type.SENT, 1L).build()); BlankSpan.INSTANCE.addLink( Link.fromSpanContext(SpanContext.INVALID, Link.Type.CHILD_LINKED_SPAN)); BlankSpan.INSTANCE.setStatus(Status.OK); BlankSpan.INSTANCE.end(EndSpanOptions.DEFAULT); BlankSpan.INSTANCE.end(); }
@Test public void doNotCrash() { Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>(); attributes.put( "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue")); Map<String, AttributeValue> multipleAttributes = new HashMap<String, AttributeValue>(); multipleAttributes.put( "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue")); multipleAttributes.put("MyBooleanAttributeKey", AttributeValue.booleanAttributeValue(true)); multipleAttributes.put("MyLongAttributeKey", AttributeValue.longAttributeValue(123)); // Tests only that all the methods are not crashing/throwing errors. noRecordEventsSpan.putAttribute( "MyStringAttributeKey2", AttributeValue.stringAttributeValue("MyStringAttributeValue2")); noRecordEventsSpan.addAttributes(attributes); noRecordEventsSpan.addAttributes(multipleAttributes); noRecordEventsSpan.addAnnotation("MyAnnotation"); noRecordEventsSpan.addAnnotation("MyAnnotation", attributes); noRecordEventsSpan.addAnnotation("MyAnnotation", multipleAttributes); noRecordEventsSpan.addAnnotation(Annotation.fromDescription("MyAnnotation")); noRecordEventsSpan.addNetworkEvent(NetworkEvent.builder(NetworkEvent.Type.SENT, 1L).build()); noRecordEventsSpan.addMessageEvent(MessageEvent.builder(MessageEvent.Type.SENT, 1L).build()); noRecordEventsSpan.addLink( Link.fromSpanContext(SpanContext.INVALID, Link.Type.CHILD_LINKED_SPAN)); noRecordEventsSpan.setStatus(Status.OK); noRecordEventsSpan.end(EndSpanOptions.DEFAULT); noRecordEventsSpan.end(); } }
"MySingleStringAttributeKey", AttributeValue.stringAttributeValue("MySingleStringAttributeValue")); span.addAnnotation(Annotation.fromDescription(ANNOTATION_DESCRIPTION)); span.addAnnotation(ANNOTATION_DESCRIPTION, attributes); span.addNetworkEvent(