Search in sources :

Example 11 with MockServiceManager

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()));
}
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 12 with MockServiceManager

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());
}
Also used : SpringPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) MockServiceManager(com.newrelic.agent.MockServiceManager) Test(org.junit.Test)

Example 13 with MockServiceManager

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());
}
Also used : SpringPointCut(com.newrelic.agent.instrumentation.pointcuts.frameworks.spring.SpringPointCut) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) MockServiceManager(com.newrelic.agent.MockServiceManager) Test(org.junit.Test)

Example 14 with MockServiceManager

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());
}
Also used : HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) MockServiceManager(com.newrelic.agent.MockServiceManager) PointCutConfiguration(com.newrelic.agent.instrumentation.PointCutConfiguration) Test(org.junit.Test)

Example 15 with MockServiceManager

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());
}
Also used : HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) ServiceManager(com.newrelic.agent.service.ServiceManager) MockServiceManager(com.newrelic.agent.MockServiceManager) PointCutConfiguration(com.newrelic.agent.instrumentation.PointCutConfiguration) Test(org.junit.Test)

Aggregations

MockServiceManager (com.newrelic.agent.MockServiceManager)127 ConfigService (com.newrelic.agent.config.ConfigService)61 Test (org.junit.Test)49 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)48 HashMap (java.util.HashMap)44 TransactionService (com.newrelic.agent.TransactionService)42 MockRPMService (com.newrelic.agent.MockRPMService)37 ThreadService (com.newrelic.agent.ThreadService)34 AgentConfig (com.newrelic.agent.config.AgentConfig)34 AttributesService (com.newrelic.agent.attributes.AttributesService)28 HarvestService (com.newrelic.agent.HarvestService)27 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)27 MockHarvestService (com.newrelic.agent.MockHarvestService)26 MockCoreService (com.newrelic.agent.MockCoreService)21 StatsService (com.newrelic.agent.stats.StatsService)21 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)21 Before (org.junit.Before)19 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)16 SqlTraceServiceImpl (com.newrelic.agent.sql.SqlTraceServiceImpl)16 SqlTraceService (com.newrelic.agent.sql.SqlTraceService)15