use of com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor in project pinpoint by naver.
the class ASMMethodNodeTest method addInterceptor.
@Test
public void addInterceptor() throws Exception {
final int interceptorId = interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(new ArgsArrayInterceptor());
final String targetClassName = "com.navercorp.pinpoint.profiler.instrument.mock.NormalClass";
final ASMClass declaringClass = mock(ASMClass.class);
when(declaringClass.getName()).thenReturn(targetClassName);
final ObjectBinderFactory objectBinderFactory = mock(ObjectBinderFactory.class);
ASMClassNodeLoader.TestClassLoader classLoader = ASMClassNodeLoader.getClassLoader();
classLoader.setTrace(false);
classLoader.setVerify(false);
classLoader.setTargetClassName(targetClassName);
classLoader.setCallbackHandler(new ASMClassNodeLoader.CallbackHandler() {
@Override
public void handle(ClassNode classNode) {
List<MethodNode> methodNodes = classNode.methods;
for (MethodNode methodNode : methodNodes) {
ASMMethod method = new ASMMethod(objectBinderFactory, pluginContext, apiMetaDataService, interceptorRegistryBinder, declaringClass, methodNode);
try {
method.addInterceptor(interceptorId);
} catch (InstrumentException e) {
e.printStackTrace();
}
}
}
});
Class<?> clazz = classLoader.loadClass(targetClassName);
Method method = clazz.getDeclaredMethod("sum", int.class);
assertEquals(55, method.invoke(clazz.newInstance(), 10));
}
use of com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor in project pinpoint by naver.
the class ASMMethodNodeAdapterTest method isVisited.
@Test
public void isVisited() throws Exception {
// init
final int interceptorId = interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(new ArgsArrayInterceptor());
final InterceptorDefinition interceptorDefinition = new InterceptorDefinitionFactory().createInterceptorDefinition(ArgsArrayInterceptor.class);
final String targetClassName = "com.navercorp.pinpoint.profiler.instrument.mock.ArgsClass";
final MethodNode methodNode = ASMClassNodeLoader.get(targetClassName, "arg");
ASMMethodNodeAdapter adapter = new ASMMethodNodeAdapter(JavaAssistUtils.javaNameToJvmName(targetClassName), methodNode);
assertEquals(false, adapter.hasInterceptor());
adapter.addBeforeInterceptor(interceptorId, interceptorDefinition, -1);
assertEquals(true, adapter.hasInterceptor());
}
use of com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor in project pinpoint by naver.
the class ASMMethodVariablesTest method initInterceptorLocalVariables.
@Test
public void initInterceptorLocalVariables() throws Exception {
MethodNode methodNode = ASMClassNodeLoader.get("com.navercorp.pinpoint.profiler.instrument.mock.ConstructorChildClass", "<init>");
ASMMethodVariables variables = new ASMMethodVariables("com/navercorp/pinpoint/profiler/instrument/mock/ConstructorChildClass", methodNode);
assertNull(variables.getEnterInsnNode());
assertNull(variables.getEnterInsnNode());
InterceptorRegistryBinder interceptorRegistryBinder = new DefaultInterceptorRegistryBinder();
int interceptorId = interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(new ArgsArrayInterceptor());
final InterceptorDefinition interceptorDefinition = new InterceptorDefinitionFactory().createInterceptorDefinition(ArgsArrayInterceptor.class);
InsnList instructions = new InsnList();
boolean first = variables.initInterceptorLocalVariables(instructions, interceptorId, interceptorDefinition, -1);
assertEquals(true, first);
assertNotNull(variables.getEnterInsnNode());
assertNotNull(variables.getEnterInsnNode());
}
use of com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor in project pinpoint by naver.
the class ASMMethodVariablesTest method hasInterceptor.
@Test
public void hasInterceptor() throws Exception {
InterceptorRegistryBinder interceptorRegistryBinder = new DefaultInterceptorRegistryBinder();
int interceptorId = interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(new ArgsArrayInterceptor());
final InterceptorDefinition interceptorDefinition = new InterceptorDefinitionFactory().createInterceptorDefinition(ArgsArrayInterceptor.class);
final ClassNode classNode = ASMClassNodeLoader.get("com.navercorp.pinpoint.profiler.instrument.mock.ArgsClass");
List<MethodNode> methodNodes = classNode.methods;
for (MethodNode methodNode : methodNodes) {
ASMMethodNodeAdapter methodNodeAdapter = new ASMMethodNodeAdapter(classNode.name, methodNode);
assertEquals(false, methodNodeAdapter.hasInterceptor());
methodNodeAdapter.addBeforeInterceptor(interceptorId, interceptorDefinition, -1);
assertEquals(true, methodNodeAdapter.hasInterceptor());
}
}
use of com.navercorp.pinpoint.profiler.instrument.mock.ArgsArrayInterceptor in project pinpoint by naver.
the class ASMMethodNodeAdapterAddInterceptorTest method addArgsArrayInterceptor.
@Test
public void addArgsArrayInterceptor() throws Exception {
int interceptorId = interceptorRegistryBinder.getInterceptorRegistryAdaptor().addInterceptor(new ArgsArrayInterceptor());
addInterceptor(interceptorId, ArgsArrayInterceptor.class);
}
Aggregations