use of com.newrelic.agent.MockServiceManager 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()));
}
use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.
the class ClassTransformerConfigImplTest method testSpringPointcutEnabled.
@Test
public void testSpringPointcutEnabled() {
Map<String, Object> configuration = new HashMap<>();
configuration.put("lite_mode", true);
configuration.put("class_transformer:instrumentation_default:enabled", true);
configuration.put("enable_spring_tracing", true);
configuration.put("app_name", "Unit Test");
configuration = buildConfigMap(configuration);
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(configuration);
ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
ServiceManager serviceManager = new MockServiceManager(configService);
ServiceFactory.setServiceManager(serviceManager);
SpringPointCut springPointCut = new SpringPointCut(null, agentConfig);
assertTrue(springPointCut.isEnabled());
}
use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.
the class ClassTransformerConfigImplTest method testSpringPointcutDisabled.
@Test
public void testSpringPointcutDisabled() {
Map<String, Object> classTransformerMap = new HashMap<>();
Map<String, Object> defaultInstrumentationSettings = new HashMap<>();
defaultInstrumentationSettings.put("enabled", false);
classTransformerMap.put(ClassTransformerConfigImpl.DEFAULT_INSTRUMENTATION, defaultInstrumentationSettings);
Map<String, Object> configSettings = new HashMap<>();
configSettings.put(AgentConfigImpl.CLASS_TRANSFORMER, classTransformerMap);
configSettings.put(AgentConfigImpl.APP_NAME, "Unit Test");
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(configSettings);
ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
ServiceManager serviceManager = new MockServiceManager(configService);
ServiceFactory.setServiceManager(serviceManager);
SpringPointCut springPointCut = new SpringPointCut(null, agentConfig);
assertFalse(springPointCut.isEnabled());
}
use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.
the class ClassTransformerConfigImplTest method testPoincutExplicitEnable.
@Test
public void testPoincutExplicitEnable() {
Map<String, Object> config = new HashMap<>();
config.put("class_transformer:PointcutClassName:enabled", true);
config.put("class_transformer:instrumentation_default:enabled", true);
config.put("app_name", "Unit Test");
config = buildConfigMap(config);
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(config);
ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
ServiceManager serviceManager = new MockServiceManager(configService);
ServiceFactory.setServiceManager(serviceManager);
PointCutConfiguration pointCutConfiguration = new PointCutConfiguration("PointcutClassName", null, true, agentConfig.getClassTransformerConfig());
assertTrue(pointCutConfiguration.isEnabled());
}
use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.
the class ClassTransformerConfigImplTest method testPointcutDisabled.
@Test
public void testPointcutDisabled() {
Map<String, Object> configuration = new HashMap<>();
configuration.put("class_transformer:instrumentation_default:enabled", true);
configuration.put("class_transformer:my_pointcut_group:enabled", false);
configuration.put("app_name", "Unit Test");
configuration = buildConfigMap(configuration);
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(configuration);
ClassTransformerConfig classTransformerConfig = agentConfig.getClassTransformerConfig();
ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, Collections.<String, Object>emptyMap());
ServiceManager serviceManager = new MockServiceManager(configService);
ServiceFactory.setServiceManager(serviceManager);
PointCutConfiguration pointCutConfiguration = new PointCutConfiguration("name", "my_pointcut_group", true, classTransformerConfig);
assertFalse(pointCutConfiguration.isEnabled());
}
Aggregations