本文整理汇总了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);
}
示例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"));
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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<>());
}
示例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();
}
};
}
示例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;
}
});
}
示例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);
}
示例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));
}
示例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);
}
示例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());
}
示例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);
}
示例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());
}