Search in sources :

Example 1 with MethodDescriptor

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

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();
}
Also used : JdbcUrlParser(com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcUrlParser) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) Driver(java.sql.Driver) Matchers.anyString(org.mockito.Matchers.anyString) MethodDescriptor(com.navercorp.pinpoint.bootstrap.context.MethodDescriptor) Test(org.junit.Test)

Example 3 with MethodDescriptor

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);
}
Also used : JdbcUrlParser(com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcUrlParser) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) Driver(java.sql.Driver) Matchers.anyString(org.mockito.Matchers.anyString) MethodDescriptor(com.navercorp.pinpoint.bootstrap.context.MethodDescriptor) Test(org.junit.Test)

Example 4 with MethodDescriptor

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;
}
Also used : MethodDescriptor(com.navercorp.pinpoint.bootstrap.context.MethodDescriptor)

Example 5 with MethodDescriptor

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));
}
Also used : DefaultMethodDescriptor(com.navercorp.pinpoint.profiler.context.DefaultMethodDescriptor) EnhancedDataSender(com.navercorp.pinpoint.profiler.sender.EnhancedDataSender) TBase(org.apache.thrift.TBase) MethodDescriptor(com.navercorp.pinpoint.bootstrap.context.MethodDescriptor) DefaultMethodDescriptor(com.navercorp.pinpoint.profiler.context.DefaultMethodDescriptor) Test(org.junit.Test)

Aggregations

MethodDescriptor (com.navercorp.pinpoint.bootstrap.context.MethodDescriptor)5 Test (org.junit.Test)4 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)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 DefaultMethodDescriptor (com.navercorp.pinpoint.profiler.context.DefaultMethodDescriptor)1 ApplicationContext (com.navercorp.pinpoint.profiler.context.module.ApplicationContext)1 InstrumentEngine (com.navercorp.pinpoint.profiler.instrument.InstrumentEngine)1 EnhancedDataSender (com.navercorp.pinpoint.profiler.sender.EnhancedDataSender)1 TBase (org.apache.thrift.TBase)1