• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MockSpan类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.opentracing.mock.MockSpan的典型用法代码示例。如果您正苦于以下问题:Java MockSpan类的具体用法?Java MockSpan怎么用?Java MockSpan使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MockSpan类属于io.opentracing.mock包,在下文中一共展示了MockSpan类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testUnknownHostException

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void testUnknownHostException() throws IOException {
    CloseableHttpClient client = clientBuilder.build();

    try {
        client.execute(new HttpGet("http://notexisting.example.com"));
    } catch (UnknownHostException ex) {
    }

    List<MockSpan> mockSpans = mockTracer.finishedSpans();
    Assert.assertEquals(2, mockSpans.size());

    MockSpan mockSpan = mockSpans.get(0);
    Assert.assertEquals(Boolean.TRUE, mockSpan.tags().get(Tags.ERROR.getKey()));

    // logs
    Assert.assertEquals(1, mockSpan.logEntries().size());
    Assert.assertEquals(2, mockSpan.logEntries().get(0).fields().size());
    Assert.assertEquals(Tags.ERROR.getKey(), mockSpan.logEntries().get(0).fields().get("event"));
    Assert.assertNotNull(mockSpan.logEntries().get(0).fields().get("error.object"));
}
 
开发者ID:opentracing-contrib,项目名称:java-apache-httpclient,代码行数:22,代码来源:TracingHttpClientBuilderTest.java


示例2: test

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void test() throws SQLException {
  BasicDataSource dataSource = getDataSource("");

  JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
  jdbcTemplate.execute("CREATE TABLE employee (id INTEGER)");

  dataSource.close();

  List<MockSpan> finishedSpans = mockTracer.finishedSpans();
  assertEquals(1, finishedSpans.size());
  checkTags(finishedSpans, "myservice", "jdbc:hsqldb:mem:spring");
  checkSameTrace(finishedSpans);

  assertNull(mockTracer.scopeManager().active());
}
 
开发者ID:opentracing-contrib,项目名称:java-p6spy,代码行数:17,代码来源:SpringTest.java


示例3: jpa_with_active_span_only

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void jpa_with_active_span_only() {
  EntityManagerFactory entityManagerFactory = Persistence
      .createEntityManagerFactory("jpa_active_span_only");

  Employee employee = new Employee();
  EntityManager entityManager = entityManagerFactory.createEntityManager();
  entityManager.getTransaction().begin();
  entityManager.persist(employee);
  entityManager.getTransaction().commit();
  entityManager.close();
  entityManagerFactory.close();

  assertNotNull(employee.id);

  List<MockSpan> finishedSpans = mockTracer.finishedSpans();
  assertEquals(0, finishedSpans.size());

  assertNull(mockTracer.activeSpan());
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:21,代码来源:HibernateTest.java


示例4: testWithSpanOnlyWithParent

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void testWithSpanOnlyWithParent() throws SQLException {
  try (Scope activeSpan = mockTracer.buildSpan("parent").startActive(true)) {
    BasicDataSource dataSource = getDataSource(";traceWithActiveSpanOnly=true");

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.execute("CREATE TABLE with_parent_skip (id INTEGER)");

    dataSource.close();
  }

  List<MockSpan> finishedSpans = mockTracer.finishedSpans();
  assertEquals(2, finishedSpans.size());
  checkSameTrace(finishedSpans);
  assertNull(mockTracer.scopeManager().active());
}
 
开发者ID:opentracing-contrib,项目名称:java-p6spy,代码行数:17,代码来源:SpringTest.java


示例5: jpa

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void jpa() {
  EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("jpa");

  Employee employee = new Employee();
  EntityManager entityManager = entityManagerFactory.createEntityManager();
  entityManager.getTransaction().begin();
  entityManager.persist(employee);
  entityManager.getTransaction().commit();
  entityManager.close();
  entityManagerFactory.close();

  assertNotNull(employee.id);

  List<MockSpan> finishedSpans = mockTracer.finishedSpans();
  assertEquals(8, finishedSpans.size());
  checkTags(finishedSpans, "myservice", "jdbc:hsqldb:mem:jpa");
  assertNull(mockTracer.scopeManager().active());
}
 
开发者ID:opentracing-contrib,项目名称:java-p6spy,代码行数:20,代码来源:HibernateTest.java


示例6: testParentSpanFromSpanManager

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void testParentSpanFromSpanManager() throws InterruptedException {
    {
        Scope scope = mockTracer.buildSpan("parent")
                .startActive(true);

        mockWebServer.enqueue(new MockResponse()
                .setResponseCode(200));

        StringEntityRequest
                entity = feign.<StringEntityRequest>newInstance(new Target.HardCodedTarget(StringEntityRequest.class,
                mockWebServer.url("/foo").toString()));
        entity.get();
        scope.close();
    }
    Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(2));

    List<MockSpan> mockSpans = mockTracer.finishedSpans();
    Assert.assertEquals(2, mockSpans.size());
    Assert.assertEquals(mockSpans.get(1).context().traceId(), mockSpans.get(0).context().traceId());
    Assert.assertEquals(mockSpans.get(1).context().spanId(), mockSpans.get(0).parentId());
}
 
开发者ID:OpenFeign,项目名称:feign-opentracing,代码行数:23,代码来源:FeignTracingTest.java


示例7: withActiveSpanOnlyNoParent

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void withActiveSpanOnlyNoParent() throws InterruptedException {
  SessionFactory sessionFactory = createSessionFactory(";traceWithActiveSpanOnly=true");
  Session session = sessionFactory.openSession();

  Employee employee = new Employee();
  session.beginTransaction();
  session.save(employee);
  session.getTransaction().commit();
  session.close();
  sessionFactory.close();

  List<MockSpan> finishedSpans = mockTracer.finishedSpans();
  assertEquals(0, finishedSpans.size());

  assertNull(mockTracer.scopeManager().active());
}
 
开发者ID:opentracing-contrib,项目名称:java-p6spy,代码行数:18,代码来源:HibernateTest.java


示例8: spring_with_parent_and_active_span_only

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void spring_with_parent_and_active_span_only() throws Exception {
  try (Scope ignored = mockTracer.buildSpan("parent").startActive(true)) {
    BasicDataSource dataSource = getDataSource(true);

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.execute("CREATE TABLE with_parent_skip_1 (id INTEGER)");
    jdbcTemplate.execute("CREATE TABLE with_parent_skip_2 (id INTEGER)");

    dataSource.close();
  }

  List<MockSpan> spans = mockTracer.finishedSpans();
  assertEquals(3, spans.size());

  checkSameTrace(spans);
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:18,代码来源:SpringTest.java


示例9: testZuulTracing

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void testZuulTracing() {
  restTemplate.getForEntity("/test", String.class);

  await().until(() -> mockTracer.finishedSpans().size() == 3);
  List<MockSpan> mockSpans = mockTracer.finishedSpans();
  assertEquals(3, mockSpans.size());

  // 2 spans from java-web-servlet, 1 from zuul
  assertEquals(2, getSpansByComponentName(mockSpans, "java-web-servlet").size());

  MockSpan zuulSpan = getSpansByComponentName(mockSpans, TracePreZuulFilter.COMPONENT_NAME)
      .get(0);
  assertEquals(200, zuulSpan.tags().get(Tags.HTTP_STATUS.getKey()));
  assertEquals("http://localhost:53751/hello",
      zuulSpan.tags().get(TracePostZuulFilter.ROUTE_HOST_TAG));
  assertEquals("GET", zuulSpan.operationName());
  assertEquals(0, zuulSpan.generatedErrors().size());

  TestUtils.assertSameTraceId(mockSpans);
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:22,代码来源:ZuulTracingTest.java


示例10: testAsyncTraceAndSpans

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void testAsyncTraceAndSpans() throws Exception {
  try (ActiveSpan span = mockTracer.buildSpan("bar")
      .startActive()) {
    Future<String> fut = asyncService.fooAsync();
    await().until(() -> fut.isDone());
    assertThat(fut.get()).isNotNull();
  }
  await().until(() -> mockTracer.finishedSpans().size() == 3);

  List<MockSpan> mockSpans = mockTracer.finishedSpans();
  // parent span from test, span modelling @Async, span inside @Async
  assertEquals(3, mockSpans.size());
  TestUtils.assertSameTraceId(mockSpans);
  MockSpan asyncSpan = mockSpans.get(1);
  assertEquals(3, asyncSpan.tags().size());
  assertEquals(TraceAsyncAspect.TAG_COMPONENT, asyncSpan.tags().get(Tags.COMPONENT.getKey()));
  assertEquals("fooAsync", asyncSpan.tags().get(ExtensionTags.METHOD_TAG.getKey()));
  assertEquals(AsyncService.class.getSimpleName(),
      asyncSpan.tags().get(ExtensionTags.CLASS_TAG.getKey()));
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:22,代码来源:AsyncAnnotationTest.java


示例11: test

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void test() throws Exception {
  Producer<Integer, String> producer = createProducer();

  // Send 1
  producer.send(new ProducerRecord<>("messages", 1, "test"));

  // Send 2
  producer.send(new ProducerRecord<>("messages", 1, "test"), new Callback() {
    @Override
    public void onCompletion(RecordMetadata metadata, Exception exception) {
      assertEquals("messages", metadata.topic());
    }
  });

  final CountDownLatch latch = new CountDownLatch(2);
  createConsumer(latch, 1);

  producer.close();

  List<MockSpan> mockSpans = mockTracer.finishedSpans();
  assertEquals(4, mockSpans.size());
  checkSpans(mockSpans);
  assertNull(mockTracer.activeSpan());
}
 
开发者ID:opentracing-contrib,项目名称:java-kafka-client,代码行数:26,代码来源:TracingKafkaTest.java


示例12: testWithCircuitBreaker

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void testWithCircuitBreaker() {
  try (ActiveSpan span = mockTracer.buildSpan("test_with_circuit_breaker")
      .startActive()) {
    String response = greetingService.alwaysFail();
    assertThat(response).isNotNull();
  }

  /**
   * 3 spans totally
   * <ul>
   *     <li>one thats started in test</li>
   *     <li>one thats added in alwaysFail method of Greeting Service</li>
   *     <li>one thats added in the defaultGreeting method which is a fallback</li>
   * </ul>
   */
  await().atMost(3, TimeUnit.SECONDS).until(() -> mockTracer.finishedSpans().size() == 3);

  List<MockSpan> mockSpans = mockTracer.finishedSpans();
  assertEquals(3, mockSpans.size());
  TestUtils.assertSameTraceId(mockSpans);
  MockSpan hystrixSpan = mockSpans.get(1);
  assertThat(hystrixSpan.tags()).isNotEmpty();
  //one thats added in the defaultGreeting method which is a fallback should have the custom tag added
  assertThat(hystrixSpan.tags().get("fallback")).isEqualTo("yes");
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:27,代码来源:TracedHystrixCommandTest.java


示例13: extract_second_no_context

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void extract_second_no_context() {
  MockSpan span = mockTracer.buildSpan("first").start();
  Headers headers = new RecordHeaders();
  assertTrue(headers.toArray().length == 0);

  // inject first
  TracingKafkaUtils.inject(span.context(), headers, mockTracer);
  int headersLength = headers.toArray().length;
  assertTrue(headersLength > 0);

  // check second
  MockSpan.MockContext spanContext2 = (MockContext) TracingKafkaUtils
      .extractSpanContext(headers, mockTracer);
  assertNull(spanContext2);
}
 
开发者ID:opentracing-contrib,项目名称:java-kafka-client,代码行数:17,代码来源:TracingKafkaUtilsTest.java


示例14: testFailRoutingContext

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void testFailRoutingContext() throws Exception {
    {
        router.route("/fail").handler(routingContext -> {
            routingContext.fail(501);
        });

        request("/fail", HttpMethod.GET, 501);
        Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
    }
    List<MockSpan> mockSpans = mockTracer.finishedSpans();
    Assert.assertEquals(1, mockSpans.size());

    MockSpan mockSpan = mockSpans.get(0);
    Assert.assertEquals("GET", mockSpan.operationName());
    Assert.assertEquals(6, mockSpan.tags().size());
    Assert.assertEquals(Boolean.TRUE, mockSpan.tags().get(Tags.ERROR.getKey()));
    Assert.assertEquals(501, mockSpan.tags().get(Tags.HTTP_STATUS.getKey()));
    Assert.assertEquals("GET", mockSpan.tags().get(Tags.HTTP_METHOD.getKey()));
    Assert.assertEquals("http://localhost:8080/fail", mockSpan.tags().get(Tags.HTTP_URL.getKey()));
    Assert.assertEquals(0, mockSpan.logEntries().size());
}
 
开发者ID:opentracing-contrib,项目名称:java-vertx-web,代码行数:23,代码来源:TracingHandlerTest.java


示例15: testPreSendServerSpan

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void testPreSendServerSpan() {
  MessageBuilder<String> messageBuilder = MessageBuilder.withPayload("Hi")
      .setHeader(TracingChannelInterceptor.SIMP_MESSAGE_TYPE, SimpMessageType.MESSAGE)
      .setHeader(TracingChannelInterceptor.SIMP_DESTINATION, TEST_DESTINATION);

  MockSpan parentSpan = mockTracer.buildSpan("parent").startManual();
  mockTracer.inject(parentSpan.context(), Format.Builtin.TEXT_MAP,
      new TextMapInjectAdapter(messageBuilder));

  TracingChannelInterceptor interceptor = new TracingChannelInterceptor(mockTracer,
      Tags.SPAN_KIND_SERVER);

  Message<?> processed = interceptor.preSend(messageBuilder.build(), null);

  // Verify span cached with message is child of propagated parentSpan span context
  assertTrue(processed.getHeaders().containsKey(TracingChannelInterceptor.OPENTRACING_SPAN));
  MockSpan childSpan = (MockSpan) processed.getHeaders()
      .get(TracingChannelInterceptor.OPENTRACING_SPAN);
  assertEquals(parentSpan.context().spanId(), childSpan.parentId());
  assertEquals(parentSpan.context().traceId(), childSpan.context().traceId());
  assertEquals(TEST_DESTINATION, childSpan.operationName());
  assertEquals(Tags.SPAN_KIND_SERVER, childSpan.tags().get(Tags.SPAN_KIND.getKey()));
  assertEquals(TracingChannelInterceptor.WEBSOCKET,
      childSpan.tags().get(Tags.COMPONENT.getKey()));
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:27,代码来源:TracingChannelInterceptorTest.java


示例16: testWithoutCircuitBreaker

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void testWithoutCircuitBreaker() throws Exception {

  try (ActiveSpan span = mockTracer.buildSpan("test_without_circuit_breaker")
      .startActive()) {
    String response = greetingService.sayHello();
    assertThat(response).isNotNull();
  }

  /**
   * 2 spans totally
   * <ul>
   *     <li>one that's started in test</li>
   *     <li>one that's added in sayHello method of Greeting Service</li>
   * </ul>
   */

  await().atMost(3, TimeUnit.SECONDS).until(() -> mockTracer.finishedSpans().size() == 2);

  List<MockSpan> mockSpans = mockTracer.finishedSpans();
  assertEquals(2, mockSpans.size());
  TestUtils.assertSameTraceId(mockSpans);
  MockSpan hystrixSpan = mockSpans.get(1);
  assertThat(hystrixSpan.tags()).isEmpty();
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:26,代码来源:TracedHystrixCommandTest.java


示例17: parallel

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void parallel() {
  Observable<Integer> observable = createParallelObservable(mockTracer);

  List<Integer> result = new ArrayList<>();
  Consumer<Integer> onNext = consumer(result);

  observable.subscribe(new TracingConsumer<>(onNext, "sequential", mockTracer));

  await().atMost(15, TimeUnit.SECONDS).until(reportedSpansSize(mockTracer), equalTo(1));
  assertEquals(5, result.size());

  List<MockSpan> spans = mockTracer.finishedSpans();
  assertEquals(1, spans.size());
  checkSpans(spans);

  assertNull(mockTracer.scopeManager().active());
}
 
开发者ID:opentracing-contrib,项目名称:java-rxjava,代码行数:19,代码来源:TracingConsumerTest.java


示例18: testWrongZuulRoutePort

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void testWrongZuulRoutePort() {
  restTemplate.getForEntity("/wrong-port", String.class);

  // 1 span from servlet filter, 1 from zuul
  await().until(() -> mockTracer.finishedSpans().size() == 2);
  List<MockSpan> mockSpans = mockTracer.finishedSpans();
  assertEquals(2, mockSpans.size());

  MockSpan zuulSpan = getSpansByComponentName(mockSpans, TracePreZuulFilter.COMPONENT_NAME)
      .get(0);
  assertEquals(TracePreZuulFilter.COMPONENT_NAME, zuulSpan.tags().get(Tags.COMPONENT.getKey()));
  assertEquals(500, zuulSpan.tags().get(Tags.HTTP_STATUS.getKey()));
  assertEquals(1, zuulSpan.logEntries().size());
  assertEquals(Tags.ERROR.getKey(), zuulSpan.logEntries().get(0).fields().get("event"));
  assertTrue(zuulSpan.logEntries().get(0).fields().containsKey("error.object"));
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:18,代码来源:ZuulTracingTest.java


示例19: testExceptionThrown

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void testExceptionThrown() {
  try {
    asyncService.fooException();
  } catch (Exception e) {
    e.printStackTrace();
  }
  await().until(() -> mockTracer.finishedSpans().size() == 1);

  List<MockSpan> mockSpans = mockTracer.finishedSpans();
  assertEquals(1, mockSpans.size());
  assertEquals(4, mockSpans.get(0).tags().size());
  assertEquals(Boolean.TRUE, mockSpans.get(0).tags().get(Tags.ERROR.getKey()));
  assertEquals(1, mockSpans.get(0).logEntries().size());
  assertEquals("error", mockSpans.get(0).logEntries().get(0).fields().get("event"));
  assertTrue(mockSpans.get(0).logEntries().get(0).fields()
      .get("error.object") instanceof RuntimeException);
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:19,代码来源:AsyncAnnotationTest.java


示例20: two_parallel

import io.opentracing.mock.MockSpan; //导入依赖的package包/类
@Test
public void two_parallel() throws Exception {
  List<Integer> result = new CopyOnWriteArrayList<>();
  executeParallelObservable("first_parallel", result);
  executeParallelObservable("second_parallel", result);

  await().atMost(15, TimeUnit.SECONDS).until(reportedSpansSize(mockTracer), equalTo(2));

  assertEquals(10, result.size());

  List<MockSpan> spans = mockTracer.finishedSpans();
  assertEquals(2, spans.size());

  assertNotEquals(spans.get(0).context().traceId(), spans.get(1).context().traceId());

  assertNull(mockTracer.scopeManager().active());
}
 
开发者ID:opentracing-contrib,项目名称:java-rxjava,代码行数:18,代码来源:TracingObserverTest.java



注:本文中的io.opentracing.mock.MockSpan类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AbstractResource类代码示例发布时间:2022-05-21
下一篇:
Java XSD类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap