Search in sources :

Example 1 with StandardHostValveInvokeInterceptor

use of com.navercorp.pinpoint.plugin.tomcat.interceptor.StandardHostValveInvokeInterceptor 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 2 with StandardHostValveInvokeInterceptor

use of com.navercorp.pinpoint.plugin.tomcat.interceptor.StandardHostValveInvokeInterceptor 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 3 with StandardHostValveInvokeInterceptor

use of com.navercorp.pinpoint.plugin.tomcat.interceptor.StandardHostValveInvokeInterceptor in project pinpoint by naver.

the class InvokeMethodInterceptorTest method testHeaderNOTExists.

@Test
public void testHeaderNOTExists() {
    when(request.getRequestURI()).thenReturn("/hellotest.nhn");
    when(request.getRemoteAddr()).thenReturn("10.0.0.1");
    when(request.getHeader(Header.HTTP_TRACE_ID.toString())).thenReturn(null);
    when(request.getHeader(Header.HTTP_PARENT_SPAN_ID.toString())).thenReturn(null);
    when(request.getHeader(Header.HTTP_SPAN_ID.toString())).thenReturn(null);
    when(request.getHeader(Header.HTTP_SAMPLED.toString())).thenReturn(null);
    when(request.getHeader(Header.HTTP_FLAGS.toString())).thenReturn(null);
    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)).newTraceObject();
    interceptor.before("target", new Object[] { request, response });
    interceptor.after("target", new Object[] { request, response }, new Object(), null);
    verify(traceContext, times(2)).newTraceObject();
}
Also used : TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) StandardHostValveInvokeInterceptor(com.navercorp.pinpoint.plugin.tomcat.interceptor.StandardHostValveInvokeInterceptor) Test(org.junit.Test)

Aggregations

TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)3 StandardHostValveInvokeInterceptor (com.navercorp.pinpoint.plugin.tomcat.interceptor.StandardHostValveInvokeInterceptor)3 Test (org.junit.Test)3 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)2 DefaultTraceId (com.navercorp.pinpoint.profiler.context.id.DefaultTraceId)2