use of brave.propagation.CurrentTraceContext in project brave by openzipkin.
the class CurrentTraceContextTest method is_inheritable.
protected void is_inheritable(CurrentTraceContext inheritableCurrentTraceContext) throws Exception {
// use a single-threaded version of newCachedThreadPool
ExecutorService service = new ThreadPoolExecutor(0, 1, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
// submitting a job grows the pool, attaching the context to its thread
try (CurrentTraceContext.Scope scope = inheritableCurrentTraceContext.newScope(context)) {
assertThat(service.submit(() -> inheritableCurrentTraceContext.get()).get()).isEqualTo(context);
}
// same thread executes the next job and still has the same context (leaked and not cleaned up)
assertThat(service.submit(() -> inheritableCurrentTraceContext.get()).get()).isEqualTo(context);
service.shutdownNow();
}
Aggregations