Java Code Examples for io.opentracing.mock.MockTracer

The following examples show how to use io.opentracing.mock.MockTracer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public Archive<?> generateDeployment(final TestDeployment testDeployment,
                                     final Collection<ProtocolArchiveProcessor> processors) {

    final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "microprofile-opentracing.war")
                                            .merge(testDeployment.getApplicationArchive());

    // opentracing-api jar added by Geronimo Impl. Also added by TCK causes issues with same classes in different Classloaders
    final Map<ArchivePath, Node> content = webArchive.getContent(object -> object.get().matches(".*opentracing-api.*jar.*"));
    content.forEach((archivePath, node) -> webArchive.delete(archivePath));

    // TCK expects a MockTracer. Check org/eclipse/microprofile/opentracing/tck/application/TracerWebService.java:133
    webArchive.addAsLibrary(jarLocation(MockTracer.class));
    webArchive.addAsLibrary(jarLocation(ThreadLocalScopeManager.class));
    webArchive.addAsWebInfResource("META-INF/beans.xml");
    webArchive.addClass(MicroProfileOpenTracingTCKTracer.class);

    System.out.println(webArchive.toString(true));

    return super.generateDeployment(
            new TestDeployment(null, webArchive, testDeployment.getAuxiliaryArchives()), processors);
}
 
Example 2
Source Project: java-specialagent   Source File: Dubbo26AgentTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testErrorSpans(final MockTracer tracer) {
  GreeterServiceImpl.isThrowExecption = true;
  try {
    client.get().sayHello("jorge");
  }
  catch (final Exception e) {
    Assert.assertEquals(GreeterServiceImpl.errorMesg, e.getMessage());
  }

  final List<MockSpan> mockSpans = tracer.finishedSpans();
  Assert.assertEquals(2, mockSpans.size());
  Assert.assertEquals("GreeterService/sayHello", mockSpans.get(0).operationName());
  Assert.assertEquals("GreeterService/sayHello", mockSpans.get(1).operationName());
  Assert.assertEquals(true, mockSpans.get(0).tags().get(Tags.ERROR.getKey()));
  Assert.assertEquals(true, mockSpans.get(1).tags().get(Tags.ERROR.getKey()));
}
 
Example 3
Source Project: java-specialagent   Source File: SpringJmsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void before(final MockTracer tracer) throws Exception {
  tracer.reset();

  final HashSet<TransportConfiguration> transports = new HashSet<>();
  transports.add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));

  final ConfigurationImpl configuration = new ConfigurationImpl();
  configuration.setAcceptorConfigurations(transports);
  configuration.setSecurityEnabled(false);

  final File targetDir = new File(new File("").getAbsoluteFile(), "target");
  configuration.setBrokerInstance(targetDir);

  server = new ActiveMQServerImpl(configuration);
  server.start();
}
 
Example 4
Source Project: java-specialagent   Source File: RxJava3Test.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void consumerTest3WithError(final MockTracer tracer) {
  final Observable<Integer> observable = createSequentialObservable(tracer, true);
  final List<Integer> result = new ArrayList<>();
  final Consumer<Integer> onNext = consumer(result);
  final List<String> completeList = new ArrayList<>();
  final List<String> errorList = new ArrayList<>();
  observable.subscribe(onNext, onError(errorList), onComplete(completeList, tracer));

  assertEquals(0, result.size());
  assertEquals(0, completeList.size());
  assertEquals(1, errorList.size());

  final List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(1, spans.size());

  assertNull(tracer.scopeManager().active());
}
 
Example 5
Source Project: opentracing-toolbox   Source File: TagListenerTest.java    License: MIT License 6 votes vote down vote up
@Test
void multipleListenersAreChained() {
    final Tracer unit = new ProxyTracer(new MockTracer())
            .with(listener)
            .with(listener);

    final Tracer.SpanBuilder builder = unit.buildSpan("test")
            .withTag("k1", "v");

    final Span span = builder
            .start()
            .setTag("k2", "v");

    verify(listener, times(2)).onTag(eq(builder), tag("k1"), eq("v"));
    verify(listener, times(2)).onTag(eq(span), tag("k2"), eq("v"));
}
 
Example 6
Source Project: java-specialagent   Source File: ThreadTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNoRunnable(final MockTracer tracer) throws InterruptedException {
  final AtomicBoolean foundSpan = new AtomicBoolean(false);
  final Thread thread = new Thread() {
    @Override
    public void run() {
      foundSpan.set(tracer.activeSpan() != null);
    }
  };

  try (final Scope scope = tracer.buildSpan("parent").startActive(true)) {
    thread.start();
  }

  thread.join(10_000);
  assertTrue(foundSpan.get());
  assertEquals(1, tracer.finishedSpans().size());
  assertNull(GlobalTracer.get().activeSpan());
}
 
Example 7
Source Project: java-metrics   Source File: MetricsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithStartTimestamp() throws InterruptedException {
    MetricsReporter reporter = Mockito.mock(MetricsReporter.class);
    MockTracer tracer = new MockTracer();
    Tracer metricsTracer = Metrics.decorate(tracer, reporter);

    long start = System.currentTimeMillis() * 687;
    Thread.sleep(100);
    Scope parent = metricsTracer.buildSpan("parent")
            .withStartTimestamp(start)
            .startActive(true);

    parent.close();

    List<MockSpan> spans = tracer.finishedSpans();
    assertEquals(1, spans.size());
    MockSpan span = spans.get(0);
    long started = span.startMicros();
    assertEquals(start, started);
}
 
Example 8
Source Project: java-specialagent   Source File: AwsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAsyncClient(final MockTracer tracer) throws Exception {
  final AmazonDynamoDBAsync dbClient = buildAsyncClient();
  final Future<CreateTableResult> createTableResultFuture = createTableAsync(dbClient, "asyncRequest");
  try {
    final CreateTableResult result = createTableResultFuture.get(10, TimeUnit.SECONDS);
    // The following assertion is only relevant when a local instance of dynamodb is present.
    // If a local instance of dynamodb is NOT present, an exception is thrown.
    assertEquals("asyncRequest", result.getTableDescription().getTableName());
  }
  catch (final Exception e) {
    logger.log(Level.WARNING, e.getMessage());
  }

  final List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(1, spans.size());
  assertEquals("CreateTableRequest", spans.get(0).operationName());
}
 
Example 9
Source Project: java-specialagent   Source File: LettuceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPubSub(final MockTracer tracer) {
  final StatefulRedisPubSubConnection<String,String> connection = client.connectPubSub();
  connection.addListener(new RedisPubSubAdapter<>());

  final RedisPubSubCommands<String,String> commands = connection.sync();
  commands.subscribe("channel");

  final RedisCommands<String,String> commands2 = client.connect().sync();
  commands2.publish("channel", "msg");

  await().atMost(15, TimeUnit.SECONDS).until(TestUtil.reportedSpansSize(tracer), equalTo(4));

  client.shutdown();

  final List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(4, spans.size());
}
 
Example 10
Source Project: java-specialagent   Source File: RxJava2Test.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void consumerTest(final MockTracer tracer) {
  final Observable<Integer> observable = createSequentialObservable(tracer, false);
  final List<Integer> result = new ArrayList<>();
  final Consumer<Integer> onNext = consumer(result);

  final Disposable disposable = observable.subscribe(onNext);
  logger.fine(String.valueOf(disposable));

  assertEquals(5, result.size());

  final List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(1, spans.size());

  assertNull(tracer.scopeManager().active());
}
 
Example 11
Source Project: opentracing-toolbox   Source File: RenameTest.java    License: MIT License 6 votes vote down vote up
@ParameterizedTest
@MethodSource("data")
void renamesOperationName(
        final String source,
        final CaseFormat targetFormat,
        final String target) {

    final MockTracer tracer = new MockTracer();
    final Tracer unit = new ProxyTracer(tracer)
            .with(new Rename(targetFormat));

    unit.buildSpan(source)
            .start().finish();

    final MockSpan span = getOnlyElement(tracer.finishedSpans());
    assertEquals(target, span.operationName());
}
 
Example 12
@Before
public void beforeTest() throws Exception {
	mockTracer = Mockito.spy(new MockTracer(new ThreadLocalScopeManager(), MockTracer.Propagator.TEXT_MAP));

	ServletHandler servletHandler = new ServletHandler();
	servletHandler.addServletWithMapping(TestServlet.class, "/hello");

	servletHandler.addFilterWithMapping(new FilterHolder(tracingFilter()), "/*", EnumSet.of(DispatcherType.REQUEST,
			DispatcherType.FORWARD, DispatcherType.ASYNC, DispatcherType.ERROR, DispatcherType.INCLUDE));

	jettyServer = new Server(0);
	jettyServer.setHandler(servletHandler);
	jettyServer.start();
	serverPort = ((ServerConnector) jettyServer.getConnectors()[0]).getLocalPort();
}
 
Example 13
Source Project: java-specialagent   Source File: RabbitMQTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void before(final MockTracer tracer) throws IOException, TimeoutException {
  tracer.reset();
  final ConnectionFactory factory = new ConnectionFactory();
  factory.setUsername("guest");
  factory.setPassword("guest");
  factory.setHost("localhost");
  factory.setPort(embeddedAMQPBroker.getBrokerPort());
  connection = factory.newConnection();
  channel = connection.createChannel();
}
 
Example 14
Source Project: java-specialagent   Source File: RabbitMQTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void basicConsume(final MockTracer tracer) throws IOException, InterruptedException {
  final String exchangeName = "basicConsumeExchange";
  final String queueName = "basicConsumeQueue";
  final String routingKey = "#";

  channel.exchangeDeclare(exchangeName, "direct", true);
  channel.queueDeclare(queueName, true, false, false, null);
  channel.queueBind(queueName, exchangeName, routingKey);

  final byte[] messageBodyBytes = "Hello, world!".getBytes();
  channel.basicPublish(exchangeName, routingKey, null, messageBodyBytes);

  final CountDownLatch latch = new CountDownLatch(1);
  channel.basicConsume(queueName, false, new DefaultConsumer(channel) {
    @Override
    public void handleDelivery(final String consumerTag, final Envelope envelope, final AMQP.BasicProperties properties, final byte[] body) throws IOException {
      final long deliveryTag = envelope.getDeliveryTag();
      channel.basicAck(deliveryTag, false);
      latch.countDown();
    }
  });

  latch.await(15, TimeUnit.SECONDS);
  List<MockSpan> finishedSpans = tracer.finishedSpans();
  for (int tries = 10; tries > 0 && finishedSpans.size() < 2; --tries) {
    TimeUnit.SECONDS.sleep(1L);
    finishedSpans = tracer.finishedSpans();
  }

  assertEquals(2, finishedSpans.size());
  assertNull(tracer.activeSpan());
}
 
Example 15
@Test
public void test(final MockTracer tracer) {
  try (final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(KafkaConfiguration.class)) {
    final Sender sender = context.getBean(Sender.class);
    final Receiver receiver = context.getBean(Receiver.class);

    sender.send("Ping");

    await().atMost(5, SECONDS).until(new Callable<List<String>>() {
      @Override
      public List<String> call() throws Exception {
        return receiver.getReceivedMessages();
      }
    }, hasSize(1));
  }

  final List<MockSpan> finishedSpans = tracer.finishedSpans();
  assertThat(finishedSpans).hasSize(2);

  final MockSpan outputSpan = getSpanByOperation("send:output", tracer);
  assertThat(outputSpan.parentId()).isEqualTo(0);
  assertThat(outputSpan.tags()).hasSize(3);
  assertThat(outputSpan.tags()).containsEntry(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_PRODUCER);
  assertThat(outputSpan.tags()).containsEntry(Tags.COMPONENT.getKey(), "spring-messaging");
  assertThat(outputSpan.tags()).containsEntry(Tags.MESSAGE_BUS_DESTINATION.getKey(), "output");

  final MockSpan inputSpan = getSpanByOperation("receive:input", tracer);
  assertThat(inputSpan.parentId()).isEqualTo(outputSpan.context().spanId());
  assertThat(inputSpan.tags()).hasSize(3);
  assertThat(inputSpan.tags()).containsEntry(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER);
  assertThat(inputSpan.tags()).containsEntry(Tags.COMPONENT.getKey(), "spring-messaging");
  assertThat(inputSpan.tags()).containsEntry(Tags.MESSAGE_BUS_DESTINATION.getKey(), "input");

  assertThat(outputSpan.startMicros()).isLessThanOrEqualTo(inputSpan.startMicros());
}
 
Example 16
Source Project: java-specialagent   Source File: Cassandra4Test.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test(final MockTracer tracer) {
  try (final CqlSession session = createSession()) {
    createKeyspace(session);
  }

  assertEquals(1, tracer.finishedSpans().size());
}
 
Example 17
Source Project: java-specialagent   Source File: ExecutorServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@AgentRunner.TestConfig(verbose=false)
public void testInvokeAllSilent(final MockTracer tracer) throws InterruptedException {
  final CountDownLatch countDownLatch = new CountDownLatch(2);

  executorService.invokeAll(Arrays.asList(new TestCallable(tracer, countDownLatch), new TestCallable(tracer, countDownLatch)));

  countDownLatch.await();
  assertFalse(tracer.finishedSpans().isEmpty());
}
 
Example 18
Source Project: java-specialagent   Source File: KafkaTest.java    License: Apache License 2.0 5 votes vote down vote up
private static void createConsumer(final CountDownLatch latch, final Integer key, final MockTracer tracer) throws Exception {
  final Map<String,Object> consumerProps = KafkaTestUtils.consumerProps("sampleRawConsumer", "false", embeddedKafkaRule.getEmbeddedKafka());
  consumerProps.put("auto.offset.reset", "earliest");

  Executors.newSingleThreadExecutor().execute(new Runnable() {
    @Override
    public void run() {
      try (final KafkaConsumer<Integer,String> consumer = new KafkaConsumer<>(consumerProps)) {
        consumer.subscribe(Collections.singletonList("messages"));
        while (latch.getCount() > 0) {
          final ConsumerRecords<Integer,String> records = consumer.poll(100);
          for (final ConsumerRecord<Integer,String> record : records) {
            final SpanContext spanContext = TracingKafkaUtils.extractSpanContext(record.headers(), tracer);
            assertNotNull(spanContext);
            assertEquals("test", record.value());
            if (key != null)
              assertEquals(key, record.key());

            consumer.commitSync();
            latch.countDown();
          }
        }
      }
    }
  });

  assertTrue(latch.await(30, TimeUnit.SECONDS));
}
 
Example 19
Source Project: java-grpc   Source File: GrpcTagsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPeerAddressSocket() {
  final InetSocketAddress address =
      new InetSocketAddress("127.0.0.1", ThreadLocalRandom.current().nextInt(65535));
  final Attributes attributes =
      Attributes.newBuilder().set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, address).build();
  MockSpan span = new MockTracer().buildSpan("").start();
  GrpcTags.PEER_ADDRESS.set(span, attributes);
  assertThat(span.tags())
      .containsOnly(
          MapEntry.entry(
              GrpcTags.PEER_ADDRESS.getKey(), address.getHostString() + ':' + address.getPort()));
}
 
Example 20
Source Project: java-specialagent   Source File: CXFITest.java    License: Apache License 2.0 5 votes vote down vote up
private static void checkTag() {
  final Tracer tracer = TestUtil.getGlobalTracer();
  final MockTracer mockTracer = (MockTracer)tracer;
  final List<MockSpan> spans = mockTracer.finishedSpans();
  for (final MockSpan span : spans)
    if (!AbstractSpanTagInterceptor.SPAN_TAG_VALUE.equals(span.tags().get(AbstractSpanTagInterceptor.SPAN_TAG_KEY)))
      throw new AssertionError("no costomized tag");
}
 
Example 21
Source Project: java-specialagent   Source File: RxJava3Test.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void consumerTest4(final MockTracer tracer) {
  final Observable<Integer> observable = createSequentialObservable(tracer, false);
  final List<Integer> result = new ArrayList<>();
  final Consumer<Integer> onNext = consumer(result);
  final List<String> subscribeList = new ArrayList<>();
  final String subscribed = "subscribed";
  final Consumer<Object> onSubscribe = new Consumer<Object>() {
    @Override
    public void accept(final Object t) {
      subscribeList.add(subscribed);
    }
  };

  final List<String> completeList = new ArrayList<>();
  final List<String> errorList = new ArrayList<>();
  observable.doOnSubscribe(onSubscribe).subscribe(onNext, onError(errorList), onComplete(completeList, tracer));

  assertEquals(5, result.size());

  assertEquals(1, completeList.size());
  assertTrue(completeList.contains(COMPLETED));

  assertEquals(1, subscribeList.size());
  assertTrue(subscribeList.contains(subscribed));

  assertTrue(errorList.isEmpty());

  final List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(1, spans.size());

  assertNull(tracer.scopeManager().active());
}
 
Example 22
Source Project: java-specialagent   Source File: PulsarFunctionsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDeployedFunction(final MockTracer tracer) throws PulsarClientException {
  if (!isJdkSupported)
    return;

  producer.newMessage().value("my-message".getBytes()).send();
  consumer.receive(15, TimeUnit.SECONDS);

  final List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(1, spans.size());
  verify(tracer);
}
 
Example 23
Source Project: java-jfr-tracer   Source File: SpanBuilderWrapperTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void addReferenceOnParentSpanContextNull() {
    MockTracer delegateTracer = new MockTracer();
    TracerWrapper tracerWrapper = new TracerWrapper(delegateTracer);
    String operationName = "addReferenceOnParentSpanContextNull";
    SpanBuilderWrapper spanBuilderWrapper = new SpanBuilderWrapper(tracerWrapper, operationName,
            delegateTracer.buildSpan(operationName));

    SpanBuilder spanBuilder = spanBuilderWrapper.addReference(References.CHILD_OF, null);
    assertSame(spanBuilderWrapper, spanBuilder);
    assertNull(spanBuilderWrapper.parentId());
}
 
Example 24
Source Project: java-specialagent   Source File: ExecutorServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@AgentRunner.TestConfig(verbose=false)
public void testSubmitCallableSilent(final MockTracer tracer) throws InterruptedException {
  final CountDownLatch countDownLatch = new CountDownLatch(1);

  executorService.submit(new TestCallable(tracer, countDownLatch));

  countDownLatch.await();
  assertFalse(tracer.finishedSpans().isEmpty());
}
 
Example 25
@Test
@AgentRunner.TestConfig(verbose=false)
public void scheduleCallableTestSilentWithParent(final MockTracer tracer) throws InterruptedException {
  final CountDownLatch countDownLatch = new CountDownLatch(1);
  try (final Scope scope = tracer.buildSpan("parent").startActive(true)) {
    executorService.schedule(new TestCallable(tracer, countDownLatch), 0, TimeUnit.MILLISECONDS);
  }

  countDownLatch.await();
  assertFalse(tracer.finishedSpans().isEmpty());
}
 
Example 26
Source Project: java-specialagent   Source File: PulsarClientTest.java    License: Apache License 2.0 5 votes vote down vote up
private static void test(final MockTracer tracer, final boolean async) throws Exception {
  if (!isJdkSupported) {
    logger.warning("jdk" + System.getProperty("java.version") + " is not supported by Pulsar");
    return;
  }

  try (
    final PulsarClient client = PulsarClient.builder().serviceUrl(pulsarService.getBrokerServiceUrl()).build();
    final Consumer<byte[]> consumer = client.newConsumer().topic("my-topic").subscriptionName("my-subscription").subscribe();
    final Producer<byte[]> producer = client.newProducer().topic("my-topic").create();
  ) {
    if (async)
      producer.sendAsync("My message".getBytes()).get(15, TimeUnit.SECONDS);
    else
      producer.send("My message".getBytes());

    final Message<byte[]> message;
    if (async)
      message = consumer.receiveAsync().get(15, TimeUnit.SECONDS);
    else
      message = consumer.receive();

    System.out.println("Message received: " + new String(message.getData()));
    consumer.acknowledge(message);
  }

  final List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(2, spans.size());
  assertNull(tracer.activeSpan());
  for (final MockSpan span : spans)
    assertEquals(PulsarClientAgentIntercept.COMPONENT_NAME, span.tags().get(Tags.COMPONENT.getKey()));

  assertEquals(spans.get(0).context().traceId(), spans.get(1).context().traceId());
}
 
Example 27
Source Project: java-metrics   Source File: MetricsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTags() {
    MetricsReporter reporter = Mockito.mock(MetricsReporter.class);
    MockTracer tracer = new MockTracer();
    Tracer metricsTracer = Metrics.decorate(tracer, reporter);

    Scope parent = metricsTracer.buildSpan("parent")
            .withTag("booleanTag", true)
            .withTag("numericTag", new Integer(100))
            .startActive(true);

    parent.close();

    List<MockSpan> spans = tracer.finishedSpans();
    assertEquals(1, spans.size());
    MockSpan span = spans.get(0);
    Map<String, Object> tags = span.tags();

    Object booleanTag = tags.get("booleanTag");
    assertNotNull("Expected a tag named 'booleanTag'", booleanTag);
    assertTrue("booleanTag should be a Boolean", booleanTag instanceof Boolean);
    assertEquals("booleanTag should be true", true, booleanTag);

    Object numericTag = tags.get("numericTag");
    assertNotNull("Expected a tag named 'numericTag'", numericTag);
    assertTrue("numericTag should be a Number", numericTag instanceof Number);
    assertEquals("numericTag should be 100", 100, numericTag);
}
 
Example 28
Source Project: spark-dependencies   Source File: TraversalsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testInorder() {
  Node<MockTracingWrapper> root = new Node<>(new MockTracingWrapper(new MockTracer(), "foo"), null);
  Node<MockTracingWrapper> child1 = new Node<>(new MockTracingWrapper(new MockTracer(), "child1"), root);
  Node<MockTracingWrapper> child2 = new Node<>(new MockTracingWrapper(new MockTracer(), "child2"), root);
  Node<MockTracingWrapper> child3 = new Node<>(new MockTracingWrapper(new MockTracer(), "child3"), root);

  List<Node> nodes = new ArrayList<>();
  Traversals.postOrder(root, (node, parent) -> {
    if (parent != null) {
      assertEquals(root, parent);
    } else {
      assertEquals(null, parent);
    }
    nodes.add(node);
  });
  assertEquals(new ArrayList<>(Arrays.asList(child1, child2, child3, root)), nodes);

  Node<MockTracingWrapper> child33 = new Node<>(new MockTracingWrapper(new MockTracer(), "child33"), child3);
  Node<MockTracingWrapper> child333 = new Node<>(new MockTracingWrapper(new MockTracer(), "child333"), child33);

  List<Node> nodes2 = new ArrayList<>();
  List<Node> parents2 = new ArrayList<>();
  Traversals.postOrder(root, (node, parent) -> {
    nodes2.add(node);
    parents2.add(parent);
  });
  assertEquals(new ArrayList<>(Arrays.asList(child1, child2, child333, child33, child3, root)), nodes2);
  assertEquals(new ArrayList<>(Arrays.asList(root, root, child33, child3, root, null)), parents2);
}
 
Example 29
Source Project: java-specialagent   Source File: AwsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSyncClient(final MockTracer tracer) {
  final AmazonDynamoDB dbClient = buildClient();
  try {
    createTable(dbClient, "table-1");
  }
  catch (final Exception e) {
    logger.log(Level.WARNING, e.getMessage());
  }

  final List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(1, spans.size());
  assertEquals("CreateTableRequest", spans.get(0).operationName());
}
 
Example 30
@Test
@AgentRunner.TestConfig(verbose=false)
public void scheduleWithFixedDelayTestSilentWithParent(final MockTracer tracer) throws InterruptedException {
  final CountDownLatch countDownLatch = new CountDownLatch(1);
  try (final Scope scope = tracer.buildSpan("parent").startActive(true)) {
    executorService.scheduleWithFixedDelay(new TestRunnable(tracer, countDownLatch), 0, 10_000, TimeUnit.MILLISECONDS);
  }

  countDownLatch.await();
  assertFalse(tracer.finishedSpans().isEmpty());
}