Prepare for improving sampling performance.
This commit is contained in:
parent
5b853ec38b
commit
19f2a561c9
|
|
@ -0,0 +1,26 @@
|
|||
package org.skywalking.apm.agent.core.context;
|
||||
|
||||
import org.skywalking.apm.trace.Span;
|
||||
|
||||
/**
|
||||
* The <code>AbstractTracingContext</code> provides the major methods of all context implementations.
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public interface AbstractTracingContext {
|
||||
Span createSpan(String operationName, boolean isLeaf);
|
||||
|
||||
Span createSpan(String operationName, long startTime, boolean isLeaf);
|
||||
|
||||
Span activeSpan();
|
||||
|
||||
void stopSpan(Span span, Long endTime);
|
||||
|
||||
void stopSpan(Span span);
|
||||
|
||||
void inject(ContextCarrier carrier);
|
||||
|
||||
AbstractTracingContext extract(ContextCarrier carrier);
|
||||
|
||||
String getGlobalTraceId();
|
||||
}
|
||||
|
|
@ -12,8 +12,8 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* {@link ContextCarrier} is a data carrier of {@link TracerContext}.
|
||||
* It holds the snapshot (current state) of {@link TracerContext}.
|
||||
* {@link ContextCarrier} is a data carrier of {@link TracingContext}.
|
||||
* It holds the snapshot (current state) of {@link TracingContext}.
|
||||
* <p>
|
||||
* Created by wusheng on 2017/2/17.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -5,38 +5,38 @@ import org.skywalking.apm.trace.Span;
|
|||
import org.skywalking.apm.trace.TraceSegment;
|
||||
|
||||
/**
|
||||
* {@link TracerContext} controls the whole context of {@link TraceSegment}. Any {@link TraceSegment} relates to
|
||||
* {@link TracingContext} controls the whole context of {@link TraceSegment}. Any {@link TraceSegment} relates to
|
||||
* single-thread, so this context use {@link ThreadLocal} to maintain the context, and make sure, since a {@link
|
||||
* TraceSegment} starts, all ChildOf spans are in the same context.
|
||||
* <p>
|
||||
* What is 'ChildOf'? {@see https://github.com/opentracing/specification/blob/master/specification.md#references-between-spans}
|
||||
* <p>
|
||||
* Also, {@link ContextManager} delegates to all {@link TracerContext}'s major methods: {@link
|
||||
* TracerContext#createSpan(String)}, {@link TracerContext#activeSpan()}, {@link TracerContext#stopSpan(Span)}
|
||||
* Also, {@link ContextManager} delegates to all {@link TracingContext}'s major methods: {@link
|
||||
* TracingContext#createSpan(String, boolean)}, {@link TracingContext#activeSpan()}, {@link TracingContext#stopSpan(Span)}
|
||||
* <p>
|
||||
* Created by wusheng on 2017/2/17.
|
||||
*/
|
||||
public class ContextManager implements TracerContextListener, BootService {
|
||||
private static ThreadLocal<TracerContext> CONTEXT = new ThreadLocal<TracerContext>();
|
||||
private static ThreadLocal<AbstractTracingContext> CONTEXT = new ThreadLocal<AbstractTracingContext>();
|
||||
|
||||
private static TracerContext get() {
|
||||
TracerContext segment = CONTEXT.get();
|
||||
private static AbstractTracingContext get() {
|
||||
AbstractTracingContext segment = CONTEXT.get();
|
||||
if (segment == null) {
|
||||
segment = new TracerContext();
|
||||
segment = new TracingContext();
|
||||
CONTEXT.set(segment);
|
||||
}
|
||||
return segment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see {@link TracerContext#inject(ContextCarrier)}
|
||||
* @see {@link TracingContext#inject(ContextCarrier)}
|
||||
*/
|
||||
public static void inject(ContextCarrier carrier) {
|
||||
get().inject(carrier);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see {@link TracerContext#extract(ContextCarrier)}
|
||||
* @see {@link TracingContext#extract(ContextCarrier)}
|
||||
*/
|
||||
public static void extract(ContextCarrier carrier) {
|
||||
get().extract(carrier);
|
||||
|
|
@ -46,7 +46,7 @@ public class ContextManager implements TracerContextListener, BootService {
|
|||
* @return the first global trace id if exist. Otherwise, "N/A".
|
||||
*/
|
||||
public static String getGlobalTraceId() {
|
||||
TracerContext segment = CONTEXT.get();
|
||||
AbstractTracingContext segment = CONTEXT.get();
|
||||
if (segment == null) {
|
||||
return "N/A";
|
||||
} else {
|
||||
|
|
@ -88,7 +88,7 @@ public class ContextManager implements TracerContextListener, BootService {
|
|||
|
||||
@Override
|
||||
public void bootUp() {
|
||||
TracerContext.ListenerManager.add(this);
|
||||
TracingContext.ListenerManager.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ package org.skywalking.apm.agent.core.context;
|
|||
import org.skywalking.apm.trace.TraceSegment;
|
||||
|
||||
/**
|
||||
* {@link TracerContextListener} is a status change listener of {@link TracerContext}.
|
||||
* Add a {@link TracerContextListener} implementation through {@link TracerContext}
|
||||
* {@link TracerContextListener} is a status change listener of {@link TracingContext}.
|
||||
* Add a {@link TracerContextListener} implementation through {@link TracingContext}
|
||||
* <p>
|
||||
* All this class's methods will be called concurrently. Make sure all implementations are thread-safe.
|
||||
* <p>
|
||||
|
|
@ -12,7 +12,7 @@ import org.skywalking.apm.trace.TraceSegment;
|
|||
*/
|
||||
public interface TracerContextListener {
|
||||
/**
|
||||
* This method will be called, after the {@link TracerContext#finish()}
|
||||
* This method will be called, after the {@link TracingContext#finish()}
|
||||
*
|
||||
* @param traceSegment finished {@link TraceSegment}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* {@link TracerContext} maintains the context.
|
||||
* {@link TracingContext} maintains the context.
|
||||
* You manipulate (create/finish/get) spans and (inject/extract) context.
|
||||
* <p>
|
||||
* Created by wusheng on 2017/2/17.
|
||||
*/
|
||||
public final class TracerContext {
|
||||
public final class TracingContext implements AbstractTracingContext {
|
||||
private TraceSegment segment;
|
||||
|
||||
/**
|
||||
|
|
@ -34,7 +34,7 @@ public final class TracerContext {
|
|||
/**
|
||||
* Create a {@link TraceSegment} and init {@link #spanIdGenerator} as 0;
|
||||
*/
|
||||
TracerContext() {
|
||||
TracingContext() {
|
||||
this.segment = new TraceSegment(Config.Agent.APPLICATION_CODE);
|
||||
ServiceManager.INSTANCE.findService(SamplingService.class).trySampling(this.segment);
|
||||
this.spanIdGenerator = 0;
|
||||
|
|
@ -106,7 +106,7 @@ public final class TracerContext {
|
|||
/**
|
||||
* @return the current trace id.
|
||||
*/
|
||||
String getGlobalTraceId() {
|
||||
public String getGlobalTraceId() {
|
||||
return segment.getRelatedGlobalTraces().get(0).get();
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +138,7 @@ public final class TracerContext {
|
|||
}
|
||||
|
||||
/**
|
||||
* Give a snapshot of this {@link TracerContext},
|
||||
* Give a snapshot of this {@link TracingContext},
|
||||
* and save current state to the given {@link ContextCarrier}.
|
||||
*
|
||||
* @param carrier holds the snapshot
|
||||
|
|
@ -165,12 +165,13 @@ public final class TracerContext {
|
|||
* @param carrier holds the snapshot, if get this {@link ContextCarrier} from remote, make sure {@link
|
||||
* ContextCarrier#deserialize(String)} called.
|
||||
*/
|
||||
public void extract(ContextCarrier carrier) {
|
||||
public AbstractTracingContext extract(ContextCarrier carrier) {
|
||||
if (carrier.isValid()) {
|
||||
this.segment.ref(getRef(carrier));
|
||||
ServiceManager.INSTANCE.findService(SamplingService.class).setSampleWhenExtract(this.segment, carrier);
|
||||
this.segment.relatedGlobalTraces(carrier.getDistributedTraceIds());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private TraceSegmentRef getRef(ContextCarrier carrier) {
|
||||
|
|
@ -6,7 +6,7 @@ import com.lmax.disruptor.dsl.Disruptor;
|
|||
import com.lmax.disruptor.util.DaemonThreadFactory;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.boot.StatusBootService;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.agent.core.context.TracerContextListener;
|
||||
import org.skywalking.apm.logging.ILog;
|
||||
import org.skywalking.apm.logging.LogManager;
|
||||
|
|
@ -40,7 +40,7 @@ public class TraceSegmentProcessQueue extends StatusBootService implements Trace
|
|||
|
||||
@Override
|
||||
protected void bootUpWithStatus() {
|
||||
TracerContext.ListenerManager.add(this);
|
||||
TracingContext.ListenerManager.add(this);
|
||||
disruptor.start();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class ContextManagerTestCase {
|
|||
|
||||
Assert.assertEquals(span, ContextManager.activeSpan());
|
||||
|
||||
TracerContext.ListenerManager.add(TestTracerContextListener.INSTANCE);
|
||||
TracingContext.ListenerManager.add(TestTracerContextListener.INSTANCE);
|
||||
ContextManager.stopSpan();
|
||||
|
||||
TraceSegment segment = TestTracerContextListener.INSTANCE.finishedSegmentCarrier[0];
|
||||
|
|
@ -35,6 +35,6 @@ public class ContextManagerTestCase {
|
|||
|
||||
@After
|
||||
public void reset() {
|
||||
TracerContext.ListenerManager.remove(TestTracerContextListener.INSTANCE);
|
||||
TracingContext.ListenerManager.remove(TestTracerContextListener.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,15 +15,15 @@ import java.util.List;
|
|||
/**
|
||||
* Created by wusheng on 2017/2/19.
|
||||
*/
|
||||
public class TracerContextTestCase {
|
||||
public class TracingContextTestCase {
|
||||
@Test
|
||||
public void testSpanLifeCycle() {
|
||||
TracerContext context = new TracerContext();
|
||||
TracingContext context = new TracingContext();
|
||||
Span span = context.createSpan("/serviceA", false);
|
||||
|
||||
Assert.assertEquals(span, context.activeSpan());
|
||||
|
||||
TracerContext.ListenerManager.add(TestTracerContextListener.INSTANCE);
|
||||
TracingContext.ListenerManager.add(TestTracerContextListener.INSTANCE);
|
||||
final TraceSegment[] finishedSegmentCarrier = TestTracerContextListener.INSTANCE.finishedSegmentCarrier;
|
||||
context.stopSpan(span);
|
||||
|
||||
|
|
@ -34,13 +34,13 @@ public class TracerContextTestCase {
|
|||
|
||||
@Test
|
||||
public void testChildOfSpan() {
|
||||
TracerContext context = new TracerContext();
|
||||
TracingContext context = new TracingContext();
|
||||
Span serviceSpan = context.createSpan("/serviceA", false);
|
||||
Span dbSpan = context.createSpan("db/preparedStatement/execute", false);
|
||||
|
||||
Assert.assertEquals(dbSpan, context.activeSpan());
|
||||
|
||||
TracerContext.ListenerManager.add(TestTracerContextListener.INSTANCE);
|
||||
TracingContext.ListenerManager.add(TestTracerContextListener.INSTANCE);
|
||||
final TraceSegment[] finishedSegmentCarrier = TestTracerContextListener.INSTANCE.finishedSegmentCarrier;
|
||||
|
||||
try {
|
||||
|
|
@ -59,7 +59,7 @@ public class TracerContextTestCase {
|
|||
|
||||
@Test
|
||||
public void testInject() {
|
||||
TracerContext context = new TracerContext();
|
||||
TracingContext context = new TracingContext();
|
||||
Span serviceSpan = context.createSpan("/serviceA", false);
|
||||
Span dbSpan = context.createSpan("db/preparedStatement/execute", false);
|
||||
Tags.PEER_HOST.set(dbSpan, "127.0.0.1");
|
||||
|
|
@ -85,11 +85,11 @@ public class TracerContextTestCase {
|
|||
|
||||
Assert.assertTrue(carrier.isValid());
|
||||
|
||||
TracerContext context = new TracerContext();
|
||||
TracingContext context = new TracingContext();
|
||||
context.extract(carrier);
|
||||
Span span = context.createSpan("/serviceC", false);
|
||||
|
||||
TracerContext.ListenerManager.add(TestTracerContextListener.INSTANCE);
|
||||
TracingContext.ListenerManager.add(TestTracerContextListener.INSTANCE);
|
||||
final TraceSegment[] finishedSegmentCarrier = TestTracerContextListener.INSTANCE.finishedSegmentCarrier;
|
||||
|
||||
context.stopSpan(span);
|
||||
|
|
@ -100,6 +100,6 @@ public class TracerContextTestCase {
|
|||
|
||||
@After
|
||||
public void reset() {
|
||||
TracerContext.ListenerManager.remove(TestTracerContextListener.INSTANCE);
|
||||
TracingContext.ListenerManager.remove(TestTracerContextListener.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
|||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
|
@ -67,7 +67,7 @@ public class DubboInterceptorTest {
|
|||
dubboInterceptor = new DubboInterceptor();
|
||||
testParam = new RequestParamForTestBelow283();
|
||||
mockTracerContextListener = new MockTracerContextListener();
|
||||
TracerContext.ListenerManager.add(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.add(mockTracerContextListener);
|
||||
|
||||
mockStatic(RpcContext.class);
|
||||
mockStatic(BugFixActive.class);
|
||||
|
|
@ -227,7 +227,7 @@ public class DubboInterceptorTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
TracerContext.ListenerManager.remove(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.remove(mockTracerContextListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import org.mockito.Mock;
|
|||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import org.skywalking.apm.sniffer.mock.context.MockTracerContextListener;
|
||||
|
|
@ -60,7 +60,7 @@ public class DefaultHttpClientInterceptorTest {
|
|||
ServiceManager.INSTANCE.boot();
|
||||
defaultHttpClientInterceptor = new DefaultHttpClientInterceptor();
|
||||
|
||||
TracerContext.ListenerManager.add(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.add(mockTracerContextListener);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import org.powermock.api.mockito.PowerMockito;
|
|||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import org.skywalking.apm.sniffer.mock.context.MockTracerContextListener;
|
||||
|
|
@ -77,7 +77,7 @@ public class HttpClientExecuteInterceptorTest {
|
|||
});
|
||||
when(httpHost.getPort()).thenReturn(8080);
|
||||
|
||||
TracerContext.ListenerManager.add(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.add(mockTracerContextListener);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -153,7 +153,7 @@ public class HttpClientExecuteInterceptorTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
TracerContext.ListenerManager.remove(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.remove(mockTracerContextListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import org.mockito.Matchers;
|
|||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.sniffer.mock.context.MockTracerContextListener;
|
||||
import org.skywalking.apm.sniffer.mock.context.SegmentAssert;
|
||||
import org.skywalking.apm.trace.Span;
|
||||
|
|
@ -74,7 +74,7 @@ public class SWCallableStatementTest extends AbstractStatementTest {
|
|||
swConnection = new SWConnection("jdbc:mysql://127.0.0.1:3306/test", new Properties(), jdbcConnection);
|
||||
multiHostConnection = new SWConnection("jdbc:mysql://127.0.0.1:3306,127.0.0.1:3309/test", new Properties(), jdbcConnection);
|
||||
|
||||
TracerContext.ListenerManager.add(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.add(mockTracerContextListener);
|
||||
|
||||
when(jdbcConnection.prepareCall(anyString())).thenReturn(mysqlCallableStatement);
|
||||
when(jdbcConnection.prepareCall(anyString(), anyInt(), anyInt(), anyInt())).thenReturn(mysqlCallableStatement);
|
||||
|
|
@ -724,7 +724,7 @@ public class SWCallableStatementTest extends AbstractStatementTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
TracerContext.ListenerManager.remove(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.remove(mockTracerContextListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import org.junit.runner.RunWith;
|
|||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.sniffer.mock.context.MockTracerContextListener;
|
||||
import org.skywalking.apm.sniffer.mock.context.SegmentAssert;
|
||||
import org.skywalking.apm.trace.TraceSegment;
|
||||
|
|
@ -48,7 +48,7 @@ public class SWConnectionTest extends AbstractStatementTest {
|
|||
swConnection = new SWConnection("jdbc:mysql://127.0.0.1:3306/test", new Properties(), jdbcConnection);
|
||||
multiHostConnection = new SWConnection("jdbc:mysql://127.0.0.1:3306,127.0.0.1:3309/test", new Properties(), jdbcConnection);
|
||||
|
||||
TracerContext.ListenerManager.add(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.add(mockTracerContextListener);
|
||||
|
||||
when(jdbcConnection.prepareStatement(anyString())).thenReturn(mysqlPreparedStatement);
|
||||
}
|
||||
|
|
@ -350,7 +350,7 @@ public class SWConnectionTest extends AbstractStatementTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
TracerContext.ListenerManager.remove(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.remove(mockTracerContextListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import org.junit.runner.RunWith;
|
|||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.sniffer.mock.context.MockTracerContextListener;
|
||||
import org.skywalking.apm.sniffer.mock.context.SegmentAssert;
|
||||
import org.skywalking.apm.trace.Span;
|
||||
|
|
@ -46,7 +46,7 @@ public class SWStatementTest extends AbstractStatementTest {
|
|||
swConnection = new SWConnection("jdbc:mysql://127.0.0.1:3306/test", new Properties(), jdbcConnection);
|
||||
multiHostConnection = new SWConnection("jdbc:mysql://127.0.0.1:3306,127.0.0.1:3309/test", new Properties(), jdbcConnection);
|
||||
|
||||
TracerContext.ListenerManager.add(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.add(mockTracerContextListener);
|
||||
|
||||
when(jdbcConnection.createStatement()).thenReturn(mysqlStatement);
|
||||
when(jdbcConnection.createStatement(anyInt(), anyInt())).thenReturn(mysqlStatement);
|
||||
|
|
@ -299,6 +299,6 @@ public class SWStatementTest extends AbstractStatementTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
TracerContext.ListenerManager.remove(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.remove(mockTracerContextListener);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import org.mockito.Matchers;
|
|||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.sniffer.mock.context.MockTracerContextListener;
|
||||
import org.skywalking.apm.sniffer.mock.context.SegmentAssert;
|
||||
import org.skywalking.apm.trace.Span;
|
||||
|
|
@ -75,7 +75,7 @@ public class SwPreparedStatementTest extends AbstractStatementTest {
|
|||
swConnection = new SWConnection("jdbc:mysql://127.0.0.1:3306/test", new Properties(), jdbcConnection);
|
||||
multiHostConnection = new SWConnection("jdbc:mysql://127.0.0.1:3306,127.0.0.1:3309/test", new Properties(), jdbcConnection);
|
||||
|
||||
TracerContext.ListenerManager.add(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.add(mockTracerContextListener);
|
||||
|
||||
when(jdbcConnection.prepareStatement(anyString())).thenReturn(mysqlPreparedStatement);
|
||||
when(jdbcConnection.prepareStatement(anyString(), anyInt(), anyInt(), anyInt())).thenReturn(mysqlPreparedStatement);
|
||||
|
|
@ -558,6 +558,6 @@ public class SwPreparedStatementTest extends AbstractStatementTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
TracerContext.ListenerManager.remove(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.remove(mockTracerContextListener);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import org.junit.runner.RunWith;
|
|||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import org.skywalking.apm.sniffer.mock.context.MockTracerContextListener;
|
||||
|
|
@ -43,7 +43,7 @@ public class JedisMethodInterceptorTest {
|
|||
interceptor = new JedisMethodInterceptor();
|
||||
mockTracerContextListener = new MockTracerContextListener();
|
||||
|
||||
TracerContext.ListenerManager.add(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.add(mockTracerContextListener);
|
||||
|
||||
when(classInstanceContext.get(KEY_OF_REDIS_HOST, String.class)).thenReturn("127.0.0.1");
|
||||
when(classInstanceContext.get(KEY_OF_REDIS_PORT)).thenReturn(6379);
|
||||
|
|
@ -140,7 +140,7 @@ public class JedisMethodInterceptorTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
TracerContext.ListenerManager.remove(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.remove(mockTracerContextListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import org.mockito.runners.MockitoJUnitRunner;
|
|||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import org.skywalking.apm.sniffer.mock.context.MockTracerContextListener;
|
||||
|
|
@ -49,7 +49,7 @@ public class MongoDBMethodInterceptorTest {
|
|||
interceptor = new MongoDBMethodInterceptor();
|
||||
mockTracerContextListener = new MockTracerContextListener();
|
||||
|
||||
TracerContext.ListenerManager.add(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.add(mockTracerContextListener);
|
||||
|
||||
Config.Plugin.MongoDB.TRACE_PARAM = true;
|
||||
|
||||
|
|
@ -121,7 +121,7 @@ public class MongoDBMethodInterceptorTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
TracerContext.ListenerManager.remove(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.remove(mockTracerContextListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import org.mockito.runners.MockitoJUnitRunner;
|
|||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.conf.Config;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import org.skywalking.apm.sniffer.mock.context.MockTracerContextListener;
|
||||
|
|
@ -52,7 +52,7 @@ public class MongoDBWriteMethodInterceptorTest {
|
|||
interceptor = new MongoDBMethodInterceptor();
|
||||
mockTracerContextListener = new MockTracerContextListener();
|
||||
|
||||
TracerContext.ListenerManager.add(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.add(mockTracerContextListener);
|
||||
|
||||
Config.Plugin.MongoDB.TRACE_PARAM = true;
|
||||
|
||||
|
|
@ -132,7 +132,7 @@ public class MongoDBWriteMethodInterceptorTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
TracerContext.ListenerManager.remove(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.remove(mockTracerContextListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import org.junit.runner.RunWith;
|
|||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import org.skywalking.apm.sniffer.mock.context.MockTracerContextListener;
|
||||
|
|
@ -52,7 +52,7 @@ public class MotanConsumerInterceptorTest {
|
|||
invokeInterceptor = new MotanConsumerInterceptor();
|
||||
url = URL.valueOf("motan://127.0.0.1:34000/org.skywalking.apm.test.TestService");
|
||||
|
||||
TracerContext.ListenerManager.add(contextListener);
|
||||
TracingContext.ListenerManager.add(contextListener);
|
||||
|
||||
when(instanceContext.get("REQUEST_URL")).thenReturn(url);
|
||||
when(interceptorContext.allArguments()).thenReturn(new Object[] {request});
|
||||
|
|
@ -134,6 +134,6 @@ public class MotanConsumerInterceptorTest {
|
|||
|
||||
@After
|
||||
public void tearDown() {
|
||||
TracerContext.ListenerManager.remove(contextListener);
|
||||
TracingContext.ListenerManager.remove(contextListener);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import org.junit.runner.RunWith;
|
|||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
|
|
@ -57,7 +57,7 @@ public class MotanProviderInterceptorTest {
|
|||
contextListener = new MockTracerContextListener();
|
||||
url = URL.valueOf("motan://127.0.0.1:34000/org.skywalking.apm.test.TestService");
|
||||
|
||||
TracerContext.ListenerManager.add(contextListener);
|
||||
TracingContext.ListenerManager.add(contextListener);
|
||||
|
||||
when(instanceContext.get("REQUEST_URL")).thenReturn(url);
|
||||
when(interceptorContext.allArguments()).thenReturn(new Object[] {request});
|
||||
|
|
@ -162,6 +162,6 @@ public class MotanProviderInterceptorTest {
|
|||
|
||||
@After
|
||||
public void tearDown() {
|
||||
TracerContext.ListenerManager.remove(contextListener);
|
||||
TracingContext.ListenerManager.remove(contextListener);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import org.mockito.Mock;
|
|||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.ConstructorInvokeContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
|
|
@ -60,7 +60,7 @@ public class RealCallInterceptorTest {
|
|||
ServiceManager.INSTANCE.boot();
|
||||
realCallInterceptor = new RealCallInterceptor();
|
||||
|
||||
TracerContext.ListenerManager.add(mockTracerContextListener);
|
||||
TracingContext.ListenerManager.add(mockTracerContextListener);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import org.junit.runner.RunWith;
|
|||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
|
@ -57,7 +57,7 @@ public class ResinV3InterceptorTest {
|
|||
interceptor = new ResinV3Interceptor();
|
||||
contextListener = new MockTracerContextListener();
|
||||
|
||||
TracerContext.ListenerManager.add(contextListener);
|
||||
TracingContext.ListenerManager.add(contextListener);
|
||||
|
||||
when(request.getPageURI()).thenReturn("/test/testRequestURL");
|
||||
when(request.getScheme()).thenReturn("http");
|
||||
|
|
@ -145,6 +145,6 @@ public class ResinV3InterceptorTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
TracerContext.ListenerManager.remove(new MockTracerContextListener());
|
||||
TracingContext.ListenerManager.remove(new MockTracerContextListener());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import org.junit.runner.RunWith;
|
|||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
|
@ -55,7 +55,7 @@ public class ResinV4InterceptorTest {
|
|||
interceptor = new ResinV4Interceptor();
|
||||
contextListener = new MockTracerContextListener();
|
||||
|
||||
TracerContext.ListenerManager.add(contextListener);
|
||||
TracingContext.ListenerManager.add(contextListener);
|
||||
|
||||
when(request.getPageURI()).thenReturn("/test/testRequestURL");
|
||||
when(request.getScheme()).thenReturn("http");
|
||||
|
|
@ -144,6 +144,6 @@ public class ResinV4InterceptorTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
TracerContext.ListenerManager.remove(new MockTracerContextListener());
|
||||
TracingContext.ListenerManager.remove(new MockTracerContextListener());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import org.junit.runner.RunWith;
|
|||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.skywalking.apm.agent.core.boot.ServiceManager;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodInvokeContext;
|
||||
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
|
@ -54,7 +54,7 @@ public class TomcatInterceptorTest {
|
|||
tomcatInterceptor = new TomcatInterceptor();
|
||||
contextListener = new MockTracerContextListener();
|
||||
|
||||
TracerContext.ListenerManager.add(contextListener);
|
||||
TracingContext.ListenerManager.add(contextListener);
|
||||
|
||||
when(request.getRequestURI()).thenReturn("/test/testRequestURL");
|
||||
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/testRequestURL"));
|
||||
|
|
@ -139,7 +139,7 @@ public class TomcatInterceptorTest {
|
|||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
TracerContext.ListenerManager.remove(new MockTracerContextListener());
|
||||
TracingContext.ListenerManager.remove(new MockTracerContextListener());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package org.skywalking.apm.sniffer.mock.context;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.agent.core.context.TracerContextListener;
|
||||
import org.skywalking.apm.trace.TraceSegment;
|
||||
|
||||
|
|
@ -10,8 +10,8 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is mock tracer context listener, which should be added by calling {@link TracerContext.ListenerManager#add(TracerContextListener)}.
|
||||
* This mock listener will hold all finished trace, which all are generated by {@link TracerContext#finish()}.
|
||||
* This is mock tracer context listener, which should be added by calling {@link TracingContext.ListenerManager#add(TracerContextListener)}.
|
||||
* This mock listener will hold all finished trace, which all are generated by {@link TracingContext#finish()}.
|
||||
* <p>
|
||||
* Created by wusheng on 2017/2/20.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package org.skywalking.apm.sniffer.mock.trace;
|
||||
|
||||
import org.skywalking.apm.agent.core.context.TracerContext;
|
||||
import org.skywalking.apm.agent.core.context.TracingContext;
|
||||
import org.skywalking.apm.sniffer.mock.context.MockTracerContextListener;
|
||||
import org.skywalking.apm.sniffer.mock.trace.builders.trace.*;
|
||||
import org.skywalking.apm.trace.TraceSegment;
|
||||
|
|
@ -53,10 +53,10 @@ public enum TraceSegmentBuilderFactory {
|
|||
private TraceSegment build(TraceSegmentBuilder builder) {
|
||||
MockTracerContextListener listener = new MockTracerContextListener();
|
||||
try {
|
||||
TracerContext.ListenerManager.add(listener);
|
||||
TracingContext.ListenerManager.add(listener);
|
||||
return builder.build(listener);
|
||||
} finally {
|
||||
TracerContext.ListenerManager.remove(listener);
|
||||
TracingContext.ListenerManager.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import org.skywalking.apm.trace.TraceSegment;
|
|||
/**
|
||||
* Created by wusheng on 2017/2/21.
|
||||
*/
|
||||
public class MockTracerContextListenerTestCase {
|
||||
public class MockTracingContextListenerTestCase {
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
ServiceManager.INSTANCE.boot();
|
||||
Loading…
Reference in New Issue