use of brave.test.util.AssertableCallback in project brave by openzipkin.
the class BaseITTracingClientInterceptor method callbackContextIsFromInvocationTime.
/**
* This ensures that response callbacks run in the invocation context, not the client one. This
* allows async chaining to appear caused by the parent, not by the most recent client. Otherwise,
* we would see a client span child of a client span, which could be confused with duplicate
* instrumentation and affect dependency link counts.
*/
@Test
public void callbackContextIsFromInvocationTime() {
AssertableCallback<HelloReply> callback = new AssertableCallback<>();
// Capture the current trace context when onSuccess or onError occur
AtomicReference<TraceContext> invocationContext = new AtomicReference<>();
callback.setListener(() -> invocationContext.set(currentTraceContext.get()));
TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
try (Scope scope = currentTraceContext.newScope(parent)) {
GreeterGrpc.newStub(client).sayHello(HELLO_REQUEST, new StreamObserverAdapter(callback));
}
// ensures listener ran
callback.join();
assertThat(invocationContext.get()).isSameAs(parent);
assertChildOf(testSpanHandler.takeRemoteSpan(CLIENT), parent);
}
use of brave.test.util.AssertableCallback in project brave by openzipkin.
the class ITHttpAsyncClient method callbackContextIsFromInvocationTime.
/**
* This ensures that response callbacks run in the invocation context, not the client one. This
* allows async chaining to appear caused by the parent, not by the most recent client. Otherwise,
* we would see a client span child of a client span, which could be confused with duplicate
* instrumentation and affect dependency link counts.
*/
@Test
public void callbackContextIsFromInvocationTime() {
server.enqueue(new MockResponse());
AssertableCallback<Integer> callback = new AssertableCallback<>();
// Capture the current trace context when onSuccess or onError occur
AtomicReference<TraceContext> invocationContext = new AtomicReference<>();
callback.setListener(() -> invocationContext.set(currentTraceContext.get()));
TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
try (Scope scope = currentTraceContext.newScope(parent)) {
get(client, "/foo", callback);
}
// ensures listener ran
callback.join();
assertThat(invocationContext.get()).isSameAs(parent);
assertChildOf(testSpanHandler.takeRemoteSpan(CLIENT), parent);
}
use of brave.test.util.AssertableCallback in project brave by openzipkin.
the class ITHttpAsyncClient method usesParentFromInvocationTime.
/**
* This tests that the parent is determined at the time the request was made, not when the request
* was executed.
*/
@Test
public void usesParentFromInvocationTime() {
server.enqueue(new MockResponse().setBodyDelay(300, TimeUnit.MILLISECONDS));
server.enqueue(new MockResponse());
AssertableCallback<Integer> items1 = new AssertableCallback<>();
AssertableCallback<Integer> items2 = new AssertableCallback<>();
TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
try (Scope scope = currentTraceContext.newScope(parent)) {
get(client, "/items/1", items1);
get(client, "/items/2", items2);
}
try (Scope scope = currentTraceContext.newScope(null)) {
// complete within a different scope
items1.join();
items2.join();
for (int i = 0; i < 2; i++) {
TraceContext extracted = extract(takeRequest());
assertChildOf(extracted, parent);
}
}
// The spans may report in a different order than the requests
for (int i = 0; i < 2; i++) {
assertChildOf(testSpanHandler.takeRemoteSpan(CLIENT), parent);
}
}
use of brave.test.util.AssertableCallback in project brave by openzipkin.
the class ITHttpAsyncClient method callbackContextIsFromInvocationTime_root.
/**
* This ensures that response callbacks run when there is no invocation trace context.
*/
@Test
public void callbackContextIsFromInvocationTime_root() {
server.enqueue(new MockResponse());
AssertableCallback<Integer> callback = new AssertableCallback<>();
// Capture the current trace context when onSuccess or onError occur
AtomicReference<TraceContext> invocationContext = new AtomicReference<>();
callback.setListener(() -> invocationContext.set(currentTraceContext.get()));
get(client, "/foo", callback);
// ensures listener ran
callback.join();
assertThat(invocationContext.get()).isNull();
assertThat(testSpanHandler.takeRemoteSpan(CLIENT).parentId()).isNull();
}
use of brave.test.util.AssertableCallback in project brave by openzipkin.
the class ITTracingFilter_Consumer method usesParentFromInvocationTime.
/**
* This tests that the parent is determined at the time the request was made, not when the request
* was executed.
*/
@Test
public void usesParentFromInvocationTime() {
AssertableCallback<String> items1 = new AssertableCallback<>();
AssertableCallback<String> items2 = new AssertableCallback<>();
TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
try (Scope scope = currentTraceContext.newScope(parent)) {
RpcContext.getContext().asyncCall(() -> client.get().sayHello("jorge")).whenComplete(items1);
RpcContext.getContext().asyncCall(() -> client.get().sayHello("romeo")).whenComplete(items2);
}
try (Scope scope = currentTraceContext.newScope(null)) {
// complete within a different scope
items1.join();
items2.join();
for (int i = 0; i < 2; i++) {
TraceContext extracted = server.takeRequest().context();
assertChildOf(extracted, parent);
}
}
// The spans may report in a different order than the requests
for (int i = 0; i < 2; i++) {
assertChildOf(testSpanHandler.takeRemoteSpan(CLIENT), parent);
}
}
Aggregations