Search in sources :

Example 1 with MockAsyncContext

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);
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) MockAsyncContext(com.navercorp.pinpoint.profiler.instrument.mock.accessor.MockAsyncContext) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext) Method(java.lang.reflect.Method) MockAsyncContext(com.navercorp.pinpoint.profiler.instrument.mock.accessor.MockAsyncContext) Test(org.junit.Test)

Aggregations

AsyncContext (com.navercorp.pinpoint.bootstrap.context.AsyncContext)1 MockAsyncContext (com.navercorp.pinpoint.profiler.instrument.mock.accessor.MockAsyncContext)1 Method (java.lang.reflect.Method)1 Test (org.junit.Test)1 ClassNode (org.objectweb.asm.tree.ClassNode)1