Search in sources :

Example 11 with SofaTraceContext

use of com.alipay.common.tracer.core.context.trace.SofaTraceContext in project sofa-boot by sofastack.

the class ZipkinSofaTracerSpanRemoteReporterTest method testDoReport.

/**
 * Method: doReport(SofaTracerSpan span)
 */
@Test
public void testDoReport() throws Exception {
    SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext();
    // sr TL
    SofaTracerSpan sofaTracerServerSpan = this.remoteTracer.serverReceive();
    sofaTracerServerSpan.setOperationName("ServerReveive0");
    // assert
    assertEquals(sofaTracerServerSpan, sofaTraceContext.getCurrentSpan());
    // cs
    SofaTracerSpan clientSpan = this.remoteTracer.clientSend("ClientSend0");
    // assert
    assertEquals(clientSpan, sofaTraceContext.getCurrentSpan());
    // mock sync remote call
    this.mockRemoteCall();
    // cr
    this.remoteTracer.clientReceive("0");
    assertEquals(sofaTracerServerSpan, sofaTraceContext.getCurrentSpan());
    // ss TL
    this.remoteTracer.serverSend("0");
    // 异步汇报,所以 sleep 1s
    Thread.sleep(1000);
    // assert
    assertTrue(sofaTraceContext.isEmpty());
}
Also used : SofaTracerSpan(com.alipay.common.tracer.core.span.SofaTracerSpan) SofaTraceContext(com.alipay.common.tracer.core.context.trace.SofaTraceContext) Test(org.junit.Test)

Example 12 with SofaTraceContext

use of com.alipay.common.tracer.core.context.trace.SofaTraceContext in project sofa-boot by alipay.

the class ZipkinSofaTracerSpanRemoteReporterTest method testDoServerReport.

@Test
public void testDoServerReport() throws Exception {
    // sr TL
    SofaTracerSpan sofaTracerServerSpan = this.remoteTracer.serverReceive();
    sofaTracerServerSpan.setOperationName("mockOperationName");
    // ss TL
    this.remoteTracer.serverSend("0");
    // 异步汇报,所以 sleep 1s
    Thread.sleep(1000);
    // assert
    SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext();
    assertTrue(sofaTraceContext.isEmpty());
}
Also used : SofaTracerSpan(com.alipay.common.tracer.core.span.SofaTracerSpan) SofaTraceContext(com.alipay.common.tracer.core.context.trace.SofaTraceContext) Test(org.junit.Test)

Example 13 with SofaTraceContext

use of com.alipay.common.tracer.core.context.trace.SofaTraceContext in project sofa-boot by alipay.

the class ZipkinSofaTracerSpanRemoteReporterTest method testDoReport.

/**
 * Method: doReport(SofaTracerSpan span)
 */
@Test
public void testDoReport() throws Exception {
    SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext();
    // sr TL
    SofaTracerSpan sofaTracerServerSpan = this.remoteTracer.serverReceive();
    sofaTracerServerSpan.setOperationName("ServerReveive0");
    // assert
    assertEquals(sofaTracerServerSpan, sofaTraceContext.getCurrentSpan());
    // cs
    SofaTracerSpan clientSpan = this.remoteTracer.clientSend("ClientSend0");
    // assert
    assertEquals(clientSpan, sofaTraceContext.getCurrentSpan());
    // mock sync remote call
    this.mockRemoteCall();
    // cr
    this.remoteTracer.clientReceive("0");
    assertEquals(sofaTracerServerSpan, sofaTraceContext.getCurrentSpan());
    // ss TL
    this.remoteTracer.serverSend("0");
    // 异步汇报,所以 sleep 1s
    Thread.sleep(1000);
    // assert
    assertTrue(sofaTraceContext.isEmpty());
}
Also used : SofaTracerSpan(com.alipay.common.tracer.core.span.SofaTracerSpan) SofaTraceContext(com.alipay.common.tracer.core.context.trace.SofaTraceContext) Test(org.junit.Test)

Example 14 with SofaTraceContext

use of com.alipay.common.tracer.core.context.trace.SofaTraceContext in project sofa-boot by alipay.

the class ZipkinSofaTracerSpanRemoteReporterTest method mockRemoteCall.

public void mockRemoteCall() throws Exception {
    SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext();
    SofaTracerSpan originSofaTracerSpan = sofaTraceContext.getCurrentSpan();
    SofaTracerSpanContext spanContext = originSofaTracerSpan.getSofaTracerSpanContext();
    sofaTraceContext.clear();
    // sr
    SofaTracerSpan srSpan = this.remoteTracer.serverReceive(spanContext);
    srSpan.setOperationName("ServerReceive1");
    assertEquals(srSpan, sofaTraceContext.getCurrentSpan());
    // ss
    this.remoteTracer.serverSend("0");
    assertTrue(sofaTraceContext.getThreadLocalSpanSize() == 0);
    // mock restore
    sofaTraceContext.push(originSofaTracerSpan);
}
Also used : SofaTracerSpan(com.alipay.common.tracer.core.span.SofaTracerSpan) SofaTraceContext(com.alipay.common.tracer.core.context.trace.SofaTraceContext) SofaTracerSpanContext(com.alipay.common.tracer.core.context.span.SofaTracerSpanContext)

Example 15 with SofaTraceContext

use of com.alipay.common.tracer.core.context.trace.SofaTraceContext in project sofa-boot by alipay.

the class ZipkinSofaTracerSpanRemoteReporterTest method testDoClientReport.

@Test
public void testDoClientReport() throws Exception {
    SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext();
    sofaTraceContext.clear();
    // cs
    SofaTracerSpan clientSpan = this.remoteTracer.clientSend("testDoClientReport");
    assertTrue(clientSpan != null);
    // cr
    this.remoteTracer.clientReceive("0");
    // assert
    assertTrue(sofaTraceContext.isEmpty());
}
Also used : SofaTracerSpan(com.alipay.common.tracer.core.span.SofaTracerSpan) SofaTraceContext(com.alipay.common.tracer.core.context.trace.SofaTraceContext) Test(org.junit.Test)

Aggregations

SofaTraceContext (com.alipay.common.tracer.core.context.trace.SofaTraceContext)26 SofaTracerSpan (com.alipay.common.tracer.core.span.SofaTracerSpan)25 RpcInternalContext (com.alipay.sofa.rpc.context.RpcInternalContext)13 Test (org.junit.Test)7 SofaTracerSpanContext (com.alipay.common.tracer.core.context.span.SofaTracerSpanContext)6 HashMap (java.util.HashMap)6 RpcInvokeContext (com.alipay.sofa.rpc.context.RpcInvokeContext)4 SofaRequest (com.alipay.sofa.rpc.core.request.SofaRequest)3 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)2 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)2 SofaResponse (com.alipay.sofa.rpc.core.response.SofaResponse)2 InetSocketAddress (java.net.InetSocketAddress)2 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)1 RpcRuntimeContext (com.alipay.sofa.rpc.context.RpcRuntimeContext)1 ServerReceiveEvent (com.alipay.sofa.rpc.event.ServerReceiveEvent)1 SofaResourceFactory (com.alipay.sofa.rpc.server.rest.SofaResourceFactory)1 SofaResourceMethodInvoker (com.alipay.sofa.rpc.server.rest.SofaResourceMethodInvoker)1 Context (io.grpc.Context)1 ForwardingServerCall (io.grpc.ForwardingServerCall)1 ForwardingServerCallListener (io.grpc.ForwardingServerCallListener)1