SofaTraceContextHolder { public static SofaTraceContext getSofaTraceContext() { return SOFA_TRACE_CONTEXT; }  static SofaTraceContext getSofaTraceContext();  }
@Test public void testGetSofaTraceContext() throws Exception { SofaTracerSpan pushedSpan = (SofaTracerSpan) this.sofaTracer.buildSpan("span1").start(); SofaTracerSpanContext pushedSofaTracerSpanContext = pushedSpan.getSofaTracerSpanContext(); String traceId = pushedSofaTracerSpanContext.getTraceId(); String spanId = pushedSofaTracerSpanContext.getSpanId(); String parentSpanId = pushedSofaTracerSpanContext.getParentId(); assertTrue("\n" + pushedSpan.getSofaTracerSpanContext(), StringUtils.isBlank(parentSpanId)); SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext(); sofaTraceContext.clear(); SofaTracerSpan peekTracerSpan = sofaTraceContext.getCurrentSpan(); SofaTracerSpan popTracerSpan = sofaTraceContext.pop(); assertNull(peekTracerSpan); assertNull(popTracerSpan); assertTrue(sofaTraceContext.isEmpty()); sofaTraceContext.push(null); assertEquals(0, sofaTraceContext.getThreadLocalSpanSize()); sofaTraceContext.push(pushedSpan); assertEquals(1, sofaTraceContext.getThreadLocalSpanSize()); sofaTraceContext.push(null); assertEquals(1, sofaTraceContext.getThreadLocalSpanSize()); SofaTracerSpan gettedSpan = sofaTraceContext.getCurrentSpan(); assertTrue(gettedSpan == pushedSpan); assertEquals(1, sofaTraceContext.getThreadLocalSpanSize()); SofaTracerSpan poppedSpan = sofaTraceContext.pop(); assertEquals(0, sofaTraceContext.getThreadLocalSpanSize()); assertTrue(poppedSpan == pushedSpan); assertTrue(sofaTraceContext.isEmpty()); }