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);
}
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;
}
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);
}
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);
}
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));
}
Aggregations