use of com.navercorp.pinpoint.profiler.instrument.mock.accessor.MockAsyncContext in project pinpoint by naver.
the class ASMClassNodeAdapterTest method addField_transient.
@Test
public void addField_transient() throws Exception {
final String baseClassName = "com.navercorp.pinpoint.profiler.instrument.mock.SerializableClass";
final Class<AsyncContext> asyncContextClass = AsyncContext.class;
final String accessorClassName = asyncContextClass.getName();
final ASMClassNodeLoader.TestClassLoader classLoader = ASMClassNodeLoader.getClassLoader();
classLoader.setTargetClassName(baseClassName);
classLoader.setCallbackHandler(new ASMClassNodeLoader.CallbackHandler() {
@Override
public void handle(ClassNode classNode) {
ASMClassNodeAdapter classNodeAdapter = new ASMClassNodeAdapter(pluginClassInputStreamProvider, null, getClass().getProtectionDomain(), classNode);
classNodeAdapter.addField("_$PINPOINT$_" + JavaAssistUtils.javaClassNameToVariableName(accessorClassName), Type.getDescriptor(asyncContextClass));
classNodeAdapter.addInterface(accessorClassName);
ASMFieldNodeAdapter fieldNode = classNodeAdapter.getField("_$PINPOINT$_" + JavaAssistUtils.javaClassNameToVariableName(accessorClassName), null);
classNodeAdapter.addGetterMethod("_$PINPOINT$_getAsyncContext", fieldNode);
classNodeAdapter.addSetterMethod("_$PINPOINT$_setAsyncContext", fieldNode);
}
});
Class<?> baseClazz = classLoader.loadClass(baseClassName);
Object instance = baseClazz.newInstance();
AsyncContext asyncContext = new MockAsyncContext();
Method setMethod = baseClazz.getDeclaredMethod("_$PINPOINT$_setAsyncContext", asyncContextClass);
setMethod.invoke(instance, asyncContext);
Method getMethod = baseClazz.getDeclaredMethod("_$PINPOINT$_getAsyncContext");
AsyncContext result = (AsyncContext) getMethod.invoke(instance);
JavaSerializableUtils.serialize(instance);
logger.debug("{}", result);
}
Aggregations