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


Java Scope.close方法代码示例

本文整理汇总了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());
}
 
开发者ID:opentracing-contrib,项目名称:java-okhttp,代码行数:26,代码来源:AbstractOkHttpTest.java

示例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());
}
 
开发者ID:OpenFeign,项目名称:feign-opentracing,代码行数:23,代码来源:FeignTracingTest.java

示例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"));
}
 
开发者ID:talsma-ict,项目名称:context-propagation,代码行数:18,代码来源:OpentracingSpanManagerTest.java

示例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);
}
 
开发者ID:opentracing,项目名称:opentracing-java,代码行数:22,代码来源:ThreadLocalScopeManagerTest.java

示例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());
}
 
开发者ID:opentracing,项目名称:opentracing-java,代码行数:20,代码来源:ThreadLocalScopeManagerTest.java

示例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());
}
 
开发者ID:opentracing,项目名称:opentracing-java,代码行数:20,代码来源:ThreadLocalScopeManagerTest.java

示例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);
}
 
开发者ID:opentracing,项目名称:opentracing-java,代码行数:22,代码来源:AutoFinishScopeManagerTest.java

示例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();
    }
  }
}
 
开发者ID:opentracing-contrib,项目名称:java-rxjava,代码行数:16,代码来源:TracingAction.java

示例9: clear

import io.opentracing.Scope; //导入方法依赖的package包/类
static void clear() {
  Scope scope = holder.scope.get();
  if (scope != null) {
    scope.close();
  }
  holder.scope.remove();
}
 
开发者ID:opentracing-contrib,项目名称:java-rxjava,代码行数:8,代码来源:SpanHolder.java

示例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();
    }
  }
}
 
开发者ID:opentracing-contrib,项目名称:java-rxjava,代码行数:15,代码来源:TracingRunnable.java

示例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();
    }
  }
}
 
开发者ID:opentracing-contrib,项目名称:java-concurrent,代码行数:12,代码来源:TracedCallable.java

示例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();
    }
  }
}
 
开发者ID:opentracing-contrib,项目名称:java-concurrent,代码行数:12,代码来源:TracedRunnable.java

示例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();
    }
  }
}
 
开发者ID:opentracing-contrib,项目名称:java-rabbitmq-client,代码行数:14,代码来源:TracingConsumer.java

示例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();
    }
  }

}
 
开发者ID:opentracing-contrib,项目名称:java-jms,代码行数:16,代码来源:TracingMessageListener.java

示例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;
}
 
开发者ID:opentracing-contrib,项目名称:java-jms,代码行数:16,代码来源:TracingMessageUtils.java


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