当前位置: 首页>>代码示例>>Java>>正文


Java MockTracer类代码示例

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


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

示例1: testWithStartTimestamp

import io.opentracing.mock.MockTracer; //导入依赖的package包/类
@Test
public void testWithStartTimestamp() throws InterruptedException {
    MetricsReporter reporter = Mockito.mock(MetricsReporter.class);
    MockTracer tracer = new MockTracer(new ThreadLocalActiveSpanSource());
    Tracer metricsTracer = Metrics.decorate(tracer, reporter);

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

    parent.deactivate();

    List<MockSpan> spans = tracer.finishedSpans();
    assertEquals(1, spans.size());
    MockSpan span = spans.get(0);
    long started = span.startMicros();
    assertEquals(start, started);
}
 
开发者ID:opentracing-contrib,项目名称:java-metrics,代码行数:21,代码来源:MetricsTest.java

示例2: testRootToMap

import io.opentracing.mock.MockTracer; //导入依赖的package包/类
@Test
public void testRootToMap() {
  Node<MockTracingWrapper> root = new Node<>(new MockTracingWrapper(new MockTracer(), "foo"), null);
  new Node<>(new MockTracingWrapper(new MockTracer(), "child1"), root);
  new Node<>(new MockTracingWrapper(new MockTracer(), "child1"), root);
  new Node<>(new MockTracingWrapper(new MockTracer(), "child2"), root);
  Node<MockTracingWrapper> child3 = new Node<>(new MockTracingWrapper(new MockTracer(), "child3"), root);
  Node<MockTracingWrapper> child33 = new Node<>(new MockTracingWrapper(new MockTracer(), "child33"), child3);
  new Node<>(new MockTracingWrapper(new MockTracer(), "child333"), child33);

  Map<String, Map<String, Long>> depLinks = DependencyLinkDerivator.serviceDependencies(root);
  // 3 parents
  assertEquals(3, depLinks.size());
  assertEquals(3, depLinks.get("foo").size());
  assertEquals(1, depLinks.get("child3").size());
  assertEquals(1, depLinks.get("child33").size());

  assertEquals(Long.valueOf(2), depLinks.get("foo").get("child1"));
  assertEquals(Long.valueOf(1), depLinks.get("foo").get("child2"));
  assertEquals(Long.valueOf(1), depLinks.get("foo").get("child3"));
  assertEquals(Long.valueOf(1), depLinks.get("child3").get("child33"));
  assertEquals(Long.valueOf(1), depLinks.get("child33").get("child333"));
}
 
开发者ID:jaegertracing,项目名称:spark-dependencies,代码行数:24,代码来源:DependencyLinksDerivatorTest.java

示例3: createDeployment

import io.opentracing.mock.MockTracer; //导入依赖的package包/类
@Deployment
public static Archive createDeployment() throws Exception {
    WARArchive deployment = ShrinkWrap.create(WARArchive.class);

    // on real world deployments, these parts would come from a dependency of the target application
    deployment.addClass(MockTracerResolver.class);
    deployment.addPackage(MockTracer.class.getPackage());
    deployment.addAsServiceProvider(TracerResolver.class, MockTracerResolver.class);

    // this is a simple servlet, that we can hit with our tests
    deployment.addClass(SimpleServlet.class);
    deployment.addClass(HealthServlet.class);
    deployment.addAsResource("project-skip-pattern.yml");

    return deployment;
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:17,代码来源:SkipPatternTest.java

示例4: before

import io.opentracing.mock.MockTracer; //导入依赖的package包/类
@Before
public void before() throws Exception {
  tracer = new MockTracer(new LocalPropagator());
  HttpTransport httpTransport = HttpTransport.builder().tracer(tracer).build();
  HttpInbound inbound = httpTransport.inboundBuilder().port(TestUtil.findRandomPort()).build();
  serverDispatcher = Dispatcher.builder().name(SERVICE).inbound(inbound).build();
  serverDispatcher.register(RawEncoding.newUnaryProcedure(ECHO_PROCEDURE, new EchoHandler()));
  serverDispatcher.start();
  HttpOutbound outbound =
      httpTransport.outboundBuilder().url(TestUtil.getLocalhostUrl(inbound.getPort())).build();
  clientDispatcher =
      Dispatcher.builder()
          .name(CLIENT)
          .unaryOutbound(SERVICE, outbound)
          .onewayOutbound(SERVICE, outbound)
          .build();
  clientDispatcher.start();
}
 
开发者ID:yarpc,项目名称:yarpc-java,代码行数:19,代码来源:ContextPropagationTest.java

示例5: setUp

import io.opentracing.mock.MockTracer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	this.configuration = mock(ConfigurationRegistry.class);
	this.tracingPlugin = mock(TracingPlugin.class);
	when(configuration.getConfig(CorePlugin.class)).thenReturn(corePlugin);
	when(configuration.getConfig(TracingPlugin.class)).thenReturn(tracingPlugin);
	when(configuration.getConfig(ElasticsearchTracingPlugin.class)).thenReturn(spy(new ElasticsearchTracingPlugin()));
	when(corePlugin.getElasticsearchClient()).thenReturn(elasticsearchClient);
	when(corePlugin.getMetricRegistry()).thenReturn(new Metric2Registry());
	when(tracingPlugin.getDefaultRateLimitSpansPerMinute()).thenReturn(1000000d);
	when(tracingPlugin.getProfilerRateLimitPerMinuteOption()).thenReturn(mock(ConfigurationOption.class));
	when(tracingPlugin.isPseudonymizeUserNames()).thenReturn(true);
	when(tracingPlugin.isSampled(any())).thenReturn(true);
	reporter = new ElasticsearchSpanReporter();
	reporter.init(configuration);
	final ReportingSpanEventListener reportingSpanEventListener = new ReportingSpanEventListener(configuration);
	reportingSpanEventListener.addReporter(reporter);
	final SamplePriorityDeterminingSpanEventListener samplePriorityDeterminingSpanInterceptor = mock(SamplePriorityDeterminingSpanEventListener.class);
	when(samplePriorityDeterminingSpanInterceptor.onSetTag(ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).then(invocation -> invocation.getArgument(1));
	when(samplePriorityDeterminingSpanInterceptor.onSetTag(ArgumentMatchers.anyString(), ArgumentMatchers.anyBoolean())).then(invocation -> invocation.getArgument(1));
	when(samplePriorityDeterminingSpanInterceptor.onSetTag(ArgumentMatchers.anyString(), ArgumentMatchers.any(Number.class))).then(invocation -> invocation.getArgument(1));
	tracer = TracingPlugin.createSpanWrappingTracer(new MockTracer(new ThreadLocalScopeManager(), new B3Propagator()), configuration,
			new Metric2Registry(), Collections.emptyList(), samplePriorityDeterminingSpanInterceptor, reportingSpanEventListener);
	when(tracingPlugin.getTracer()).thenReturn(tracer);
}
 
开发者ID:stagemonitor,项目名称:stagemonitor,代码行数:26,代码来源:ElasticsearchSpanReporterIntegrationTest.java

示例6: setUp

import io.opentracing.mock.MockTracer; //导入依赖的package包/类
@Before
public void setUp() {
	mockTracer = new MockTracer(new ThreadLocalScopeManager(), new B3Propagator());
	tracingPlugin = mock(TracingPlugin.class);
	SpanWrappingTracer spanWrappingTracer = new SpanWrappingTracer(mockTracer, asList(
			new SpanContextInformation.SpanContextSpanEventListener(),
			new SpanContextInformation.SpanFinalizer()));
	when(tracingPlugin.getTracer()).thenReturn(spanWrappingTracer);
	when(tracingPlugin.isSampled(any())).thenReturn(true);
	reportingSpanEventListener = mock(ReportingSpanEventListener.class);
	when(tracingPlugin.getReportingSpanEventListener()).thenReturn(reportingSpanEventListener);
	servletPlugin = mock(ServletPlugin.class);
	when(servletPlugin.isClientSpanCollectionEnabled()).thenReturn(true);
	when(servletPlugin.isParseUserAgent()).thenReturn(false);
	servlet = new ClientSpanServlet(tracingPlugin, servletPlugin);
}
 
开发者ID:stagemonitor,项目名称:stagemonitor,代码行数:17,代码来源:ClientSpanServletTest.java

示例7: setUp

import io.opentracing.mock.MockTracer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	Stagemonitor.reset();
	SharedMetricRegistries.clear();
	this.corePlugin = mock(CorePlugin.class);
	when(corePlugin.isStagemonitorActive()).thenReturn(true);

	final MockTracer tracer = new MockTracer(new ThreadLocalScopeManager(), new B3Propagator());

	TracingPlugin tracingPlugin = mock(TracingPlugin.class);
	when(tracingPlugin.getTracer()).thenReturn(tracer);

	mdcSpanInterceptor = new MDCSpanEventListener(corePlugin, tracingPlugin);
	spanWrapper = new SpanWrapper(tracer.buildSpan("operation name").start(),"operation name",
			1, 1, Collections.emptyList(), new ConcurrentHashMap<>());
}
 
开发者ID:stagemonitor,项目名称:stagemonitor,代码行数:17,代码来源:MDCSpanEventListenerTest.java

示例8: reportedSpansSize

import io.opentracing.mock.MockTracer; //导入依赖的package包/类
static Callable<Integer> reportedSpansSize(final MockTracer mockTracer) {
  return new Callable<Integer>() {
    @Override
    public Integer call() throws Exception {
      return mockTracer.finishedSpans().size();
    }
  };
}
 
开发者ID:opentracing-contrib,项目名称:java-rxjava,代码行数:9,代码来源:TestUtils.java

示例9: createSequentialObservable

import io.opentracing.mock.MockTracer; //导入依赖的package包/类
static Observable<Integer> createSequentialObservable(final MockTracer mockTracer) {
  return Observable.range(1, 10)
      .map(new Func1<Integer, Integer>() {
        @Override
        public Integer call(Integer integer) {
          assertNotNull(mockTracer.scopeManager().active());
          return integer * 3;
        }
      });
}
 
开发者ID:opentracing-contrib,项目名称:java-rxjava,代码行数:11,代码来源:TestUtils.java

示例10: fromInterval

import io.opentracing.mock.MockTracer; //导入依赖的package包/类
static Observable<Long> fromInterval(final MockTracer mockTracer) {
  return Observable.interval(500, TimeUnit.MILLISECONDS, Schedulers.computation())
      .map(new Func1<Long, Long>() {
        @Override
        public Long call(Long value) {
          assertNotNull(mockTracer.scopeManager().active());
          return value * 2;
        }
      })
      .subscribeOn(Schedulers.io())
      .take(5);
}
 
开发者ID:opentracing-contrib,项目名称:java-rxjava,代码行数:13,代码来源:TestUtils.java

示例11: testAssociateSpan

import io.opentracing.mock.MockTracer; //导入依赖的package包/类
@Test
public void testAssociateSpan() {
    OpenTracingHelper helper = new OpenTracingHelper(null);

    Object obj = new Object();
    Span span = new MockTracer().buildSpan("Test").start();

    helper.associateSpan(obj, span);

    assertEquals(span, helper.retrieveSpan(obj));
}
 
开发者ID:opentracing-contrib,项目名称:java-agent,代码行数:12,代码来源:OpenTracingHelperTest.java

示例12: testGetTracerExisting

import io.opentracing.mock.MockTracer; //导入依赖的package包/类
@Test
public void testGetTracerExisting() {
    GlobalTracer.register(new MockTracer());

    OpenTracingHelper helper = new OpenTracingHelper(null);
    Tracer tracer = helper.getTracer();

    assertNotNull(tracer);

    assertTrue(tracer.buildSpan("Test").start() instanceof MockSpan);
}
 
开发者ID:opentracing-contrib,项目名称:java-agent,代码行数:12,代码来源:OpenTracingHelperTest.java

示例13: testGetAutoWiredTracer

import io.opentracing.mock.MockTracer; //导入依赖的package包/类
@Test
public void testGetAutoWiredTracer() {
    assertTrue(tracer instanceof MockTracer);
    assertTrue(GlobalTracer.isRegistered());
    GlobalTracer.get().buildSpan("hello").startManual().finish();
    assertEquals(1, ((MockTracer)tracer).finishedSpans().size());
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-web,代码行数:8,代码来源:TracerAutoConfigurationTest.java

示例14: testWithTags

import io.opentracing.mock.MockTracer; //导入依赖的package包/类
@Test
public void testWithTags() {
    MetricsReporter reporter = Mockito.mock(MetricsReporter.class);
    MockTracer tracer = new MockTracer(new ThreadLocalActiveSpanSource());
    Tracer metricsTracer = Metrics.decorate(tracer, reporter);

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

    parent.deactivate();

    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);
}
 
开发者ID:opentracing-contrib,项目名称:java-metrics,代码行数:29,代码来源:MetricsTest.java

示例15: testAsChildOf

import io.opentracing.mock.MockTracer; //导入依赖的package包/类
@Test
public void testAsChildOf() {
    MetricsReporter reporter = Mockito.mock(MetricsReporter.class);
    MockTracer tracer = new MockTracer(new ThreadLocalActiveSpanSource());
    Tracer metricsTracer = Metrics.decorate(tracer, reporter);

    ActiveSpan parentSpan = metricsTracer.buildSpan("parent")
            .withTag("spanName","parent")
            .startActive();
    parentSpan.setTag("additionalTag", "parent");

    ActiveSpan childSpan = metricsTracer.buildSpan("child")
            .asChildOf(parentSpan)
            .withTag("spanName","child")
            .startActive();
    childSpan.setTag("additionalTag", "child");

    childSpan.deactivate();
    parentSpan.deactivate();

    List<MockSpan> spans = tracer.finishedSpans();
    assertEquals(2, spans.size());
    MockSpan span1 = spans.get(0);
    MockSpan span2 = spans.get(1);

    MockSpan parent, child;
    if (span1.operationName().equals("parent")) {
        parent = span1;
        child = span2;
    } else {
        parent = span2;
        child = span1;
    }

    assertEquals("Child's parent id should be spanId of parent", child.parentId(), parent.context().spanId());
    assertEquals(0, parent.parentId());
}
 
开发者ID:opentracing-contrib,项目名称:java-metrics,代码行数:38,代码来源:MetricsTest.java


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