Skip to content

Commit

Permalink
chore: test to prove #1306 (#1336)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Adrian Cole <adrian@tetrate.io>
  • Loading branch information
jcchavezs and Adrian Cole committed Dec 15, 2023
1 parent 6d21ce5 commit 5e15c20
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 The OpenZipkin Authors
* Copyright 2013-2023 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down
2 changes: 1 addition & 1 deletion brave/src/main/java/brave/handler/SpanHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 The OpenZipkin Authors
* Copyright 2013-2023 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down
22 changes: 21 additions & 1 deletion brave/src/test/java/brave/TracerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 The OpenZipkin Authors
* Copyright 2013-2022 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -37,9 +37,12 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;
import org.junit.After;
import org.junit.Test;
import org.mockito.Mockito;

import zipkin2.Endpoint;
import zipkin2.reporter.Reporter;

Expand Down Expand Up @@ -226,6 +229,7 @@ public class TracerTest {
@Test public void join_createsChildWhenUnsupportedByPropagation() {
tracer = Tracing.newBuilder()
.propagationFactory(new Propagation.Factory() {
@Override
@Deprecated public <K> Propagation<K> create(Propagation.KeyFactory<K> keyFactory) {
return B3Propagation.FACTORY.create(keyFactory);
}
Expand Down Expand Up @@ -1092,6 +1096,22 @@ private static void simulateInProcessPropagation(Tracer tracer1, Tracer tracer2)
assertThat(toSpan.extra()).isNotEmpty();
}

@Test public void toSpan_flushedAfterFetch() throws InterruptedException, ExecutionException {
propagationFactory = baggageFactory;
TraceContext parent = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(true).build();
TraceContext incoming = TraceContext.newBuilder().traceId(1L).spanId(3L).parentId(2L).sampled(true).build();

tracer.pendingSpans.getOrCreate(parent, incoming, false);
Tracer spiedTracer = Mockito.spy(tracer);
Mockito.doAnswer(i -> {
//Simulate a concurrent call flushing the span at the beginning of this method's execution
tracer.pendingSpans.flush(incoming);
return i.callRealMethod();
}).when(spiedTracer)._toSpan(Mockito.any(TraceContext.class), Mockito.any(TraceContext.class));

spiedTracer.toSpan(incoming);
}

@Test public void currentSpan_sameContextReference() {
Span span = tracer.newTrace();
try (SpanInScope ws = tracer.withSpanInScope(span)) {
Expand Down

0 comments on commit 5e15c20

Please sign in to comment.