@Test public void sofaTracerRunnableSamples() throws InterruptedException { SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext(); SofaTracerSpan sofaTracerSpan = mock((SofaTracerSpan.class)); sofaTraceContext.push(sofaTracerSpan); RunnableTread runnableTread = new RunnableTread(); SofaTracerRunnable sofaTracerRunnable = new SofaTracerRunnable(runnableTread, sofaTraceContext); sofaTracerRunnable.run(); assertEquals(1, sofaTraceContext.getThreadLocalSpanSize()); assertEquals(Thread.currentThread().getId(), runnableTread.getThreadId()); assertEquals(Thread.currentThread().getName(), runnableTread.getThreadName()); Thread thread = new Thread(sofaTracerRunnable); thread.start(); Thread.sleep(3 * 1000); assertEquals(1, sofaTraceContext.getThreadLocalSpanSize()); assertEquals(2, runnableTread.atomicLong.get()); assertNotEquals(Thread.currentThread().getId(), runnableTread.getThreadId()); assertNotEquals(Thread.currentThread().getName(), runnableTread.getThreadName()); }
@Override public void run() { if (Thread.currentThread().getId() != tid) { if (currentSpan != null) { traceContext.push(currentSpan); SpanExtensionFactory.logStartedSpan(currentSpan); } } try { wrappedRunnable.run(); } finally { if (Thread.currentThread().getId() != tid) { if (currentSpan != null) { traceContext.pop(); } } } }
SofaTracerRunnable implements Runnable { @Override public void run() { if (Thread.currentThread().getId() != tid) { if (currentSpan != null) { traceContext.push(currentSpan); SpanExtensionFactory.logStartedSpan(currentSpan); } } try { wrappedRunnable.run(); } finally { if (Thread.currentThread().getId() != tid) { if (currentSpan != null) { traceContext.pop(); } } } } }
SofaTracerRunnable implements Runnable { @Override public void run() { if (Thread.currentThread().getId() != tid) { if (currentSpan != null) { traceContext.push(currentSpan); SpanExtensionFactory.logStartedSpan(currentSpan); } } try { wrappedRunnable.run(); } finally { if (Thread.currentThread().getId() != tid) { if (currentSpan != null) { traceContext.pop(); } } } } SofaTracerRunnable(Runnable wrappedRunnable);  SofaTracerRunnable(Runnable wrappedRunnable, SofaTraceContext traceContext); }
SofaTracerRunnable implements Runnable { @Override public void run() { if (Thread.currentThread().getId() != tid) { if (currentSpan != null) { traceContext.push(currentSpan); SpanExtensionFactory.logStartedSpan(currentSpan); } } try { wrappedRunnable.run(); } finally { if (Thread.currentThread().getId() != tid) { if (currentSpan != null) { traceContext.pop(); } } } } SofaTracerRunnable(Runnable wrappedRunnable);  SofaTracerRunnable(Runnable wrappedRunnable, SofaTraceContext traceContext); @Override void run(); }
SofaTracerRunnable implements Runnable { @Override public void run() { if (Thread.currentThread().getId() != tid) { if (currentSpan != null) { traceContext.push(currentSpan); SpanExtensionFactory.logStartedSpan(currentSpan); } } try { wrappedRunnable.run(); } finally { if (Thread.currentThread().getId() != tid) { if (currentSpan != null) { traceContext.pop(); } } } } SofaTracerRunnable(Runnable wrappedRunnable);  SofaTracerRunnable(Runnable wrappedRunnable, SofaTraceContext traceContext); @Override void run();  }