use of com.navercorp.pinpoint.bootstrap.context.MethodDescriptor 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.MethodDescriptor in project pinpoint by naver.
the class DriverConnectInterceptorTest method driverConnect.
@Test
public void driverConnect() 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";
Driver driver = mock(Driver.class);
DatabaseInfoAccessor setAccessor = mock(DatabaseInfoAccessor.class);
DatabaseInfoAccessor getAccessor = mock(DatabaseInfoAccessor.class);
SpanEventRecorder spanEventRecorder = mock(SpanEventRecorder.class);
DriverConnectInterceptor driverConnectInterceptor = new DriverConnectInterceptor(traceContext, methodDescriptor, parser);
driverConnectInterceptor.prepareAfterTrace(driver, va(invalidJdbcUrl), setAccessor, null);
driverConnectInterceptor.doInAfterTrace(spanEventRecorder, driver, va(invalidJdbcUrl), getAccessor, null);
verify(setAccessor, times(1))._$PINPOINT$_setDatabaseInfo(UnKnownDatabaseInfo.INSTANCE);
verify(getAccessor, times(1))._$PINPOINT$_getDatabaseInfo();
}
use of com.navercorp.pinpoint.bootstrap.context.MethodDescriptor 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.MethodDescriptor in project pinpoint by naver.
the class InvokeCodeGenerator method getApiId.
protected int getApiId() {
final MethodDescriptor descriptor = targetMethod.getDescriptor();
final int apiId = apiMetaDataService.cacheApi(descriptor);
return apiId;
}
use of com.navercorp.pinpoint.bootstrap.context.MethodDescriptor in project pinpoint by naver.
the class DefaultApiMetaDataServiceTest method cacheApi.
@Test
public void cacheApi() throws Exception {
EnhancedDataSender dataSender = mock(EnhancedDataSender.class);
ApiMetaDataService apiMetaDataService = new DefaultApiMetaDataService("agentId", System.currentTimeMillis(), dataSender);
MethodDescriptor methodDescriptor = new DefaultMethodDescriptor("clazz", "method", null, null);
int first = apiMetaDataService.cacheApi(methodDescriptor);
Assert.assertNotEquals("not exist", first, 0);
verify(dataSender, times(1)).request(any(TBase.class));
int second = apiMetaDataService.cacheApi(methodDescriptor);
Assert.assertEquals("check cache", first, second);
verify(dataSender, times(1)).request(any(TBase.class));
}
Aggregations