TraceableScheduledExecutorService extends TraceableExecutorService implements ScheduledExecutorService { @Override public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) { return getScheduledExecutorService().scheduleAtFixedRate( ContextUtil.isContextUnusable(this.beanFactory) ? command : new TraceRunnable(tracing(), spanNamer(), command, this.spanName), initialDelay, period, unit); } TraceableScheduledExecutorService(BeanFactory beanFactory, final ExecutorService delegate);  TraceableScheduledExecutorService(BeanFactory beanFactory, final ExecutorService delegate, String beanName); @Override ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit); @Override ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit); @Override ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit); @Override ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit);  }
@Test public void should_schedule_at_fixed_rate_a_trace_runnable() throws Exception { this.traceableScheduledExecutorService.scheduleAtFixedRate(aRunnable(), 1L, 1L, TimeUnit.DAYS); then(this.scheduledExecutorService).should().scheduleAtFixedRate( BDDMockito.argThat(matcher(Runnable.class, instanceOf(TraceRunnable.class))), anyLong(), anyLong(), any(TimeUnit.class)); }
@Test public void should_not_schedule_at_fixed_rate_a_trace_runnable_when_context_not_ready() throws Exception { SleuthContextListenerAccessor.set(this.beanFactory, false); this.traceableScheduledExecutorService.scheduleAtFixedRate(aRunnable(), 1L, 1L, TimeUnit.DAYS); then(this.scheduledExecutorService).should(never()).scheduleAtFixedRate( BDDMockito.argThat(matcher(Runnable.class, instanceOf(TraceRunnable.class))), anyLong(), anyLong(), any(TimeUnit.class)); }