Search in sources :

Example 6 with InstrumentationContextManager

use of com.newrelic.agent.instrumentation.context.InstrumentationContextManager in project newrelic-java-agent by newrelic.

the class ExtensionServiceTest method setUpAgent.

@Before
public void setUpAgent() throws Exception {
    Map<String, Object> configMap = new HashMap<>();
    configMap.put(AgentConfigImpl.APP_NAME, EXTENSION_NAME);
    AgentConfig config = AgentConfigImpl.createAgentConfig(configMap);
    configService = ConfigServiceFactory.createConfigService(config, Collections.<String, Object>emptyMap());
    serviceManager = new MockServiceManager(configService);
    ServiceFactory.setServiceManager(serviceManager);
    final InstrumentationProxy instrumentationProxy = Mockito.mock(InstrumentationProxy.class);
    serviceManager.setCoreService(new MockCoreService() {

        @Override
        public InstrumentationProxy getInstrumentation() {
            return instrumentationProxy;
        }
    });
    Mockito.when(instrumentationProxy.isRetransformClassesSupported()).thenReturn(true);
    Mockito.when(instrumentationProxy.getAllLoadedClasses()).thenReturn(new Class[] {});
    extensionService = new ExtensionService(configService, ExtensionsLoadedListener.NOOP);
    serviceManager.setExtensionService(extensionService);
    serviceManager.setJmxService(Mockito.mock(JmxService.class));
    ClassTransformerService classTransformerService = serviceManager.getClassTransformerService();
    ClassRetransformer mockRetransformer = Mockito.mock(ClassRetransformer.class);
    Mockito.when(classTransformerService.getLocalRetransformer()).thenReturn(mockRetransformer);
    InstrumentationContextManager mockContextManager = Mockito.mock(InstrumentationContextManager.class);
    Mockito.when(classTransformerService.getContextManager()).thenReturn(mockContextManager);
    ClassWeaverService mockWeaverService = Mockito.mock(ClassWeaverService.class);
    Mockito.when(mockContextManager.getClassWeaverService()).thenReturn(mockWeaverService);
    Mockito.when(mockWeaverService.reloadExternalWeavePackages(Mockito.<File>anyCollection(), Mockito.<File>anyCollection())).thenReturn(new Runnable() {

        @Override
        public void run() {
        }
    });
}
Also used : ClassRetransformer(com.newrelic.agent.instrumentation.custom.ClassRetransformer) HashMap(java.util.HashMap) InstrumentationProxy(com.newrelic.agent.InstrumentationProxy) JmxService(com.newrelic.agent.jmx.JmxService) InstrumentationContextManager(com.newrelic.agent.instrumentation.context.InstrumentationContextManager) AgentConfig(com.newrelic.agent.config.AgentConfig) MockServiceManager(com.newrelic.agent.MockServiceManager) ClassTransformerService(com.newrelic.agent.instrumentation.ClassTransformerService) MockCoreService(com.newrelic.agent.MockCoreService) ClassWeaverService(com.newrelic.agent.instrumentation.weaver.ClassWeaverService) Before(org.junit.Before)

Example 7 with InstrumentationContextManager

use of com.newrelic.agent.instrumentation.context.InstrumentationContextManager in project newrelic-java-agent by newrelic.

the class IncludeExcludeTest method testIncludes.

@Test
public void testIncludes() throws Exception {
    Map<String, Object> configMap = createConfigMap();
    Map<String, Object> classTransformerConfigMap = new HashMap<>();
    classTransformerConfigMap.put("excludes", "^my/custom/.*");
    classTransformerConfigMap.put("includes", "^my/custom/.*");
    configMap.put("class_transformer", classTransformerConfigMap);
    createServiceManager(configMap);
    InstrumentationContextManager manager = new InstrumentationContextManager(null);
    Assert.assertTrue("config includes should override excludes", manager.shouldTransform("my/custom/Class", SOME_CLASSLOADER));
}
Also used : HashMap(java.util.HashMap) InstrumentationContextManager(com.newrelic.agent.instrumentation.context.InstrumentationContextManager) Test(org.junit.Test)

Example 8 with InstrumentationContextManager

use of com.newrelic.agent.instrumentation.context.InstrumentationContextManager in project newrelic-java-agent by newrelic.

the class IncludeExcludeTest method testClassLoader.

@Test
public void testClassLoader() throws Exception {
    final ClassLoader badClassLoader = new ClassLoader() {
    };
    Map<String, Object> configMap = createConfigMap();
    Map<String, Object> classTransformerConfigMap = new HashMap<>();
    classTransformerConfigMap.put("classloader_excludes", badClassLoader.getClass().getName());
    configMap.put("class_transformer", classTransformerConfigMap);
    createServiceManager(configMap);
    InstrumentationContextManager manager = new InstrumentationContextManager(null);
    Assert.assertTrue(manager.shouldTransform("a/normal/class/Foo", SOME_CLASSLOADER));
    Assert.assertFalse(manager.shouldTransform("a/normal/class/Foo", badClassLoader));
}
Also used : HashMap(java.util.HashMap) InstrumentationContextManager(com.newrelic.agent.instrumentation.context.InstrumentationContextManager) Test(org.junit.Test)

Aggregations

InstrumentationContextManager (com.newrelic.agent.instrumentation.context.InstrumentationContextManager)8 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 InstrumentationProxy (com.newrelic.agent.InstrumentationProxy)2 MockServiceManager (com.newrelic.agent.MockServiceManager)2 File (java.io.File)2 HashSet (java.util.HashSet)2 MockCoreService (com.newrelic.agent.MockCoreService)1 AgentConfig (com.newrelic.agent.config.AgentConfig)1 ClassTransformerService (com.newrelic.agent.instrumentation.ClassTransformerService)1 ClassRetransformer (com.newrelic.agent.instrumentation.custom.ClassRetransformer)1 ClassWeaverService (com.newrelic.agent.instrumentation.weaver.ClassWeaverService)1 JmxService (com.newrelic.agent.jmx.JmxService)1 JarCollectorService (com.newrelic.agent.service.module.JarCollectorService)1 FileNotFoundException (java.io.FileNotFoundException)1 Before (org.junit.Before)1