Search in sources :

Example 36 with Instrumentation

use of java.lang.instrument.Instrumentation in project evosuite by EvoSuite.

the class InstrumentingAgent_IntTest method testInstrumentation.

@Test
public void testInstrumentation() throws Exception {
    try {
        InstrumentingAgent.activate();
        Instrumentation inst = InstrumentingAgent.getInstrumentation();
        Assert.assertNotNull(inst);
        ClassLoader loader = this.getClass().getClassLoader();
        Assert.assertTrue(inst.isModifiableClass(loader.loadClass(TimeA.class.getName())));
        Assert.assertTrue(inst.isModifiableClass(loader.loadClass(TimeB.class.getName())));
        Assert.assertTrue(inst.isModifiableClass(loader.loadClass(TimeC.class.getName())));
        Assert.assertTrue(inst.isModifiableClass(loader.loadClass(ExtendingTimeC.class.getName())));
        Assert.assertTrue(inst.isModifiableClass(loader.loadClass(ConcreteTime.class.getName())));
        Assert.assertTrue(inst.isModifiableClass(loader.loadClass(AbstractTime.class.getName())));
    } finally {
        InstrumentingAgent.deactivate();
    }
}
Also used : Instrumentation(java.lang.instrument.Instrumentation)

Example 37 with Instrumentation

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

the class MockApplicationContextFactory method build.

public DefaultApplicationContext build(ProfilerConfig config, ModuleFactory moduleFactory) {
    Instrumentation instrumentation = new DummyInstrumentation();
    String mockAgentId = "mockAgentId";
    String mockAgentName = "mockAgentName";
    String mockApplicationName = "mockApplicationName";
    AgentOption agentOption = new DefaultAgentOption(instrumentation, mockAgentId, mockAgentName, mockApplicationName, false, config, Collections.<String>emptyList(), Collections.<String>emptyList());
    return new DefaultApplicationContext(agentOption, moduleFactory);
}
Also used : DefaultApplicationContext(com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext) DefaultAgentOption(com.navercorp.pinpoint.bootstrap.DefaultAgentOption) Instrumentation(java.lang.instrument.Instrumentation) DefaultAgentOption(com.navercorp.pinpoint.bootstrap.DefaultAgentOption) AgentOption(com.navercorp.pinpoint.bootstrap.AgentOption)

Example 38 with Instrumentation

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

the class MockApplicationContextModuleTest method testMockApplicationContext.

@Test
public void testMockApplicationContext() {
    ProfilerConfig profilerConfig = spy(new DefaultProfilerConfig());
    when(profilerConfig.getStaticResourceCleanup()).thenReturn(true);
    Instrumentation instrumentation = Mockito.mock(Instrumentation.class);
    AgentOption agentOption = new DefaultAgentOption(instrumentation, "mockAgentId", "mockAgentName", "mockApplicationName", false, profilerConfig, Collections.<String>emptyList(), Collections.<String>emptyList());
    Module pluginModule = new PluginApplicationContextModule();
    InterceptorRegistryBinder interceptorRegistryBinder = new TestInterceptorRegistryBinder();
    Module testInterceptorRegistryModule = InterceptorRegistryModule.wrap(interceptorRegistryBinder);
    ModuleFactory moduleFactory = new OverrideModuleFactory(pluginModule, testInterceptorRegistryModule);
    DefaultApplicationContext applicationContext = new DefaultApplicationContext(agentOption, moduleFactory);
    Injector injector = applicationContext.getInjector();
    // singleton check
    AgentInfoSender instance1 = injector.getInstance(AgentInfoSender.class);
    AgentInfoSender instance2 = injector.getInstance(AgentInfoSender.class);
    Assert.assertSame(instance1, instance2);
    ClassFileTransformer instance4 = injector.getInstance(ClassFileTransformer.class);
    applicationContext.close();
}
Also used : ClassFileTransformer(java.lang.instrument.ClassFileTransformer) InterceptorRegistryBinder(com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder) ProfilerConfig(com.navercorp.pinpoint.bootstrap.config.ProfilerConfig) DefaultProfilerConfig(com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig) DefaultProfilerConfig(com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig) Instrumentation(java.lang.instrument.Instrumentation) AgentInfoSender(com.navercorp.pinpoint.profiler.AgentInfoSender) ModuleFactory(com.navercorp.pinpoint.profiler.context.module.ModuleFactory) DefaultApplicationContext(com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext) DefaultAgentOption(com.navercorp.pinpoint.bootstrap.DefaultAgentOption) Injector(com.google.inject.Injector) DefaultAgentOption(com.navercorp.pinpoint.bootstrap.DefaultAgentOption) AgentOption(com.navercorp.pinpoint.bootstrap.AgentOption) Module(com.google.inject.Module) Test(org.junit.Test)

Example 39 with Instrumentation

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

the class DependencyGraph method newApplicationContext.

private DefaultApplicationContext newApplicationContext() {
    ProfilerConfig profilerConfig = spy(new DefaultProfilerConfig());
    Mockito.when(profilerConfig.getStaticResourceCleanup()).thenReturn(true);
    Instrumentation instrumentation = mock(Instrumentation.class);
    AgentOption agentOption = new DefaultAgentOption(instrumentation, "mockAgentId", "mockAgentName", "mockApplicationName", false, profilerConfig, Collections.<String>emptyList(), Collections.<String>emptyList());
    InterceptorRegistryBinder interceptorRegistryBinder = new TestInterceptorRegistryBinder();
    Module testInterceptorRegistryModule = InterceptorRegistryModule.wrap(interceptorRegistryBinder);
    ModuleFactory moduleFactory = new OverrideModuleFactory(testInterceptorRegistryModule);
    return new DefaultApplicationContext(agentOption, moduleFactory);
}
Also used : OverrideModuleFactory(com.navercorp.pinpoint.profiler.context.module.OverrideModuleFactory) ModuleFactory(com.navercorp.pinpoint.profiler.context.module.ModuleFactory) DefaultApplicationContext(com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext) DefaultAgentOption(com.navercorp.pinpoint.bootstrap.DefaultAgentOption) InterceptorRegistryBinder(com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder) TestInterceptorRegistryBinder(com.navercorp.pinpoint.profiler.util.TestInterceptorRegistryBinder) ProfilerConfig(com.navercorp.pinpoint.bootstrap.config.ProfilerConfig) DefaultProfilerConfig(com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig) DefaultProfilerConfig(com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig) TestInterceptorRegistryBinder(com.navercorp.pinpoint.profiler.util.TestInterceptorRegistryBinder) OverrideModuleFactory(com.navercorp.pinpoint.profiler.context.module.OverrideModuleFactory) Instrumentation(java.lang.instrument.Instrumentation) DefaultAgentOption(com.navercorp.pinpoint.bootstrap.DefaultAgentOption) AgentOption(com.navercorp.pinpoint.bootstrap.AgentOption) Module(com.google.inject.Module) InterceptorRegistryModule(com.navercorp.pinpoint.profiler.context.module.InterceptorRegistryModule) GraphvizModule(com.google.inject.grapher.graphviz.GraphvizModule)

Example 40 with Instrumentation

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

the class MockApplicationContextFactory method build.

public DefaultApplicationContext build(ProfilerConfig config, ModuleFactory moduleFactory) {
    Instrumentation instrumentation = Mockito.mock(Instrumentation.class);
    String mockAgentId = "mockAgentId";
    String mockAgentName = "mockAgentName";
    String mockApplicationName = "mockApplicationName";
    AgentOption agentOption = new DefaultAgentOption(instrumentation, mockAgentId, mockAgentName, mockApplicationName, false, config, Collections.<String>emptyList(), Collections.<String>emptyList());
    return new DefaultApplicationContext(agentOption, moduleFactory);
}
Also used : DefaultApplicationContext(com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext) DefaultAgentOption(com.navercorp.pinpoint.bootstrap.DefaultAgentOption) Instrumentation(java.lang.instrument.Instrumentation) DefaultAgentOption(com.navercorp.pinpoint.bootstrap.DefaultAgentOption) AgentOption(com.navercorp.pinpoint.bootstrap.AgentOption)

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