ScheduledExecutorServiceWithTracing extends ExecutorServiceWithTracing implements ScheduledExecutorService { @Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { return delegate.schedule(new RunnableWithTracing(command), delay, unit); } ScheduledExecutorServiceWithTracing(ScheduledExecutorService delegate); static ScheduledExecutorServiceWithTracing withTracing(ScheduledExecutorService delegate); @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 schedule_callable_passes_through_to_delegate_with_tracing_wrapper() { Callable<?> origTaskMock = mock(Callable.class); ScheduledFuture<?> expectedResultMock = mock(ScheduledFuture.class); doReturn(expectedResultMock).when(executorServiceMock).schedule(any(Callable.class), anyLong(), any(TimeUnit.class)); TracingState expectedTracingState = generateTracingStateOnCurrentThread(); Future<?> result = instance.schedule(origTaskMock, 10L, TimeUnit.SECONDS); assertThat(result).isSameAs(expectedResultMock); verify(executorServiceMock).schedule(callableCaptor.capture(), eq(10L), eq(TimeUnit.SECONDS)); Callable<?> actualTask = callableCaptor.getValue(); verifyCallableWithTracingWrapper(actualTask, origTaskMock, expectedTracingState); verifyNoMoreInteractions(executorServiceMock); }
@Test public void schedule_runnable_with_delay_passes_through_to_delegate_with_tracing_wrapper() { Runnable origTaskMock = mock(Runnable.class); ScheduledFuture<?> expectedResultMock = mock(ScheduledFuture.class); doReturn(expectedResultMock).when(executorServiceMock).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class)); TracingState expectedTracingState = generateTracingStateOnCurrentThread(); ScheduledFuture<?> result = instance.schedule(origTaskMock, 10L, TimeUnit.SECONDS); assertThat(result).isSameAs(expectedResultMock); verify(executorServiceMock).schedule(runnableCaptor.capture(), eq(10L), eq(TimeUnit.SECONDS)); Runnable actualTask = runnableCaptor.getValue(); verifyRunnableWithTracingWrapper(actualTask, origTaskMock, expectedTracingState); verifyNoMoreInteractions(executorServiceMock); }