Search in sources :

Example 1 with TraceContext

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

the class DefaultClassEditorBuilderTest method test.

@Test
public void test() throws Exception {
    InstrumentEngine instrumentEngine = mock(InstrumentEngine.class);
    TraceContext traceContext = mock(TraceContext.class);
    InstrumentClass aClass = mock(InstrumentClass.class);
    InstrumentMethod aMethod = mock(InstrumentMethod.class);
    MethodDescriptor aDescriptor = mock(MethodDescriptor.class);
    ApplicationContext applicationContext = mock(ApplicationContext.class);
    InstrumentContext context = mock(InstrumentContext.class);
    ClassLoader classLoader = getClass().getClassLoader();
    String className = "someClass";
    String methodName = "someMethod";
    byte[] classFileBuffer = new byte[0];
    Class<?>[] parameterTypes = new Class<?>[] { String.class };
    String[] parameterTypeNames = TypeUtils.toClassNames(parameterTypes);
    when(applicationContext.getInstrumentEngine()).thenReturn(instrumentEngine);
    when(applicationContext.getTraceContext()).thenReturn(traceContext);
    when(instrumentEngine.getClass(context, classLoader, className, classFileBuffer)).thenReturn(aClass);
    when(aClass.getDeclaredMethod(methodName, parameterTypeNames)).thenReturn(aMethod);
    when(aMethod.getName()).thenReturn(methodName);
    when(aMethod.getParameterTypes()).thenReturn(parameterTypeNames);
    when(aMethod.getDescriptor()).thenReturn(aDescriptor);
    when(aClass.addInterceptor(eq(methodName), va(eq(parameterTypeNames)))).thenReturn(0);
//        DefaultClassFileTransformerBuilder builder = new DefaultClassFileTransformerBuilder(context, "TargetClass");
//        builder.injectField("some.accessor.Type", "java.util.HashMap");
//        builder.injectGetter("some.getter.Type", "someField");
//
//        MethodTransformerBuilder ib = builder.editMethod(methodName, parameterTypeNames);
//        ib.injectInterceptor("com.navercorp.pinpoint.profiler.plugin.TestInterceptor", "provided");
//
//        ClassFileTransformer transformer = builder.build();
//
//        transformer.transform(classLoader, className, null, null, classFileBuffer);
//
//        verify(aMethod).addScopedInterceptor(eq("com.navercorp.pinpoint.profiler.plugin.TestInterceptor"), eq(va("provided")), (InterceptorScope)isNull(), (ExecutionPolicy)isNull());
//        verify(aClass).addField("some.accessor.Type", "new java.util.HashMap();");
//        verify(aClass).addGetter("some.getter.Type", "someField");
}
Also used : InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) MethodDescriptor(com.navercorp.pinpoint.bootstrap.context.MethodDescriptor) ApplicationContext(com.navercorp.pinpoint.profiler.context.module.ApplicationContext) InstrumentContext(com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentEngine(com.navercorp.pinpoint.profiler.instrument.InstrumentEngine) Test(org.junit.Test)

Example 2 with TraceContext

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

the class ObjectBinderFactory method newAnnotatedInterceptorFactory.

public AnnotatedInterceptorFactory newAnnotatedInterceptorFactory(InstrumentContext pluginContext, boolean exceptionHandle) {
    final TraceContext traceContext = this.traceContextProvider.get();
    ApiMetaDataService apiMetaDataService = this.apiMetaDataServiceProvider.get();
    return new AnnotatedInterceptorFactory(profilerConfig, traceContext, dataSourceMonitorRegistry, apiMetaDataService, pluginContext, exceptionHandle);
}
Also used : TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) ApiMetaDataService(com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService) AnnotatedInterceptorFactory(com.navercorp.pinpoint.profiler.interceptor.factory.AnnotatedInterceptorFactory)

Example 3 with TraceContext

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

the class DefaultTraceContextTest method disableTrace.

@Test
public void disableTrace() {
    ProfilerConfig profilerConfig = new DefaultProfilerConfig();
    TraceContext traceContext = MockTraceContextFactory.newTestTraceContext(profilerConfig);
    Trace trace = traceContext.disableSampling();
    Assert.assertNotNull(trace);
    Assert.assertFalse(trace.canSampled());
    traceContext.removeTraceObject();
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) 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) Test(org.junit.Test)

Example 4 with TraceContext

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

the class DefaultTraceContextTest method threadLocalBindTest.

@Test
public void threadLocalBindTest() {
    ProfilerConfig profilerConfig = new DefaultProfilerConfig();
    TraceContext traceContext = MockTraceContextFactory.newTestTraceContext(profilerConfig);
    Assert.assertNotNull(traceContext.newTraceObject());
    TraceContext traceContext2 = MockTraceContextFactory.newTestTraceContext(profilerConfig);
    Trace notExist = traceContext2.currentRawTraceObject();
    Assert.assertNull(notExist);
    Assert.assertNotNull(traceContext.currentRawTraceObject());
    traceContext.removeTraceObject();
    Assert.assertNull(traceContext.currentRawTraceObject());
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) 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) Test(org.junit.Test)

Example 5 with TraceContext

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

the class InvokeMethodInterceptorTest method testHeaderNOTExists.

/**
     * Test header not exists.
     */
@SuppressWarnings("unchecked")
@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);
    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, 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.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