Search in sources :

Example 56 with InstrumentClass

use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.

the class JavassistEngineTest method testGetClass_original.

@Test
public void testGetClass_original() throws Exception {
    InstrumentEngine instrumentEngine = newJavassistEngine();
    InstrumentContext instrumentContext = mock(InstrumentContext.class);
    final byte[] originalByteCode = BytecodeUtils.getClassFile(null, mock);
    final InstrumentClass transformClass = instrumentEngine.getClass(instrumentContext, null, mock, originalByteCode);
    Assert.assertNotNull(transformClass.getDeclaredMethod("test"));
    Assert.assertNull("transform method", transformClass.getDeclaredMethod("transformMethod"));
}
Also used : InstrumentContext(com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) Test(org.junit.Test)

Example 57 with InstrumentClass

use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.

the class InvokeAfterCodeGeneratorTest method testGenerate_AroundInterceptor3_methodParam2.

@Test
public void testGenerate_AroundInterceptor3_methodParam2() throws Exception {
    final Class<AroundInterceptor3> aroundInterceptor3Class = AroundInterceptor3.class;
    final InterceptorDefinition interceptorDefinition = interceptorDefinitionFactory.createInterceptorDefinition(aroundInterceptor3Class);
    final InstrumentClass mockClass = mock(InstrumentClass.class);
    Mockito.when(mockClass.getName()).thenReturn("TestClass");
    final InstrumentMethod mockMethod = mock(InstrumentMethod.class);
    Mockito.when(mockMethod.getName()).thenReturn("TestMethod");
    Mockito.when(mockMethod.getParameterTypes()).thenReturn(new String[] { "java.lang.Object", "java.lang.Object" });
    Mockito.when(mockMethod.getReturnType()).thenReturn("java.lang.Object");
    ApiMetaDataService apiMetaDataService = mock(ApiMetaDataService.class);
    final InvokeAfterCodeGenerator invokeAfterCodeGenerator = new InvokeAfterCodeGenerator(100, interceptorDefinition, mockClass, mockMethod, apiMetaDataService, false, true);
    final String generate = invokeAfterCodeGenerator.generate();
    logger.debug("testGenerate_AroundInterceptor3_methodParam2:{}", generate);
    Assert.assertTrue(generate.contains("($w)$1"));
    Assert.assertTrue(generate.contains("($w)$2"));
    Assert.assertFalse(generate.contains("($w)$3"));
    Assert.assertTrue(generate.contains("$e"));
}
Also used : AroundInterceptor3(com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor3) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) ApiMetaDataService(com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService) Test(org.junit.Test)

Example 58 with InstrumentClass

use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.

the class InvokeAfterCodeGeneratorTest method testGenerate_AroundInterceptor3_catchClause.

@Test
public void testGenerate_AroundInterceptor3_catchClause() throws Exception {
    final Class<AroundInterceptor3> aroundInterceptor3Class = AroundInterceptor3.class;
    final InterceptorDefinition interceptorDefinition = interceptorDefinitionFactory.createInterceptorDefinition(aroundInterceptor3Class);
    final InstrumentClass mockClass = mock(InstrumentClass.class);
    Mockito.when(mockClass.getName()).thenReturn("TestClass");
    final InstrumentMethod mockMethod = mock(InstrumentMethod.class);
    Mockito.when(mockMethod.getName()).thenReturn("TestMethod");
    Mockito.when(mockMethod.getParameterTypes()).thenReturn(new String[] { "java.lang.Object", "java.lang.Object", "java.lang.Object" });
    Mockito.when(mockMethod.getReturnType()).thenReturn("java.lang.Object");
    ApiMetaDataService apiMetaDataService = mock(ApiMetaDataService.class);
    final InvokeAfterCodeGenerator invokeAfterCodeGenerator = new InvokeAfterCodeGenerator(100, interceptorDefinition, mockClass, mockMethod, apiMetaDataService, false, true);
    final String generate = invokeAfterCodeGenerator.generate();
    logger.debug("testGenerate_AroundInterceptor3_catchClause:{}", generate);
    Assert.assertTrue(generate.contains("($w)$1"));
    Assert.assertTrue(generate.contains("($w)$2"));
    Assert.assertTrue(generate.contains("($w)$3"));
    Assert.assertTrue(generate.contains("$e"));
}
Also used : AroundInterceptor3(com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor3) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) ApiMetaDataService(com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService) Test(org.junit.Test)

Example 59 with InstrumentClass

use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.

the class InvokeAfterCodeGeneratorTest method testGenerate_AroundInterceptor3_methodParam4.

@Test
public void testGenerate_AroundInterceptor3_methodParam4() throws Exception {
    final Class<AroundInterceptor3> aroundInterceptor3Class = AroundInterceptor3.class;
    final InterceptorDefinition interceptorDefinition = interceptorDefinitionFactory.createInterceptorDefinition(aroundInterceptor3Class);
    final InstrumentClass mockClass = mock(InstrumentClass.class);
    Mockito.when(mockClass.getName()).thenReturn("TestClass");
    final InstrumentMethod mockMethod = mock(InstrumentMethod.class);
    Mockito.when(mockMethod.getName()).thenReturn("TestMethod");
    Mockito.when(mockMethod.getParameterTypes()).thenReturn(new String[] { "java.lang.Object", "java.lang.Object", "java.lang.Object", "java.lang.Object" });
    Mockito.when(mockMethod.getReturnType()).thenReturn("java.lang.Object");
    ApiMetaDataService apiMetaDataService = mock(ApiMetaDataService.class);
    final InvokeAfterCodeGenerator invokeAfterCodeGenerator = new InvokeAfterCodeGenerator(100, interceptorDefinition, mockClass, mockMethod, apiMetaDataService, false, true);
    final String generate = invokeAfterCodeGenerator.generate();
    logger.debug("testGenerate_AroundInterceptor3_methodParam4:{}", generate);
    Assert.assertTrue(generate.contains("($w)$1"));
    Assert.assertTrue(generate.contains("($w)$2"));
    Assert.assertTrue(generate.contains("($w)$3"));
    Assert.assertFalse(generate.contains("($w)$4"));
    Assert.assertTrue(generate.contains("$e"));
}
Also used : AroundInterceptor3(com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor3) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) ApiMetaDataService(com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService) Test(org.junit.Test)

Example 60 with InstrumentClass

use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass in project pinpoint by naver.

the class InvokeAfterCodeGeneratorTest method testGenerate_AroundInterceptor0.

@Test
public void testGenerate_AroundInterceptor0() throws Exception {
    final Class<AroundInterceptor0> aroundInterceptor3Class = AroundInterceptor0.class;
    final InterceptorDefinition interceptorDefinition = interceptorDefinitionFactory.createInterceptorDefinition(aroundInterceptor3Class);
    final InstrumentClass mockClass = mock(InstrumentClass.class);
    Mockito.when(mockClass.getName()).thenReturn("TestClass");
    final InstrumentMethod mockMethod = mock(InstrumentMethod.class);
    Mockito.when(mockMethod.getName()).thenReturn("TestMethod");
    Mockito.when(mockMethod.getParameterTypes()).thenReturn(new String[] {});
    Mockito.when(mockMethod.getReturnType()).thenReturn("java.lang.Object");
    ApiMetaDataService apiMetaDataService = mock(ApiMetaDataService.class);
    final InvokeAfterCodeGenerator invokeAfterCodeGenerator = new InvokeAfterCodeGenerator(100, interceptorDefinition, mockClass, mockMethod, apiMetaDataService, false, true);
    final String generate = invokeAfterCodeGenerator.generate();
    logger.debug("testGenerate_AroundInterceptor0:{}", generate);
    Assert.assertFalse(generate.contains("($w)$1"));
    Assert.assertFalse(generate.contains("($w)$2"));
    Assert.assertFalse(generate.contains("($w)$3"));
    Assert.assertTrue(generate.contains("$e"));
}
Also used : AroundInterceptor0(com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor0) InstrumentClass(com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass) InstrumentMethod(com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod) ApiMetaDataService(com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService) Test(org.junit.Test)

Aggregations

InstrumentClass (com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass)60 Instrumentor (com.navercorp.pinpoint.bootstrap.instrument.Instrumentor)44 ProtectionDomain (java.security.ProtectionDomain)44 TransformCallback (com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback)42 InstrumentMethod (com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod)30 InstrumentException (com.navercorp.pinpoint.bootstrap.instrument.InstrumentException)29 Test (org.junit.Test)18 InstrumentContext (com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext)8 InstrumentEngine (com.navercorp.pinpoint.profiler.instrument.InstrumentEngine)6 ApiMetaDataService (com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService)5 TestClassLoader (com.navercorp.pinpoint.test.classloader.TestClassLoader)5 Method (java.lang.reflect.Method)5 AroundInterceptor3 (com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor3)4 JavassistClassTest (com.navercorp.pinpoint.test.javasssit.JavassistClassTest)3 ProfilerConfig (com.navercorp.pinpoint.bootstrap.config.ProfilerConfig)2 MethodFilter (com.navercorp.pinpoint.bootstrap.instrument.MethodFilter)2 Interceptor (com.navercorp.pinpoint.bootstrap.interceptor.Interceptor)2 ObjectFactory (com.navercorp.pinpoint.bootstrap.plugin.ObjectFactory)2 PreparedStatementBindingMethodFilter (com.navercorp.pinpoint.bootstrap.plugin.jdbc.PreparedStatementBindingMethodFilter)2 List (java.util.List)2