本文整理汇总了Java中io.opentracing.Scope.close方法的典型用法代码示例。如果您正苦于以下问题:Java Scope.close方法的具体用法?Java Scope.close怎么用?Java Scope.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.opentracing.Scope
的用法示例。
在下文中一共展示了Scope.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testParentSpanSource
import io.opentracing.Scope; //导入方法依赖的package包/类
@Test
public void testParentSpanSource() throws IOException {
{
Scope parent = mockTracer.buildSpan("parent")
.startActive(true);
mockWebServer.enqueue(new MockResponse()
.setResponseCode(203));
Request request = new Request.Builder()
.url(mockWebServer.url("bar"))
.tag(new TagWrapper(parent.span().context()))
.get()
.build();
client.newCall(request).execute();
parent.close();
}
List<MockSpan> mockSpans = mockTracer.finishedSpans();
assertOnErrors(mockSpans);
Assert.assertEquals(3, mockSpans.size());
Assert.assertEquals(mockSpans.get(2).context().traceId(), mockSpans.get(1).context().traceId());
Assert.assertEquals(mockSpans.get(2).context().spanId(), mockSpans.get(1).parentId());
}
示例2: testParentSpanFromSpanManager
import io.opentracing.Scope; //导入方法依赖的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());
}
示例3: testSingleSnapshotInBackgroundThread
import io.opentracing.Scope; //导入方法依赖的package包/类
@Test
public void testSingleSnapshotInBackgroundThread() throws Exception {
Scope outerSpan = mockTracer.buildSpan("first-op").startActive(true);
outerSpan.span().setBaggageItem("baggage-item", "in-outer-span");
// sanity-check: outerSpan should be the active span..
assertThat("sanity-check", GET_BAGGAGE_ITEM.call(), equalTo("in-outer-span"));
// The active span reference should propagate to the background thread and therefore return the baggage.
Future<String> backgroundBaggage = threadpool.submit(GET_BAGGAGE_ITEM);
assertThat("background baggage", backgroundBaggage.get(), equalTo("in-outer-span"));
assertThat("span finished?", mockTracer.finishedSpans(), is(emptyCollectionOf(MockSpan.class)));
outerSpan.close();
assertThat("span finished?", mockTracer.finishedSpans(), hasSize(1));
assertThat("baggage of active span", GET_BAGGAGE_ITEM.call(), equalTo("no-active-span"));
}
示例4: defaultActivate
import io.opentracing.Scope; //导入方法依赖的package包/类
@Test
public void defaultActivate() throws Exception {
Span span = mock(Span.class);
// We can't use 1.7 features like try-with-resources in this repo without meddling with pom details for tests.
Scope scope = source.activate(span, false);
try {
assertNotNull(scope);
Scope otherScope = source.active();
assertEquals(otherScope, scope);
} finally {
scope.close();
}
// Make sure the Span is not finished.
verify(span, times(0)).finish();
// And now it's gone:
Scope missingScope = source.active();
assertNull(missingScope);
}
示例5: finishSpanClose
import io.opentracing.Scope; //导入方法依赖的package包/类
@Test
public void finishSpanClose() throws Exception {
Span span = mock(Span.class);
// We can't use 1.7 features like try-with-resources in this repo without meddling with pom details for tests.
Scope scope = source.activate(span, true);
try {
assertNotNull(scope);
assertNotNull(source.active());
} finally {
scope.close();
}
// Make sure the Span got finish()ed.
verify(span, times(1)).finish();
// Verify it's gone.
assertNull(source.active());
}
示例6: dontFinishSpanNoClose
import io.opentracing.Scope; //导入方法依赖的package包/类
@Test
public void dontFinishSpanNoClose() throws Exception {
Span span = mock(Span.class);
// We can't use 1.7 features like try-with-resources in this repo without meddling with pom details for tests.
Scope scope = source.activate(span, false);
try {
assertNotNull(scope);
assertNotNull(source.active());
} finally {
scope.close();
}
// Make sure the Span did *not* get finish()ed.
verify(span, never()).finish();
// Verify it's gone.
assertNull(source.active());
}
示例7: activateSpan
import io.opentracing.Scope; //导入方法依赖的package包/类
@Test
public void activateSpan() throws Exception {
Span span = mock(Span.class);
// We can't use 1.7 features like try-with-resources in this repo without meddling with pom details for tests.
Scope active = source.activate(span, true);
try {
assertNotNull(active);
Scope otherScope = source.active();
assertEquals(otherScope, active);
} finally {
active.close();
}
// Make sure the Span got finish()ed.
verify(span).finish();
// And now it's gone:
Scope missingSpan = source.active();
assertNull(missingSpan);
}
示例8: call
import io.opentracing.Scope; //导入方法依赖的package包/类
@Override
public void call() {
Scope scope = null;
if (span != null) {
scope = tracer.scopeManager().activate(span, false);
}
try {
action0.call();
} finally {
if (scope != null) {
scope.close();
}
}
}
示例9: clear
import io.opentracing.Scope; //导入方法依赖的package包/类
static void clear() {
Scope scope = holder.scope.get();
if (scope != null) {
scope.close();
}
holder.scope.remove();
}
示例10: run
import io.opentracing.Scope; //导入方法依赖的package包/类
@Override
public void run() {
Scope scope = null;
if (span != null) {
scope = tracer.scopeManager().activate(span, false);
}
try {
runnable.run();
} finally {
if (scope != null) {
scope.close();
}
}
}
示例11: call
import io.opentracing.Scope; //导入方法依赖的package包/类
@Override
public V call() throws Exception {
Scope scope = span == null ? null : tracer.scopeManager().activate(span, false);
try {
return delegate.call();
} finally {
if (scope != null) {
scope.close();
}
}
}
示例12: run
import io.opentracing.Scope; //导入方法依赖的package包/类
@Override
public void run() {
Scope scope = span == null ? null : tracer.scopeManager().activate(span, false);
try {
delegate.run();
} finally {
if (scope != null) {
scope.close();
}
}
}
示例13: handleDelivery
import io.opentracing.Scope; //导入方法依赖的package包/类
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
byte[] body) throws IOException {
Scope child = TracingUtils.buildChildSpan(properties, tracer);
try {
consumer.handleDelivery(consumerTag, envelope, properties, body);
} finally {
if (child != null) {
child.close();
}
}
}
示例14: onMessage
import io.opentracing.Scope; //导入方法依赖的package包/类
@Override
public void onMessage(Message message) {
Scope scope = TracingMessageUtils.buildFollowingSpan(message, tracer);
try {
if (messageListener != null) {
messageListener.onMessage(message);
}
} finally {
if (scope != null) {
scope.close();
}
}
}
示例15: buildAndFinishChildSpan
import io.opentracing.Scope; //导入方法依赖的package包/类
/**
* Build following span and finish it. Should be used by consumers/listeners
*
* @param message JMS message
* @param tracer Tracer
* @return child span
*/
public static Scope buildAndFinishChildSpan(Message message, Tracer tracer) {
Scope child = buildFollowingSpan(message, tracer);
if (child != null) {
child.close();
}
return child;
}