TraceAsyncListenableTaskExecutor implements AsyncListenableTaskExecutor { @Override public void execute(Runnable task, long startTimeout) { this.delegate.execute(this.tracing.currentTraceContext().wrap(task), startTimeout); } 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_execute_a_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.execute(aRunnable(this.tracing, executed)); } finally { span.finish(); } Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> { BDDAssertions.then(executed.get()).isTrue(); }); }
@Test public void should_execute_with_timeout_a_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.execute(aRunnable(this.tracing, executed), 1L); } finally { span.finish(); } Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> { BDDAssertions.then(executed.get()).isTrue(); }); }