TraceAsyncListenableTaskExecutor implements AsyncListenableTaskExecutor { @Override public Future<?> submit(Runnable task) { return this.delegate.submit(this.tracing.currentTraceContext().wrap(task)); } TraceAsyncListenableTaskExecutor(AsyncListenableTaskExecutor delegate, Tracing tracing); @Override ListenableFuture<?> submitListenable(Runnable task); @Override ListenableFuture<T> submitListenable(Callable<T> task); @Override void execute(Runnable task, long startTimeout); @Override Future<?> submit(Runnable task); @Override Future<T> submit(Callable<T> task); @Override void execute(Runnable task);  }
@Test public void should_submit_trace_callable() throws Exception { Span span = this.tracer.nextSpan().name("foo"); Span spanFromListenable; try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) { spanFromListenable = this.traceAsyncListenableTaskExecutor.submit(aCallable(this.tracing)).get(); } finally { span.finish(); } BDDAssertions.then(spanFromListenable).isNotNull(); }
@Test public void should_submit_trace_runnable() throws Exception { AtomicBoolean executed = new AtomicBoolean(); Span span = this.tracer.nextSpan().name("foo"); try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) { this.traceAsyncListenableTaskExecutor.submit(aRunnable(this.tracing, executed)).get(); } finally { span.finish(); } Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> { BDDAssertions.then(executed.get()).isTrue(); }); }