com.nike.wingtips.Span.generateRootSpanForNewTrace()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(12.9k)|赞(0)|评价(0)|浏览(226)

本文整理了Java中com.nike.wingtips.Span.generateRootSpanForNewTrace()方法的一些代码示例,展示了Span.generateRootSpanForNewTrace()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Span.generateRootSpanForNewTrace()方法的具体详情如下:
包路径:com.nike.wingtips.Span
类名称:Span
方法名:generateRootSpanForNewTrace

Span.generateRootSpanForNewTrace介绍

暂无

代码示例

代码示例来源:origin: Nike-Inc/wingtips

@DataProvider
public static Object[][] spanStackDataProvider() {
  Span rootSpan = Span.generateRootSpanForNewTrace("rootspan", SpanPurpose.SERVER).build();
  Span childSpan = rootSpan.generateChildSpan("childSpan", SpanPurpose.CLIENT);
  return new Object[][] {
      { null },
      { new LinkedList<>() },
      { new LinkedList<>(Collections.singleton(rootSpan)) },
      { new LinkedList<>(Arrays.asList(rootSpan, childSpan)) }
  };
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void toJson_should_use_cached_json() {
  // given
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  String uuidString = UUID.randomUUID().toString();
  Whitebox.setInternalState(validSpan, "cachedJsonRepresentation", uuidString);
  // when
  String toJsonResult = validSpan.toJSON();
  // then
  assertThat(toJsonResult).isEqualTo(uuidString);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void toKeyValueString_should_use_cached_key_value_string() {
  // given
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  String uuidString = UUID.randomUUID().toString();
  Whitebox.setInternalState(validSpan, "cachedKeyValueRepresentation", uuidString);
  // when
  String toKeyValueStringResult = validSpan.toKeyValueString();
  // then
  assertThat(toKeyValueStringResult).isEqualTo(uuidString);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void convertSpanToJSON_should_function_properly_for_non_completed_spans() throws IOException {
  // given: valid span and JSON string from SpanParser.convertSpanToJSON()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  String json = SpanParser.convertSpanToJSON(validSpan);
  assertThat(validSpan.isCompleted()).isFalse();
  assertThat(validSpan.getDurationNanos()).isNull();
  // when: jackson is used to deserialize that JSON
  Map<String, Object> spanValuesFromJackson = objectMapper.readValue(json, new TypeReference<Map<String, Object>>() {});
  // then: the original span and jackson's span values should be exactly the same
  verifySpanEqualsDeserializedValues(validSpan, spanValuesFromJackson);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test(expected = IllegalStateException.class)
public void complete_should_throw_IllegalStateException_if_span_is_already_completed() {
  // given
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  validSpan.complete();
  assertThat(validSpan.isCompleted()).isTrue();
  // expect
  validSpan.complete();
  fail("Expected IllegalStateException but no exception was thrown");
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void convertSpanToJSON_should_function_properly_for_completed_spans() throws IOException {
  // given: valid span and completed, and JSON string from SpanParser.convertSpanToJSON()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  completeSpan(validSpan);
  assertThat(validSpan.isCompleted()).isTrue();
  assertThat(validSpan.getDurationNanos()).isNotNull();
  String json = SpanParser.convertSpanToJSON(validSpan);
  // when: jackson is used to deserialize that JSON
  Map<String, Object> spanValuesFromJackson = objectMapper.readValue(json, new TypeReference<Map<String, Object>>() {});
  // then: the original span and jackson's span values should be exactly the same
  verifySpanEqualsDeserializedValues(validSpan, spanValuesFromJackson);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void fromKeyValueString_should_function_properly_for_non_completed_spans() {
  // given: valid, non-completed span and key/value string from Span.fromKeyValueString()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  String keyValStr = SpanParser.convertSpanToKeyValueFormat(validSpan);
  assertThat(validSpan.isCompleted()).isFalse();
  // when: fromKeyValueString is called
  Span spanFromKeyValStr = SpanParser.fromKeyValueString(keyValStr);
  // then: the original span and the fromKeyValueString() span values should be exactly the same
  verifySpanDeepEquals(spanFromKeyValStr, validSpan, true);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void fromJson_should_function_properly_for_non_completed_spans() {
  // given: valid, non-completed span and JSON string from SpanParser.convertSpanToJSON()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  String json = SpanParser.convertSpanToJSON(validSpan);
  assertThat(validSpan.isCompleted()).isFalse();
  // when: fromJson is called
  Span spanFromJson = SpanParser.fromJSON(json);
  // then: the original span and the fromJson() span values should be exactly the same
  verifySpanDeepEquals(spanFromJson, validSpan, true);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void convertSpanToKeyValueFormat_should_function_properly_for_non_completed_spans() {
  // given: valid span and key/value string from SpanParser.convertSpanToKeyValueFormat()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  assertThat(validSpan.isCompleted()).isFalse();
  String keyValueStr = SpanParser.convertSpanToKeyValueFormat(validSpan);
  // when: the string is deserialized into a map
  Map<String, Object> deserializedValues = deserializeKeyValueSpanString(keyValueStr);
  // then: the original span and deserialized map values should be exactly the same
  verifySpanEqualsDeserializedValues(validSpan, deserializedValues);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void complete_should_reset_cached_json() throws IOException {
  // given
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  String uuidString = UUID.randomUUID().toString();
  Whitebox.setInternalState(validSpan, "cachedJsonRepresentation", uuidString);
  // when
  String beforeCompleteJson = validSpan.toJSON();
  completeSpan(validSpan);
  // then
  String afterCompleteJson = validSpan.toJSON();
  assertThat(afterCompleteJson).isNotEqualTo(beforeCompleteJson);
  assertThat(afterCompleteJson).isNotEqualTo(uuidString);
  Map<String, Object> spanValuesFromJackson = objectMapper.readValue(afterCompleteJson, new TypeReference<Map<String, Object>>() { });
  verifySpanEqualsDeserializedValues(validSpan, spanValuesFromJackson);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void startRequestWithChildSpan_wipes_out_any_existing_spans_on_the_stack() {
  // given: Tracer already has some Spans on the stack, and we have a parent span we're going to use
  Tracer.getInstance().startRequestWithRootSpan("span1");
  Tracer.getInstance().startSubSpan("span2", SpanPurpose.LOCAL_ONLY);
  assertThat(getSpanStackSize()).isEqualTo(2);
  Span newSpanParent = Span.generateRootSpanForNewTrace("parentspan", SpanPurpose.CLIENT).build();
  // when: Tracer.startRequestWithChildSpan(Span, String) is called to start a span with a parent
  Tracer.getInstance().startRequestWithChildSpan(newSpanParent, "childspan");
  // then: a new span is started that has the given parent, and the other spans on the stack are removed
  assertThat(getSpanStackSize()).isEqualTo(1);
  Span span = Tracer.getInstance().getCurrentSpan();
  assertThat(span).isNotNull();
  assertThat(span.getSpanName()).isEqualTo("childspan");
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void fromKeyValueString_should_function_properly_for_completed_spans() {
  // given: valid span that has been completed, and key/value string from Span.fromKeyValueString()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  completeSpan(validSpan);
  assertThat(validSpan.isCompleted()).isTrue();
  String keyValStr = SpanParser.convertSpanToKeyValueFormat(validSpan);
  // when: fromKeyValueString is called
  Span spanFromKeyValStr = SpanParser.fromKeyValueString(keyValStr);
  // then: the original span and the fromKeyValueString() span values should be exactly the same
  verifySpanDeepEquals(spanFromKeyValStr, validSpan, true);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void fromJson_should_function_properly_for_completed_spans() {
  // given: valid span that has been completed, and JSON string from SpanParser.convertSpanToJSON()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  completeSpan(validSpan);
  assertThat(validSpan.isCompleted()).isTrue();
  String json = SpanParser.convertSpanToJSON(validSpan);
  // when: fromJson is called
  Span spanFromJson = SpanParser.fromJSON(json);
  // then: the original span and the fromJson() span values should be exactly the same
  verifySpanDeepEquals(spanFromJson, validSpan, true);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void convertSpanToKeyValueFormat_should_function_properly_for_completed_spans() {
  // given: valid span and completed, and key/value string from SpanParser.convertSpanToKeyValueFormat()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  completeSpan(validSpan);
  assertThat(validSpan.isCompleted()).isTrue();
  String keyValueStr = SpanParser.convertSpanToKeyValueFormat(validSpan);
  // when: the string is deserialized into a map
  Map<String, Object> deserializedValues = deserializeKeyValueSpanString(keyValueStr);
  // then: the original span and deserialized map values should be exactly the same
  verifySpanEqualsDeserializedValues(validSpan, deserializedValues);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void getDuration_should_be_null_until_span_is_completed() {
  // given
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  assertThat(validSpan.getDurationNanos()).isNull();
  // when
  validSpan.complete();
  // then
  assertThat(validSpan.getDurationNanos()).isNotNull();
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void convertSpanToJSON_should_function_properly_when_there_are_null_values() throws IOException {
  // given: valid span with null values and JSON string from SpanParser.convertSpanToJSON()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, null).build();
  assertThat(validSpan.getParentSpanId()).isNull();
  assertThat(validSpan.getUserId()).isNull();
  assertThat(validSpan.getDurationNanos()).isNull();
  String json = SpanParser.convertSpanToJSON(validSpan);
  // when: jackson is used to deserialize that JSON
  Map<String, Object> spanValuesFromJackson = objectMapper.readValue(json, new TypeReference<Map<String, Object>>() {});
  // then: the original span context and jackson's span context values should be exactly the same
  verifySpanEqualsDeserializedValues(validSpan, spanValuesFromJackson);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void complete_should_reset_cached_key_value_string() {
  // given
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, spanPurpose).build();
  String uuidString = UUID.randomUUID().toString();
  Whitebox.setInternalState(validSpan, "cachedKeyValueRepresentation", uuidString);
  // when
  String beforeCompleteKeyValueString = validSpan.toKeyValueString();
  completeSpan(validSpan);
  // then
  String afterCompleteKeyValueString = validSpan.toKeyValueString();
  assertThat(afterCompleteKeyValueString).isNotEqualTo(beforeCompleteKeyValueString);
  assertThat(afterCompleteKeyValueString).isNotEqualTo(uuidString);
  Map<String, Object> deserializedValues = deserializeKeyValueSpanString(afterCompleteKeyValueString);
  verifySpanEqualsDeserializedValues(validSpan, deserializedValues);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void fromJson_should_function_properly_when_there_are_null_values() {
  // given: valid span with null values and JSON string from SpanParser.convertSpanToJSON()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, null).build();
  assertThat(validSpan.getParentSpanId()).isNull();
  assertThat(validSpan.getUserId()).isNull();
  assertThat(validSpan.getDurationNanos()).isNull();
  String json = SpanParser.convertSpanToJSON(validSpan);
  // when: fromJson is called
  Span spanFromJson = SpanParser.fromJSON(json);
  // then: the original span and the fromJson() span values should be exactly the same
  verifySpanDeepEquals(spanFromJson, validSpan, true);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void convertSpanToKeyValueFormat_should_function_properly_when_there_are_null_values() {
  // given: valid span with null values and key/value string from SpanParser.convertSpanToKeyValueFormat()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, null).build();
  assertThat(validSpan.getParentSpanId()).isNull();
  assertThat(validSpan.getUserId()).isNull();
  assertThat(validSpan.getDurationNanos()).isNull();
  String keyValueStr = SpanParser.convertSpanToKeyValueFormat(validSpan);
  // when: the string is deserialized into a map
  Map<String, Object> deserializedValues = deserializeKeyValueSpanString(keyValueStr);
  // then: the original span and deserialized map values should be exactly the same
  verifySpanEqualsDeserializedValues(validSpan, deserializedValues);
}

代码示例来源:origin: Nike-Inc/wingtips

@Test
public void fromKeyValueString_should_function_properly_when_there_are_null_values() {
  // given: valid span with null values and key/value string from Span.fromKeyValueString()
  Span validSpan = Span.generateRootSpanForNewTrace(spanName, null).build();
  assertThat(validSpan.getParentSpanId()).isNull();
  assertThat(validSpan.getUserId()).isNull();
  assertThat(validSpan.getDurationNanos()).isNull();
  String keyValStr = SpanParser.convertSpanToKeyValueFormat(validSpan);
  // when: fromKeyValueString is called
  Span spanFromKeyValStr = SpanParser.fromKeyValueString(keyValStr);
  // then: the original span and the fromKeyValueString() span values should be exactly the same
  verifySpanDeepEquals(spanFromKeyValStr, validSpan, true);
}

相关文章