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

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

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

Span.isCompleted介绍

暂无

代码示例

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

@Test
public void completeRequestSpan_does_nothing_if_listener_is_already_marked_completed() {
  // given
  implSpy.alreadyCompleted.set(true);
  assertThat(tracingStateSpan.isCompleted()).isFalse();
  // when
  implSpy.completeRequestSpan(asyncEventMock);
  // then
  assertThat(tracingStateSpan.isCompleted()).isFalse();
  assertThat(implSpy.alreadyCompleted.get()).isTrue();
}

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

@Test
public void doFilterInternal_should_not_call_setupTracingCompletionWhenAsyncRequestCompletes_when_isAsyncRequest_returns_false(
) throws ServletException, IOException {
  // given
  RequestTracingFilter filterSpy = spy(getBasicFilter());
  doReturn(false).when(filterSpy).isAsyncRequest(any(HttpServletRequest.class));
  // when
  filterSpy.doFilterInternal(requestMock, responseMock, spanCapturingFilterChain);
  // then
  assertThat(spanCapturingFilterChain.capturedSpan).isNotNull();
  assertThat(spanCapturingFilterChain.capturedSpan.isCompleted()).isTrue();
  verify(filterSpy, never()).setupTracingCompletionWhenAsyncRequestCompletes(
    any(HttpServletRequest.class), any(HttpServletResponse.class), any(TracingState.class),
    any(HttpTagAndSpanNamingStrategy.class), any(HttpTagAndSpanNamingAdapter.class)
  );
}

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

private Span setupTracingForChannelInactive(boolean traceCompletedOrScheduled) {
  state.setTraceCompletedOrScheduled(traceCompletedOrScheduled);
  Span span = Span.newBuilder("fooSpan", Span.SpanPurpose.SERVER).build();
  Assertions.assertThat(span.isCompleted()).isFalse();
  Deque<Span> spanStack = new LinkedList<>();
  spanStack.add(span);
  state.setDistributedTraceStack(spanStack);
  return span;
}

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

@Test
public void fromHttpServletRequestOrCreateRootSpan_returns_new_root_span_if_traceId_is_missing_from_headers() {
  // given: no trace ID in headers, but user ID exists
  given(request.getHeader(ALT_USER_ID_HEADER_KEY)).willReturn(altUserId);
  // when: creating Span object from HTTP request using fromHttpServletRequestOrCreateRootSpan
  long beforeCallNanos = System.nanoTime();
  Span newSpan = HttpSpanFactory.fromHttpServletRequestOrCreateRootSpan(request, USER_ID_HEADER_KEYS);
  long afterCallNanos = System.nanoTime();
  // then: ensure root span object is created even though there was no trace ID header, and the returned span contains the expected user ID
  assertThat(newSpan).isNotNull();
  assertThat(newSpan.getParentSpanId()).isNull();
  assertThat(newSpan.getUserId()).isEqualTo(altUserId);
  assertThat(newSpan.getSpanStartTimeNanos()).isBetween(beforeCallNanos, afterCallNanos);
  assertThat(newSpan.isCompleted()).isFalse();
  assertThat(newSpan.getSpanPurpose()).isEqualTo(SpanPurpose.SERVER);
}

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

@Test
public void close_completes_the_span_as_expected_overall_request_span() {
  // given
  Span overallSpan = Tracer.getInstance().startRequestWithRootSpan("root");
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(overallSpan);
  assertThat(overallSpan.isCompleted()).isFalse();
  // when
  overallSpan.close();
  // then
  assertThat(overallSpan.isCompleted()).isTrue();
  assertThat(Tracer.getInstance().getCurrentSpan()).isNull();
}

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

@Test
public void handleSpanCloseMethod_completes_the_span_as_expected_overall_request_span() {
  // given
  Span overallSpan = Tracer.getInstance().startRequestWithRootSpan("root");
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(overallSpan);
  assertThat(overallSpan.isCompleted()).isFalse();
  // when
  Tracer.getInstance().handleSpanCloseMethod(overallSpan);
  // then
  assertThat(overallSpan.isCompleted()).isTrue();
  assertThat(Tracer.getInstance().getCurrentSpan()).isNull();
}

代码示例来源: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
public void close_completes_the_span_as_expected_subspan() {
  // given
  Span parentSpan = Tracer.getInstance().startRequestWithRootSpan("root");
  Span subspan = Tracer.getInstance().startSubSpan("subspan", SpanPurpose.LOCAL_ONLY);
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(subspan);
  assertThat(subspan.isCompleted()).isFalse();
  // when
  subspan.close();
  // then
  assertThat(subspan.isCompleted()).isTrue();
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(parentSpan);
}

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

@Test
public void handleSpanCloseMethod_completes_the_span_as_expected_subspan() {
  // given
  Span parentSpan = Tracer.getInstance().startRequestWithRootSpan("root");
  Span subspan = Tracer.getInstance().startSubSpan("subspan", SpanPurpose.LOCAL_ONLY);
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(subspan);
  assertThat(subspan.isCompleted()).isFalse();
  // when
  Tracer.getInstance().handleSpanCloseMethod(subspan);
  // then
  assertThat(subspan.isCompleted()).isTrue();
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(parentSpan);
}

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

@Test
public void completeSubSpan_should_do_nothing_if_there_is_only_one_span_on_the_stack() {
  // given: a single span on the stack
  Tracer.getInstance().startRequestWithRootSpan("somespan");
  assertThat(Tracer.getInstance().getCurrentSpan()).isNotNull();
  assertThat(getSpanStackSize()).isEqualTo(1);
  Span span = Tracer.getInstance().getCurrentSpan();
  assertThat(span).isNotNull();
  assertThat(span.getSpanName()).isEqualTo("somespan");
  // when: completeSubSpan() is called
  Tracer.getInstance().completeSubSpan();
  // then: nothing should be done because the stack only has one thing on it and completeSubSpan() requires at least two spans
  assertThat(span.isCompleted()).isFalse();
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(span);
  assertThat(getSpanStackSize()).isEqualTo(1);
}

代码示例来源: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(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 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 handleSpanCloseMethod_does_nothing_if_span_is_already_completed() {
  // given
  Span rootSpan = Tracer.getInstance().startRequestWithRootSpan("root");
  Span subspan = Tracer.getInstance().startSubSpan("subspan", SpanPurpose.LOCAL_ONLY);
  Tracer.getInstance().completeSubSpan();
  assertThat(subspan.isCompleted()).isTrue();
  assertThat(rootSpan.isCompleted()).isFalse();
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(rootSpan);
  assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isEqualTo(singletonList(rootSpan));
  // when
  Tracer.getInstance().handleSpanCloseMethod(subspan);
  // then
  assertThat(rootSpan.isCompleted()).isFalse();
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(rootSpan);
  assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isEqualTo(singletonList(rootSpan));
}

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

@Test
public void close_does_nothing_if_span_is_already_completed() {
  // given
  Span rootSpan = Tracer.getInstance().startRequestWithRootSpan("root");
  Span subspan = Tracer.getInstance().startSubSpan("subspan", SpanPurpose.LOCAL_ONLY);
  Tracer.getInstance().completeSubSpan();
  assertThat(subspan.isCompleted()).isTrue();
  assertThat(rootSpan.isCompleted()).isFalse();
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(rootSpan);
  assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isEqualTo(singletonList(rootSpan));
  // when
  subspan.close();
  // then
  assertThat(rootSpan.isCompleted()).isFalse();
  assertThat(Tracer.getInstance().getCurrentSpan()).isSameAs(rootSpan);
  assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isEqualTo(singletonList(rootSpan));
}

代码示例来源: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 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);
}

相关文章