use of com.navercorp.pinpoint.profiler.instrument.InstrumentEngine 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");
}
use of com.navercorp.pinpoint.profiler.instrument.InstrumentEngine in project pinpoint by naver.
the class JavassistClassTest method testDeclaredMethods.
@Test
public void testDeclaredMethods() 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);
int findMethodCount = 0;
for (InstrumentMethod methodInfo : testObject.getDeclaredMethods()) {
if (!methodInfo.getName().equals("callA")) {
continue;
}
String[] parameterTypes = methodInfo.getParameterTypes();
if (parameterTypes == null || parameterTypes.length == 0) {
findMethodCount++;
}
}
Assert.assertEquals(findMethodCount, 1);
}
use of com.navercorp.pinpoint.profiler.instrument.InstrumentEngine in project pinpoint by naver.
the class JavassistClassTest method hasEnclodingMethod.
@Test
public void hasEnclodingMethod() throws Exception {
InstrumentEngine engine = newJavassistEngine();
InstrumentContext instrumentContext = mock(InstrumentContext.class);
String testObjectName = "com.navercorp.pinpoint.test.javasssit.mock.TestObjectNestedClass";
byte[] testObjectByteCode = readByteCode(testObjectName);
InstrumentClass testObject = engine.getClass(instrumentContext, null, testObjectName, testObjectByteCode);
Assert.assertEquals(testObject.getName(), testObjectName);
assertEquals(1, testObject.getNestedClasses(ClassFilters.enclosingMethod("enclosingMethod", "java.lang.String", "int")).size());
assertEquals(0, testObject.getNestedClasses(ClassFilters.enclosingMethod("enclosingMethod", "int")).size());
}
use of com.navercorp.pinpoint.profiler.instrument.InstrumentEngine in project pinpoint by naver.
the class TestClassLoader method addTranslator.
public void addTranslator() {
final InstrumentEngine instrumentEngine = applicationContext.getInstrumentEngine();
if (instrumentEngine instanceof JavassistEngine) {
logger.info("JAVASSIST BCI engine");
ClassPool classPool = ((JavassistEngine) instrumentEngine).getClassPool(this);
this.instrumentTranslator = new JavassistTranslator(this, classPool, applicationContext.getClassFileTransformerDispatcher());
this.addTranslator(instrumentTranslator);
} else if (instrumentEngine instanceof ASMEngine) {
logger.info("ASM BCI engine");
this.instrumentTranslator = new DefaultTranslator(this, applicationContext.getClassFileTransformerDispatcher());
this.addTranslator(instrumentTranslator);
} else {
logger.info("Unknown BCI engine");
this.instrumentTranslator = new DefaultTranslator(this, applicationContext.getClassFileTransformerDispatcher());
this.addTranslator(instrumentTranslator);
}
}
use of com.navercorp.pinpoint.profiler.instrument.InstrumentEngine in project pinpoint by naver.
the class JavassistClassTest method getNestedClasses.
@Test
public void getNestedClasses() throws Exception {
InstrumentEngine engine = newJavassistEngine();
InstrumentContext instrumentContext = mock(InstrumentContext.class);
String testObjectName = "com.navercorp.pinpoint.test.javasssit.mock.TestObjectNestedClass";
byte[] testObjectByteCode = readByteCode(testObjectName);
InstrumentClass testObject = engine.getClass(instrumentContext, null, testObjectName, testObjectByteCode);
Assert.assertEquals(testObject.getName(), testObjectName);
// find class name condition.
final String targetClassName = "com.navercorp.pinpoint.profiler.interceptor.bci.TestObjectNestedClass$InstanceInner";
for (InstrumentClass c : testObject.getNestedClasses(ClassFilters.name(targetClassName))) {
assertEquals(targetClassName, c.getName());
}
// find enclosing method condition.
assertEquals(2, testObject.getNestedClasses(ClassFilters.enclosingMethod("annonymousInnerClass")).size());
// find interface condition.
assertEquals(2, testObject.getNestedClasses(ClassFilters.interfaze("java.util.concurrent.Callable")).size());
// find enclosing method & interface condition.
assertEquals(1, testObject.getNestedClasses(ClassFilters.chain(ClassFilters.enclosingMethod("annonymousInnerClass"), ClassFilters.interfaze("java.util.concurrent.Callable"))).size());
}
Aggregations