use of org.assertj.core.api.BDDAssertions.then in project spring-cloud-sleuth by spring-cloud.
the class SpringCloudSleuthDocTests method should_start_a_span_with_explicit_parent.
@Test
public void should_start_a_span_with_explicit_parent() throws Exception {
ExecutorService executorService = Executors.newSingleThreadExecutor();
String commissionValue = "10";
Span initialSpan = this.tracer.nextSpan().name("calculateTax").start();
executorService.submit(() -> {
// tag::manual_span_joining[]
// let's assume that we're in a thread Y and we've received
// the `initialSpan` from thread X. `initialSpan` will be the parent
// of the `newSpan`
Span newSpan = null;
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(initialSpan)) {
newSpan = this.tracer.nextSpan().name("calculateCommission");
// ...
// You can tag a span
newSpan.tag("commissionValue", commissionValue);
// ...
// You can log an event on a span
newSpan.annotate("commissionCalculated");
} finally {
// newSpan will not be present on the parent
if (newSpan != null) {
newSpan.finish();
}
}
// end::manual_span_joining[]
}).get();
List<zipkin2.Span> spans = this.reporter.getSpans();
Optional<zipkin2.Span> calculateTax = spans.stream().filter(span -> span.name().equals("calculatecommission")).findFirst();
BDDAssertions.then(calculateTax).isPresent();
BDDAssertions.then(calculateTax.get().tags()).containsEntry("commissionValue", "10");
BDDAssertions.then(calculateTax.get().annotations()).hasSize(1);
executorService.shutdown();
}
Aggregations