Search in sources :

Example 1 with CurrentTraceContext

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();
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CurrentTraceContext(brave.propagation.CurrentTraceContext)

Aggregations

CurrentTraceContext (brave.propagation.CurrentTraceContext)1 ExecutorService (java.util.concurrent.ExecutorService)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1