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);
}
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);
}
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);
}
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));
}
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);
}
Aggregations