Search in sources :

Example 16 with TraceContext

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

the class SpanSimpleAroundInterceptorTest method beforeExceptionLifeCycle.

@Test
public void beforeExceptionLifeCycle() throws Exception {
    Trace trace = newTrace();
    TraceContext context = newTraceContext(trace);
    TestSpanSimpleAroundInterceptor interceptor = new TestSpanSimpleAroundInterceptor(context) {

        @Override
        protected void doInBeforeTrace(SpanRecorder trace, Object target, Object[] args) {
            touchBefore();
            throw new RuntimeException();
        }
    };
    checkSpanInterceptor(context, interceptor);
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) Test(org.junit.Test)

Example 17 with TraceContext

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

the class SpanSimpleAroundInterceptorTest method newTraceContext.

private TraceContext newTraceContext(final Trace trace) {
    final Answer answer = new Answer() {

        private boolean stop = false;

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final String methodName = invocation.getMethod().getName();
            if (methodName.equals("removeTraceObject")) {
                stop = true;
            }
            if (stop) {
                return null;
            }
            return trace;
        }
    };
    TraceContext traceContext = mock(TraceContext.class);
    when(traceContext.currentRawTraceObject()).thenAnswer(answer);
    when(traceContext.newTraceObject()).thenAnswer(answer);
    when(traceContext.removeTraceObject()).thenAnswer(answer);
    return traceContext;
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext)

Example 18 with TraceContext

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

the class SpanSimpleAroundInterceptorTest method beforeAfterExceptionLifeCycle.

@Test
public void beforeAfterExceptionLifeCycle() throws Exception {
    Trace trace = newTrace();
    TraceContext context = newTraceContext(trace);
    TestSpanSimpleAroundInterceptor interceptor = new TestSpanSimpleAroundInterceptor(context) {

        @Override
        protected void doInBeforeTrace(SpanRecorder recorder, Object target, Object[] args) {
            touchBefore();
            throw new RuntimeException();
        }

        @Override
        protected void doInAfterTrace(SpanRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
            touchAfter();
            throw new RuntimeException();
        }
    };
    checkSpanInterceptor(context, interceptor);
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) Test(org.junit.Test)

Example 19 with TraceContext

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

the class DriverConnectInterceptorTest method driverConnect_return_Null_NPEtest.

@Test
public void driverConnect_return_Null_NPEtest() throws SQLException {
    TraceContext traceContext = mock(TraceContext.class);
    MethodDescriptor methodDescriptor = mock(MethodDescriptor.class);
    JdbcUrlParser parser = mock(JdbcUrlParser.class);
    when(parser.parse(anyString())).thenReturn(UnKnownDatabaseInfo.INSTANCE);
    String invalidJdbcUrl = "invalidUrl";
    final Driver driver = mock(Driver.class);
    SpanEventRecorder spanEventRecorder = mock(SpanEventRecorder.class);
    DriverConnectInterceptor driverConnectInterceptor = new DriverConnectInterceptor(traceContext, methodDescriptor, parser);
    driverConnectInterceptor.prepareAfterTrace(driver, va(invalidJdbcUrl), null, null);
    driverConnectInterceptor.doInAfterTrace(spanEventRecorder, driver, va(invalidJdbcUrl), null, null);
}
Also used : JdbcUrlParser(com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcUrlParser) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) Driver(java.sql.Driver) Matchers.anyString(org.mockito.Matchers.anyString) MethodDescriptor(com.navercorp.pinpoint.bootstrap.context.MethodDescriptor) Test(org.junit.Test)

Example 20 with TraceContext

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

the class InvokeMethodInterceptorTest method testInvalidHeaderExists.

/**
     * Test invalid header exists.
     */
@SuppressWarnings("unchecked")
@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");
    final Enumeration<?> enumeration = mock(Enumeration.class);
    when(request.getParameterNames()).thenReturn((Enumeration<String>) enumeration);
    TraceContext traceContext = spyTraceContext();
    final 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.jboss.interceptor.StandardHostValveInvokeInterceptor) Test(org.junit.Test)

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