本文整理汇总了Java中io.opentracing.mock.MockTracer.finishedSpans方法的典型用法代码示例。如果您正苦于以下问题:Java MockTracer.finishedSpans方法的具体用法?Java MockTracer.finishedSpans怎么用?Java MockTracer.finishedSpans使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.opentracing.mock.MockTracer
的用法示例。
在下文中一共展示了MockTracer.finishedSpans方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例3: 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());
}
示例4: testStandardUsage
import io.opentracing.mock.MockTracer; //导入方法依赖的package包/类
@Test
public void testStandardUsage() {
Map<String,Object> sysTags = new HashMap<String,Object>();
sysTags.put("service", "TestService");
MetricsReporter reporter = Mockito.mock(MetricsReporter.class);
MockTracer tracer = new MockTracer(new ThreadLocalActiveSpanSource());
Tracer metricsTracer = Metrics.decorate(tracer, reporter);
ActiveSpan parent = metricsTracer.buildSpan("parent").withTag("spanName","parent").startActive();
parent.setTag("additionalTag", "parent");
ActiveSpan child = metricsTracer.buildSpan("child").withTag("spanName","child").startActive();
child.setTag("additionalTag", "child");
// Test ref counting works fine
ActiveSpan child2 = child.capture().activate();
child2.deactivate();
// Still should be ref to child span
assertEquals(0, tracer.finishedSpans().size());
child.deactivate();
assertEquals(1, tracer.finishedSpans().size());
parent.deactivate();
List<MockSpan> spans = tracer.finishedSpans();
assertEquals(2, spans.size());
Mockito.verify(reporter, Mockito.times(2)).reportSpan(spanDataCaptor.capture());
List<SpanData> captured = spanDataCaptor.getAllValues();
assertEquals(captured.size(), spans.size());
for (int i=0; i < spans.size(); i++) {
MockSpan span = spans.get(i);
assertEquals(span.operationName(), span.tags().get("spanName"));
assertEquals(span.operationName(), span.tags().get("additionalTag"));
}
assertTrue(captured.get(0).getDuration() < captured.get(1).getDuration());
assertEquals("child", captured.get(0).getOperationName());
assertEquals("parent", captured.get(1).getOperationName());
assertEquals(tracer.finishedSpans().get(0).tags(), captured.get(0).getTags());
assertEquals(tracer.finishedSpans().get(1).tags(), captured.get(1).getTags());
}
示例5: testStandardUsage
import io.opentracing.mock.MockTracer; //导入方法依赖的package包/类
@Test
public void testStandardUsage() {
Map<String,Object> sysTags = new HashMap<String,Object>();
sysTags.put("service", "TestService");
MetricsReporter reporter = Mockito.mock(MetricsReporter.class);
MockTracer tracer = new MockTracer(new ThreadLocalActiveSpanSource());
Tracer metricsTracer = Metrics.decorate(tracer, reporter);
ActiveSpan parent = metricsTracer.buildSpan("parent").withTag("spanName","parent").startActive();
parent.setTag("additionalTag", "parent");
ActiveSpan child = metricsTracer.buildSpan("child").withTag("spanName","child").startActive();
child.setTag("additionalTag", "child");
// Test ref counting works fine
ActiveSpan child2 = child.capture().activate();
child2.deactivate();
// Still should be ref to child span
assertEquals(0, tracer.finishedSpans().size());
child.deactivate();
assertEquals(1, tracer.finishedSpans().size());
parent.deactivate();
List<MockSpan> spans = tracer.finishedSpans();
assertEquals(2, spans.size());
Mockito.verify(reporter, Mockito.times(2)).reportSpan(spanCaptor.capture(), operationCaptor.capture(),
tagsCaptor.capture(), durationCaptor.capture());
List<BaseSpan<?>> capturedSpans = spanCaptor.getAllValues();
assertEquals(capturedSpans.size(), spans.size());
for (int i=0; i < spans.size(); i++) {
MockSpan span = spans.get(i);
assertEquals(span.operationName(), span.tags().get("spanName"));
assertEquals(span.operationName(), span.tags().get("additionalTag"));
assertEquals(span.context(), capturedSpans.get(i).context());
}
assertEquals(Arrays.asList("child","parent"), operationCaptor.getAllValues());
assertTrue(durationCaptor.getAllValues().get(0) < durationCaptor.getAllValues().get(1));
assertEquals(tracer.finishedSpans().get(0).tags(), tagsCaptor.getAllValues().get(0));
assertEquals(tracer.finishedSpans().get(1).tags(), tagsCaptor.getAllValues().get(1));
}
示例6: verify
import io.opentracing.mock.MockTracer; //导入方法依赖的package包/类
static void verify(MockTracer mockTracer) {
await().until(() -> mockTracer.finishedSpans().size() == 1);
List<MockSpan> mockSpans = mockTracer.finishedSpans();
assertEquals(1, mockSpans.size());
assertEquals(Tags.SPAN_KIND_CLIENT, mockSpans.get(0).tags().get(Tags.SPAN_KIND.getKey()));
}