use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod in project pinpoint by naver.
the class ThriftPlugin method addTAsyncMethodCallEditor.
private void addTAsyncMethodCallEditor() {
final String targetClassName = "org.apache.thrift.async.TAsyncMethodCall";
transformTemplate.transform(targetClassName, new TransformCallback() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
final InstrumentClass target = instrumentor.getInstrumentClass(loader, className, classfileBuffer);
target.addField(AsyncTraceIdAccessor.class.getName());
target.addField(ThriftConstants.FIELD_ACCESSOR_SOCKET_ADDRESS);
target.addGetter(ThriftConstants.FIELD_GETTER_T_NON_BLOCKING_TRANSPORT, ThriftConstants.T_ASYNC_METHOD_CALL_FIELD_TRANSPORT);
// TAsyncMethodCall(TAsyncClient, TProtocolFactory, TNonblockingTransport, AsyncMethodCallback<T>, boolean)
final InstrumentMethod constructor = target.getConstructor("org.apache.thrift.async.TAsyncClient", "org.apache.thrift.protocol.TProtocolFactory", "org.apache.thrift.transport.TNonblockingTransport", "org.apache.thrift.async.AsyncMethodCallback", "boolean");
if (constructor != null) {
String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.client.async.TAsyncMethodCallConstructInterceptor";
constructor.addInterceptor(interceptor);
}
// TAsyncMethodCall.cleanUpAndFireCallback(SelectionKey)
final InstrumentMethod cleanUpAndFireCallback = target.getDeclaredMethod("cleanUpAndFireCallback", "java.nio.channels.SelectionKey");
if (cleanUpAndFireCallback != null) {
String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.client.async.TAsyncMethodCallCleanUpAndFireCallbackInterceptor";
cleanUpAndFireCallback.addInterceptor(interceptor);
}
// TAsyncMethodCall.onError(Exception)
final InstrumentMethod onError = target.getDeclaredMethod("onError", "java.lang.Exception");
if (onError != null) {
String interceptor = "com.navercorp.pinpoint.plugin.thrift.interceptor.client.async.TAsyncMethodCallOnErrorInterceptor";
onError.addInterceptor(interceptor);
}
return target.toBytecode();
}
});
}
use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod in project pinpoint by naver.
the class JavassistClassTest method testDeclaredMethod.
@Test
public void testDeclaredMethod() throws InstrumentException {
InstrumentEngine engine = newJavassistEngine();
InstrumentContext instrumentContext = mock(InstrumentContext.class);
String testObjectName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject";
byte[] testObjectByteCode = readByteCode(testObjectName);
InstrumentClass testObject = engine.getClass(instrumentContext, null, testObjectName, testObjectByteCode);
Assert.assertEquals(testObject.getName(), testObjectName);
InstrumentMethod declaredMethod = testObject.getDeclaredMethod("callA");
Assert.assertNotNull(declaredMethod);
}
use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod 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"));
}
use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod 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"));
}
use of com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod 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"));
}
Aggregations