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