Search in sources :

Example 1 with Instrumentation

use of java.lang.instrument.Instrumentation in project pinpoint by naver.

the class DynamicTransformServiceTest method testRetransform_Fail_memoryleak_prevent.

@Test()
public void testRetransform_Fail_memoryleak_prevent() throws Exception {
    final Instrumentation instrumentation = mock(Instrumentation.class);
    when(instrumentation.isModifiableClass(any(Class.class))).thenReturn(true);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            throw new UnmodifiableClassException();
        }
    }).when(instrumentation).retransformClasses(any(Class.class));
    DefaultDynamicTransformerRegistry listener = new DefaultDynamicTransformerRegistry();
    final ClassFileTransformer classFileTransformer = mock(ClassFileTransformer.class);
    DynamicTransformService dynamicTransformService = new DynamicTransformService(instrumentation, listener);
    try {
        dynamicTransformService.retransform(String.class, classFileTransformer);
        Assert.fail("expected retransform fail");
    } catch (Exception e) {
    }
    Assert.assertEquals(listener.size(), 0);
}
Also used : ClassFileTransformer(java.lang.instrument.ClassFileTransformer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) UnmodifiableClassException(java.lang.instrument.UnmodifiableClassException) Instrumentation(java.lang.instrument.Instrumentation) UnmodifiableClassException(java.lang.instrument.UnmodifiableClassException) Test(org.junit.Test)

Example 2 with Instrumentation

use of java.lang.instrument.Instrumentation in project byte-buddy by raphw.

the class AgentBuilderListenerTest method testReadEdgeAddingListenerNamedDuplexCannotRead.

@Test
public void testReadEdgeAddingListenerNamedDuplexCannotRead() throws Exception {
    Instrumentation instrumentation = mock(Instrumentation.class);
    JavaModule source = mock(JavaModule.class), target = mock(JavaModule.class);
    when(source.isNamed()).thenReturn(true);
    when(source.canRead(target)).thenReturn(false);
    when(target.canRead(source)).thenReturn(false);
    AgentBuilder.Listener listener = new AgentBuilder.Listener.ModuleReadEdgeCompleting(instrumentation, true, Collections.singleton(target));
    listener.onTransformation(mock(TypeDescription.class), mock(ClassLoader.class), source, LOADED, mock(DynamicType.class));
    verify(source).isNamed();
    verify(source).canRead(target);
    verify(source).addReads(instrumentation, target);
    verifyNoMoreInteractions(source);
    verify(target).canRead(source);
    verify(target).addReads(instrumentation, source);
    verifyNoMoreInteractions(target);
}
Also used : DynamicType(net.bytebuddy.dynamic.DynamicType) Instrumentation(java.lang.instrument.Instrumentation) TypeDescription(net.bytebuddy.description.type.TypeDescription) JavaModule(net.bytebuddy.utility.JavaModule) Test(org.junit.Test)

Example 3 with Instrumentation

use of java.lang.instrument.Instrumentation in project byte-buddy by raphw.

the class AgentBuilderListenerTest method testReadEdgeAddingListenerNamedCannotRead.

@Test
public void testReadEdgeAddingListenerNamedCannotRead() throws Exception {
    Instrumentation instrumentation = mock(Instrumentation.class);
    JavaModule source = mock(JavaModule.class), target = mock(JavaModule.class);
    when(source.isNamed()).thenReturn(true);
    when(source.canRead(target)).thenReturn(false);
    AgentBuilder.Listener listener = new AgentBuilder.Listener.ModuleReadEdgeCompleting(instrumentation, false, Collections.singleton(target));
    listener.onTransformation(mock(TypeDescription.class), mock(ClassLoader.class), source, LOADED, mock(DynamicType.class));
    verify(source).isNamed();
    verify(source).canRead(target);
    verify(source).addReads(instrumentation, target);
    verifyNoMoreInteractions(source);
    verifyZeroInteractions(target);
}
Also used : DynamicType(net.bytebuddy.dynamic.DynamicType) Instrumentation(java.lang.instrument.Instrumentation) TypeDescription(net.bytebuddy.description.type.TypeDescription) JavaModule(net.bytebuddy.utility.JavaModule) Test(org.junit.Test)

Example 4 with Instrumentation

use of java.lang.instrument.Instrumentation in project byte-buddy by raphw.

the class AgentBuilderListenerTest method testReadEdgeAddingListenerDuplexNotSupported.

@Test
public void testReadEdgeAddingListenerDuplexNotSupported() throws Exception {
    Instrumentation instrumentation = mock(Instrumentation.class);
    AgentBuilder.Listener listener = new AgentBuilder.Listener.ModuleReadEdgeCompleting(instrumentation, true, Collections.<JavaModule>emptySet());
    listener.onTransformation(mock(TypeDescription.class), mock(ClassLoader.class), JavaModule.UNSUPPORTED, LOADED, mock(DynamicType.class));
}
Also used : DynamicType(net.bytebuddy.dynamic.DynamicType) Instrumentation(java.lang.instrument.Instrumentation) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 5 with Instrumentation

use of java.lang.instrument.Instrumentation in project byte-buddy by raphw.

the class AgentBuilderListenerTest method testReadEdgeAddingListenerCanRead.

@Test
public void testReadEdgeAddingListenerCanRead() throws Exception {
    Instrumentation instrumentation = mock(Instrumentation.class);
    JavaModule source = mock(JavaModule.class), target = mock(JavaModule.class);
    when(source.isNamed()).thenReturn(true);
    when(source.canRead(target)).thenReturn(true);
    AgentBuilder.Listener listener = new AgentBuilder.Listener.ModuleReadEdgeCompleting(instrumentation, false, Collections.singleton(target));
    listener.onTransformation(mock(TypeDescription.class), mock(ClassLoader.class), source, LOADED, mock(DynamicType.class));
    verify(source).isNamed();
    verify(source).canRead(target);
    verifyNoMoreInteractions(source);
    verifyZeroInteractions(target);
}
Also used : DynamicType(net.bytebuddy.dynamic.DynamicType) Instrumentation(java.lang.instrument.Instrumentation) TypeDescription(net.bytebuddy.description.type.TypeDescription) JavaModule(net.bytebuddy.utility.JavaModule) Test(org.junit.Test)

Aggregations

Instrumentation (java.lang.instrument.Instrumentation)41 Test (org.junit.Test)25 TypeDescription (net.bytebuddy.description.type.TypeDescription)8 DynamicType (net.bytebuddy.dynamic.DynamicType)8 AgentOption (com.navercorp.pinpoint.bootstrap.AgentOption)6 DefaultAgentOption (com.navercorp.pinpoint.bootstrap.DefaultAgentOption)6 ClassFileTransformer (java.lang.instrument.ClassFileTransformer)6 JavaModule (net.bytebuddy.utility.JavaModule)6 DefaultProfilerConfig (com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig)5 ProfilerConfig (com.navercorp.pinpoint.bootstrap.config.ProfilerConfig)4 DefaultApplicationContext (com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext)4 InterceptorRegistryBinder (com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder)4 Module (com.google.inject.Module)3 TestInterceptorRegistryBinder (com.navercorp.pinpoint.profiler.util.TestInterceptorRegistryBinder)3 ByteBuddy (net.bytebuddy.ByteBuddy)3 ModuleFactory (com.navercorp.pinpoint.profiler.context.module.ModuleFactory)2 ApiMetaDataService (com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService)2 ObjectBinderFactory (com.navercorp.pinpoint.profiler.objectfactory.ObjectBinderFactory)2 UnmodifiableClassException (java.lang.instrument.UnmodifiableClassException)2 URLClassLoader (java.net.URLClassLoader)2