// Path: instrument-starters/opentracing-spring-cloud-core/src/main/java/io/opentracing/contrib/spring/cloud/ExtensionTags.java
// public class ExtensionTags {
// 
//   private ExtensionTags() {
//   }
// 
//   /**
//    * Tag for {@link Class#getSimpleName()}
//    */
//   public static final StringTag CLASS_TAG = new StringTag("class");
// 
//   /**
//    * Tag for method name
//    */
//   public static final StringTag METHOD_TAG = new StringTag("method");
// }
// 
// Path: instrument-starters/opentracing-spring-cloud-core/src/test/java/io/opentracing/contrib/spring/cloud/MockTracingConfiguration.java
// @Configuration
// @EnableAutoConfiguration
// public class MockTracingConfiguration {
// 
//   @Bean
//   public MockTracer mockTracer() {
//     GlobalTracerTestUtil.resetGlobalTracer();
//     return new MockTracer();
//   }
// 
//   @Bean
//   public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
//     return restTemplateBuilder.build();
//   }
// 
//   @Bean
//   public AsyncRestTemplate asyncRestTemplate() {
//     return new AsyncRestTemplate();
//   }
// 
//   public static TestRestTemplate createNotTracedRestTemplate(int port) {
//     return new TestRestTemplate(new RestTemplateBuilder().rootUri("http://localhost:" + port));
//   }
// }
// 
// Path: instrument-starters/opentracing-spring-cloud-core/src/test/java/io/opentracing/contrib/spring/cloud/TestUtils.java
// public class TestUtils {
// 
//   /**
//    * Check if all spans have same traceId.
//    *
//    * @param spans the spans to check
//    */
//   public static void assertSameTraceId(Collection<MockSpan> spans) {
//     if (!spans.isEmpty()) {
//       final long traceId = spans.iterator().next().context().traceId();
//       for (MockSpan span : spans) {
//         Assert.assertEquals(traceId, span.context().traceId());
//       }
//     }
//   }
// }
// 
// Path: instrument-starters/opentracing-spring-cloud-core/src/test/java/io/opentracing/contrib/spring/cloud/scheduled/ScheduledTest.java
// @EnableScheduling
// static class Configuration {
// 
// }
// 
// Path: instrument-starters/opentracing-spring-cloud-core/src/test/java/io/opentracing/contrib/spring/cloud/scheduled/ScheduledTest.java
// @Component
// @EnableScheduling
// static class ScheduledComponent {
// 
//   @Autowired
//   private Tracer tracer;
//   @Autowired
//   private ScheduledAnnotationBeanPostProcessor scheduledAnnotationBeanPostProcessor;
//   @Autowired
//   private BeanFactory beanFactory;
// 
//   @Scheduled(fixedDelay = 1)
//   public void scheduledFoo() {
//     // disable upcoming scheduling
//     scheduledAnnotationBeanPostProcessor
//         .postProcessBeforeDestruction(beanFactory.getBean(ScheduledComponent.class), null);
//     tracer.buildSpan("child").start().finish();
//   }
// }


import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import io.opentracing.Tracer;
import io.opentracing.contrib.spring.cloud.ExtensionTags;
import io.opentracing.contrib.spring.cloud.MockTracingConfiguration;
import io.opentracing.contrib.spring.cloud.TestUtils;
import io.opentracing.contrib.spring.cloud.scheduled.ScheduledTest.Configuration;
import io.opentracing.contrib.spring.cloud.scheduled.ScheduledTest.ScheduledComponent;
import io.opentracing.mock.MockSpan;
import io.opentracing.mock.MockTracer;
import io.opentracing.tag.Tags;
import java.util.List;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor;
import org.springframework.stereotype.Component;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    private Tracer tracer;
    @Autowired
    private ScheduledAnnotationBeanPostProcessor scheduledAnnotationBeanPostProcessor;
    @Autowired
    private BeanFactory beanFactory;

    @Scheduled(fixedDelay = 1)
    public void scheduledFoo() {
      // disable upcoming scheduling
      scheduledAnnotationBeanPostProcessor
          .postProcessBeforeDestruction(beanFactory.getBean(ScheduledComponent.class), null);
      tracer.buildSpan("child").start().finish();
    }
  }

  @Autowired
  private MockTracer tracer;

  @After
  public void after() {
    tracer.reset();
  }

  @Test
  public void testScheduled() throws InterruptedException {
    await().until(() -> tracer.finishedSpans().size() == 2);
    // 1. span created for @Scheduled
    // 2. span created inside scheduled method
    List<MockSpan> mockSpans = tracer.finishedSpans();
    assertEquals(2, mockSpans.size());
// Path: instrument-starters/opentracing-spring-cloud-core/src/main/java/io/opentracing/contrib/spring/cloud/ExtensionTags.java
// public class ExtensionTags {
// 
//   private ExtensionTags() {
//   }
// 
//   /**
//    * Tag for {@link Class#getSimpleName()}
//    */
//   public static final StringTag CLASS_TAG = new StringTag("class");
// 
//   /**
//    * Tag for method name
//    */
//   public static final StringTag METHOD_TAG = new StringTag("method");
// }
// 
// Path: instrument-starters/opentracing-spring-cloud-core/src/test/java/io/opentracing/contrib/spring/cloud/MockTracingConfiguration.java
// @Configuration
// @EnableAutoConfiguration
// public class MockTracingConfiguration {
// 
//   @Bean
//   public MockTracer mockTracer() {
//     GlobalTracerTestUtil.resetGlobalTracer();
//     return new MockTracer();
//   }
// 
//   @Bean
//   public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
//     return restTemplateBuilder.build();
//   }
// 
//   @Bean
//   public AsyncRestTemplate asyncRestTemplate() {
//     return new AsyncRestTemplate();
//   }
// 
//   public static TestRestTemplate createNotTracedRestTemplate(int port) {
//     return new TestRestTemplate(new RestTemplateBuilder().rootUri("http://localhost:" + port));
//   }
// }
// 
// Path: instrument-starters/opentracing-spring-cloud-core/src/test/java/io/opentracing/contrib/spring/cloud/TestUtils.java
// public class TestUtils {
// 
//   /**
//    * Check if all spans have same traceId.
//    *
//    * @param spans the spans to check
//    */
//   public static void assertSameTraceId(Collection<MockSpan> spans) {
//     if (!spans.isEmpty()) {
//       final long traceId = spans.iterator().next().context().traceId();
//       for (MockSpan span : spans) {
//         Assert.assertEquals(traceId, span.context().traceId());
//       }
//     }
//   }
// }
// 
// Path: instrument-starters/opentracing-spring-cloud-core/src/test/java/io/opentracing/contrib/spring/cloud/scheduled/ScheduledTest.java
// @EnableScheduling
// static class Configuration {
// 
// }
// 
// Path: instrument-starters/opentracing-spring-cloud-core/src/test/java/io/opentracing/contrib/spring/cloud/scheduled/ScheduledTest.java
// @Component
// @EnableScheduling
// static class ScheduledComponent {
// 
//   @Autowired
//   private Tracer tracer;
//   @Autowired
//   private ScheduledAnnotationBeanPostProcessor scheduledAnnotationBeanPostProcessor;
//   @Autowired
//   private BeanFactory beanFactory;
// 
//   @Scheduled(fixedDelay = 1)
//   public void scheduledFoo() {
//     // disable upcoming scheduling
//     scheduledAnnotationBeanPostProcessor
//         .postProcessBeforeDestruction(beanFactory.getBean(ScheduledComponent.class), null);
//     tracer.buildSpan("child").start().finish();
//   }
// }


// Path: instrument-starters/opentracing-spring-cloud-core/src/test/java/io/opentracing/contrib/spring/cloud/scheduled/ScheduledTest.java
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import io.opentracing.Tracer;
import io.opentracing.contrib.spring.cloud.ExtensionTags;
import io.opentracing.contrib.spring.cloud.MockTracingConfiguration;
import io.opentracing.contrib.spring.cloud.TestUtils;
import io.opentracing.contrib.spring.cloud.scheduled.ScheduledTest.Configuration;
import io.opentracing.contrib.spring.cloud.scheduled.ScheduledTest.ScheduledComponent;
import io.opentracing.mock.MockSpan;
import io.opentracing.mock.MockTracer;
import io.opentracing.tag.Tags;
import java.util.List;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor;
import org.springframework.stereotype.Component;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

    private Tracer tracer;
    @Autowired
    private ScheduledAnnotationBeanPostProcessor scheduledAnnotationBeanPostProcessor;
    @Autowired
    private BeanFactory beanFactory;

    @Scheduled(fixedDelay = 1)
    public void scheduledFoo() {
      // disable upcoming scheduling
      scheduledAnnotationBeanPostProcessor
          .postProcessBeforeDestruction(beanFactory.getBean(ScheduledComponent.class), null);
      tracer.buildSpan("child").start().finish();
    }
  }

  @Autowired
  private MockTracer tracer;

  @After
  public void after() {
    tracer.reset();
  }

  @Test
  public void testScheduled() throws InterruptedException {
    await().until(() -> tracer.finishedSpans().size() == 2);
    // 1. span created for @Scheduled
    // 2. span created inside scheduled method
    List<MockSpan> mockSpans = tracer.finishedSpans();
    assertEquals(2, mockSpans.size());
    TestUtils.assertSameTraceId(mockSpans);