Search in sources :

Example 1 with JarCollectorService

use of com.newrelic.agent.service.module.JarCollectorService in project newrelic-java-agent by newrelic.

the class ClassTransformerConfigImplTest method classloaderExcludes.

@Test
public void classloaderExcludes() throws Exception {
    Map<String, Object> classTransformerMap = new HashMap<>();
    final String prefix = ClassTransformerConfigImplTest.class.getName();
    classTransformerMap.put(ClassTransformerConfigImpl.CLASSLOADER_EXCLUDES, prefix + "$BadClassLoader, " + prefix + "$BadClassLoaderOther");
    Map<String, Object> configMap = new HashMap<>();
    configMap.put("class_transformer", classTransformerMap);
    configMap.put(AgentConfigImpl.APP_NAME, "unittest");
    AgentConfig config = AgentConfigImpl.createAgentConfig(configMap);
    ClassTransformerConfig classTransformerConfig = config.getClassTransformerConfig();
    classTransformerConfig = ClassTransformerConfigImpl.createClassTransformerConfig(classTransformerMap, true, false);
    Set<String> exclusions = classTransformerConfig.getClassloaderExclusions();
    // 6 included by default ClassTransformerConfigImpl#initializeClassloaderExcludes
    Assert.assertEquals(8, exclusions.size());
    ConfigService configService = ConfigServiceFactory.createConfigService(config, Collections.<String, Object>emptyMap());
    MockServiceManager serviceManager = new MockServiceManager(configService);
    ServiceFactory.setServiceManager(serviceManager);
    JarCollectorService mockJarCollector = serviceManager.getJarCollectorService();
    when(mockJarCollector.getSourceVisitor()).thenReturn(ClassMatchVisitorFactory.NO_OP_FACTORY);
    InstrumentationContextManager icm = new InstrumentationContextManager(Mockito.mock(InstrumentationProxy.class));
    Assert.assertFalse(icm.isClassloaderExcluded(new GoodClassLoader()));
    assertTrue(icm.isClassloaderExcluded(new BadClassLoader()));
    assertTrue(icm.isClassloaderExcluded(new BadClassLoaderOther()));
}
Also used : HashMap(java.util.HashMap) InstrumentationContextManager(com.newrelic.agent.instrumentation.context.InstrumentationContextManager) InstrumentationProxy(com.newrelic.agent.InstrumentationProxy) JarCollectorService(com.newrelic.agent.service.module.JarCollectorService) MockServiceManager(com.newrelic.agent.MockServiceManager) Test(org.junit.Test)

Example 2 with JarCollectorService

use of com.newrelic.agent.service.module.JarCollectorService in project newrelic-java-agent by newrelic.

the class IncludeExcludeTest method createServiceManager.

private void createServiceManager(Map<String, Object> configMap) throws Exception {
    ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(configMap), configMap);
    MockServiceManager serviceManager = new MockServiceManager(configService);
    ServiceFactory.setServiceManager(serviceManager);
    JarCollectorService mockJarCollector = serviceManager.getJarCollectorService();
    when(mockJarCollector.getSourceVisitor()).thenReturn(ClassMatchVisitorFactory.NO_OP_FACTORY);
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) JarCollectorService(com.newrelic.agent.service.module.JarCollectorService) MockServiceManager(com.newrelic.agent.MockServiceManager)

Aggregations

MockServiceManager (com.newrelic.agent.MockServiceManager)2 JarCollectorService (com.newrelic.agent.service.module.JarCollectorService)2 InstrumentationProxy (com.newrelic.agent.InstrumentationProxy)1 ConfigService (com.newrelic.agent.config.ConfigService)1 InstrumentationContextManager (com.newrelic.agent.instrumentation.context.InstrumentationContextManager)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1