use of com.navercorp.pinpoint.bootstrap.interceptor.Interceptor in project pinpoint by naver.
the class AnnotatedInterceptorFactoryTest method test0.
@Test
public void test0() throws Exception {
AnnotatedInterceptorFactory factory = newAnnotatedInterceptorFactory();
Interceptor interceptor = factory.getInterceptor(getClass().getClassLoader(), TestInterceptor0.class.getName(), null, null, null, instrumentClass, instrumentMethod);
assertEquals(TestInterceptor0.class, interceptor.getClass());
}
use of com.navercorp.pinpoint.bootstrap.interceptor.Interceptor in project pinpoint by naver.
the class JavassistClassTest method testBeforeAddInterceptor.
@Test
public void testBeforeAddInterceptor() throws Exception {
final TestClassLoader loader = getTestClassLoader();
final String javassistClassName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject";
loader.addTransformer(javassistClassName, new TransformCallback() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
try {
logger.info("modify className:{} cl:{}", className, classLoader);
InstrumentClass aClass = instrumentor.getInstrumentClass(classLoader, javassistClassName, classfileBuffer);
String methodName = "callA";
InstrumentMethod callaMethod = aClass.getDeclaredMethod(methodName);
callaMethod.addInterceptor("com.navercorp.pinpoint.test.javasssit.TestBeforeInterceptor");
byte[] bytes = aClass.toBytecode();
return bytes;
} catch (Throwable e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
}
});
Class<?> testObjectClazz = loader.loadClass(javassistClassName);
final String methodName = "callA";
logger.info("class:{}", testObjectClazz.toString());
logger.info("class cl:{}", testObjectClazz.getClassLoader());
final Object testObject = testObjectClazz.newInstance();
Method callA = testObjectClazz.getMethod(methodName);
callA.invoke(testObject);
Interceptor interceptor = getInterceptor(loader, 0);
assertEqualsIntField(interceptor, "call", 1);
assertEqualsObjectField(interceptor, "className", "com.navercorp.pinpoint.test.javasssit.mock.TestObject");
assertEqualsObjectField(interceptor, "methodName", methodName);
assertEqualsObjectField(interceptor, "args", null);
assertEqualsObjectField(interceptor, "target", testObject);
}
use of com.navercorp.pinpoint.bootstrap.interceptor.Interceptor in project pinpoint by naver.
the class JavassistClassTest method testAddAfterInterceptor.
@Ignore
@Test
public void testAddAfterInterceptor() throws Exception {
final TestClassLoader loader = getTestClassLoader();
final String testClassObject = "com.navercorp.pinpoint.test.javasssit.mock.TestObject2";
loader.addTransformer(testClassObject, new TransformCallback() {
@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
try {
logger.info("modify cl:{}", classLoader);
InstrumentClass aClass = instrumentor.getInstrumentClass(classLoader, testClassObject, classfileBuffer);
String methodName = "callA";
aClass.getDeclaredMethod(methodName).addInterceptor("com.navercorp.pinpoint.profiler.interceptor.TestAfterInterceptor");
String methodName2 = "callB";
aClass.getDeclaredMethod(methodName2).addInterceptor("com.navercorp.pinpoint.profiler.interceptor.TestAfterInterceptor");
return aClass.toBytecode();
} catch (InstrumentException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
});
Class<?> testObjectClazz = loader.loadClass(testClassObject);
final String methodName = "callA";
logger.info("class:{}", testObjectClazz.toString());
final Object testObject = testObjectClazz.newInstance();
Method callA = testObjectClazz.getMethod(methodName);
Object result = callA.invoke(testObject);
Interceptor interceptor = getInterceptor(loader, 0);
assertEqualsIntField(interceptor, "call", 1);
assertEqualsObjectField(interceptor, "className", testClassObject);
assertEqualsObjectField(interceptor, "methodName", methodName);
assertEqualsObjectField(interceptor, "args", null);
assertEqualsObjectField(interceptor, "target", testObject);
assertEqualsObjectField(interceptor, "result", result);
final String methodName2 = "callB";
Method callBMethod = testObject.getClass().getMethod(methodName2);
callBMethod.invoke(testObject);
Interceptor interceptor2 = getInterceptor(loader, 1);
assertEqualsIntField(interceptor2, "call", 1);
assertEqualsObjectField(interceptor2, "className", testClassObject);
assertEqualsObjectField(interceptor2, "methodName", methodName2);
assertEqualsObjectField(interceptor2, "args", null);
assertEqualsObjectField(interceptor2, "target", testObject);
assertEqualsObjectField(interceptor2, "result", null);
}
use of com.navercorp.pinpoint.bootstrap.interceptor.Interceptor in project pinpoint by naver.
the class JavassistClassTest method getInterceptor.
private Interceptor getInterceptor(final TestClassLoader loader, int index) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
Class<?> interceptorClazz = loader.loadClass("com.navercorp.pinpoint.test.javasssit.TestInterceptors");
Method getMethod = interceptorClazz.getMethod("get", int.class);
Interceptor interceptor = (Interceptor) getMethod.invoke(null, index);
return interceptor;
}
use of com.navercorp.pinpoint.bootstrap.interceptor.Interceptor in project pinpoint by naver.
the class ASMMethod method addInterceptor0.
private int addInterceptor0(String interceptorClassName, Object[] constructorArgs, InterceptorScope scope, ExecutionPolicy executionPolicy) throws InstrumentException {
final ScopeInfo scopeInfo = resolveScopeInfo(interceptorClassName, scope, executionPolicy);
final Interceptor interceptor = createInterceptor(interceptorClassName, scopeInfo, constructorArgs);
final int interceptorId = this.interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(interceptor);
addInterceptor0(interceptor, interceptorId);
return interceptorId;
}
Aggregations