Search in sources :

Example 11 with TraceContext

use of com.navercorp.pinpoint.bootstrap.context.TraceContext in project pinpoint by naver.

the class InvokeMethodInterceptorTest method testValidHeaderExists.

@Test
public void testValidHeaderExists() {
    when(request.getRequestURI()).thenReturn("/hellotest.nhn");
    when(request.getRemoteAddr()).thenReturn("10.0.0.1");
    TraceId traceId = new DefaultTraceId("agentTest", System.currentTimeMillis(), 1);
    when(request.getHeader(Header.HTTP_TRACE_ID.toString())).thenReturn(traceId.getTransactionId());
    when(request.getHeader(Header.HTTP_PARENT_SPAN_ID.toString())).thenReturn("PARENTSPANID");
    when(request.getHeader(Header.HTTP_SPAN_ID.toString())).thenReturn("SPANID");
    when(request.getHeader(Header.HTTP_SAMPLED.toString())).thenReturn("false");
    when(request.getHeader(Header.HTTP_FLAGS.toString())).thenReturn("0");
    Enumeration<?> enumeration = mock(Enumeration.class);
    when(request.getParameterNames()).thenReturn(enumeration);
    TraceContext traceContext = spyTraceContext();
    StandardHostValveInvokeInterceptor interceptor = new StandardHostValveInvokeInterceptor(traceContext, descriptor);
    interceptor.before("target", new Object[] { request, response });
    interceptor.after("target", new Object[] { request, response }, new Object(), null);
    verify(traceContext, times(1)).continueTraceObject(any(TraceId.class));
    interceptor.before("target", new Object[] { request, response });
    interceptor.after("target", new Object[] { request, response }, new Object(), null);
    verify(traceContext, times(2)).continueTraceObject(any(TraceId.class));
}
Also used : DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) StandardHostValveInvokeInterceptor(com.navercorp.pinpoint.plugin.tomcat.interceptor.StandardHostValveInvokeInterceptor) Test(org.junit.Test)

Example 12 with TraceContext

use of com.navercorp.pinpoint.bootstrap.context.TraceContext in project pinpoint by naver.

the class InvokeMethodInterceptorTest method testInvalidHeaderExists.

@Test
public void testInvalidHeaderExists() {
    when(request.getRequestURI()).thenReturn("/hellotest.nhn");
    when(request.getRemoteAddr()).thenReturn("10.0.0.1");
    when(request.getHeader(Header.HTTP_TRACE_ID.toString())).thenReturn("TRACEID");
    when(request.getHeader(Header.HTTP_PARENT_SPAN_ID.toString())).thenReturn("PARENTSPANID");
    when(request.getHeader(Header.HTTP_SPAN_ID.toString())).thenReturn("SPANID");
    when(request.getHeader(Header.HTTP_SAMPLED.toString())).thenReturn("false");
    when(request.getHeader(Header.HTTP_FLAGS.toString())).thenReturn("0");
    Enumeration<?> enumeration = mock(Enumeration.class);
    when(request.getParameterNames()).thenReturn(enumeration);
    TraceContext traceContext = spyTraceContext();
    StandardHostValveInvokeInterceptor interceptor = new StandardHostValveInvokeInterceptor(traceContext, descriptor);
    interceptor.before("target", new Object[] { request, response });
    interceptor.after("target", new Object[] { request, response }, new Object(), null);
    verify(traceContext, never()).newTraceObject();
    verify(traceContext, never()).disableSampling();
    verify(traceContext, never()).continueTraceObject(any(TraceId.class));
    interceptor.before("target", new Object[] { request, response });
    interceptor.after("target", new Object[] { request, response }, new Object(), null);
    verify(traceContext, never()).newTraceObject();
    verify(traceContext, never()).disableSampling();
    verify(traceContext, never()).continueTraceObject(any(TraceId.class));
}
Also used : TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) StandardHostValveInvokeInterceptor(com.navercorp.pinpoint.plugin.tomcat.interceptor.StandardHostValveInvokeInterceptor) Test(org.junit.Test)

Example 13 with TraceContext

use of com.navercorp.pinpoint.bootstrap.context.TraceContext in project pinpoint by naver.

the class InvokeMethodInterceptorTest method spyTraceContext.

private TraceContext spyTraceContext() {
    ProfilerConfig profilerConfig = new DefaultProfilerConfig();
    TraceContext traceContext = MockTraceContextFactory.newTestTraceContext(profilerConfig);
    return spy(traceContext);
}
Also used : ProfilerConfig(com.navercorp.pinpoint.bootstrap.config.ProfilerConfig) DefaultProfilerConfig(com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig) DefaultProfilerConfig(com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext)

Example 14 with TraceContext

use of com.navercorp.pinpoint.bootstrap.context.TraceContext in project pinpoint by naver.

the class PluginTestAgent method initialize.

@Override
public void initialize(boolean createTraceObject) {
    if (createTraceObject) {
        final TraceContext traceContext = getTraceContext();
        traceContext.newTraceObject();
    }
    getRecorder().clear();
    getTestTcpDataSender().clear();
    ignoredServiceTypes.clear();
}
Also used : TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext)

Example 15 with TraceContext

use of com.navercorp.pinpoint.bootstrap.context.TraceContext in project pinpoint by naver.

the class PluginTestAgent method cleanUp.

@Override
public void cleanUp(boolean detachTraceObject) {
    if (detachTraceObject) {
        final TraceContext traceContext = getTraceContext();
        traceContext.removeTraceObject();
    }
    getRecorder().clear();
    getTestTcpDataSender().clear();
    ignoredServiceTypes.clear();
}
Also used : TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext)

Aggregations

TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)25 Test (org.junit.Test)17 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)8 DefaultProfilerConfig (com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig)5 ProfilerConfig (com.navercorp.pinpoint.bootstrap.config.ProfilerConfig)5 DefaultTraceId (com.navercorp.pinpoint.profiler.context.id.DefaultTraceId)5 SpanRecorder (com.navercorp.pinpoint.bootstrap.context.SpanRecorder)4 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)4 MethodDescriptor (com.navercorp.pinpoint.bootstrap.context.MethodDescriptor)3 StandardHostValveInvokeInterceptor (com.navercorp.pinpoint.plugin.jboss.interceptor.StandardHostValveInvokeInterceptor)3 StandardHostValveInvokeInterceptor (com.navercorp.pinpoint.plugin.tomcat.interceptor.StandardHostValveInvokeInterceptor)3 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)2 JdbcUrlParser (com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcUrlParser)2 Driver (java.sql.Driver)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)1 InstrumentContext (com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext)1 InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)1 DatabaseInfoAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor)1 DefaultTransactionCounter (com.navercorp.pinpoint.profiler.context.id.DefaultTransactionCounter)1