use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.
the class CPUSamplerTest method createServiceManager.
private MockServiceManager createServiceManager(Map<String, Object> map) throws Exception {
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
ThreadService threadService = new ThreadService();
serviceManager.setThreadService(threadService);
ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(map), map);
serviceManager.setConfigService(configService);
TransactionService transactionService = new TransactionService();
serviceManager.setTransactionService(transactionService);
ProfilerService profilerService = new ProfilerService();
serviceManager.setProfilerService(profilerService);
return serviceManager;
}
use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.
the class CustomInsightsEventsConfigUtilsTest method testEnabled.
@Test
public void testEnabled() {
// setup
Map<String, Object> root = new HashMap<>();
Map<String, Object> customEvents = new HashMap<>();
root.put("custom_insights_events", customEvents);
customEvents.put(InsightsConfigImpl.MAX_SAMPLES_STORED_PROP, 10);
MockServiceManager mockServiceManager = new MockServiceManager();
ServiceFactory.setServiceManager(mockServiceManager);
mockServiceManager.setConfigService(Mockito.mock(ConfigService.class));
// start with the default
AgentConfig config = AgentConfigImpl.createAgentConfig(root);
Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
Assert.assertTrue(config.getInsightsConfig().isEnabled());
// high security enabled
root.put(AgentConfigImpl.HIGH_SECURITY, true);
config = AgentConfigImpl.createAgentConfig(root);
Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
Assert.assertFalse(config.getInsightsConfig().isEnabled());
// high security disabled
root.put(AgentConfigImpl.HIGH_SECURITY, false);
config = AgentConfigImpl.createAgentConfig(root);
Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
Assert.assertTrue(config.getInsightsConfig().isEnabled());
// no samples
customEvents.put(InsightsConfigImpl.MAX_SAMPLES_STORED_PROP, 0);
config = AgentConfigImpl.createAgentConfig(root);
Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
Assert.assertFalse(config.getInsightsConfig().isEnabled());
customEvents.put(InsightsConfigImpl.MAX_SAMPLES_STORED_PROP, 10);
// go through both properties
customEvents.clear();
customEvents.put(InsightsConfigImpl.ENABLED_PROP, false);
config = AgentConfigImpl.createAgentConfig(root);
Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
Assert.assertFalse(config.getInsightsConfig().isEnabled());
// Transaction Events feature gate should have no effect.
customEvents.clear();
customEvents.put("collect_analytics_events", false);
config = AgentConfigImpl.createAgentConfig(root);
Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
Assert.assertTrue(config.getInsightsConfig().isEnabled());
// Test Custom Events feature gate:
customEvents.clear();
customEvents.put("collect_custom_events", false);
config = AgentConfigImpl.createAgentConfig(root);
Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
Assert.assertFalse(config.getInsightsConfig().isEnabled());
// set both
customEvents.clear();
customEvents.put(InsightsConfigImpl.ENABLED_PROP, true);
customEvents.put("collect_custom_events", false);
config = AgentConfigImpl.createAgentConfig(root);
Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
Assert.assertFalse(config.getInsightsConfig().isEnabled());
customEvents.clear();
customEvents.put(InsightsConfigImpl.ENABLED_PROP, false);
customEvents.put("collect_custom_events", true);
config = AgentConfigImpl.createAgentConfig(root);
Mockito.when(ServiceFactory.getConfigService().getDefaultAgentConfig()).thenReturn(config);
Assert.assertFalse(config.getInsightsConfig().isEnabled());
}
use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.
the class EventTestHelper method createServiceManager.
public static void createServiceManager(Map<String, Object> config) throws Exception {
if (APP_NAME == null || APP_NAME.isEmpty()) {
APP_NAME = "Unit Test";
}
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
serviceManager.start();
ThreadService threadService = new ThreadService();
serviceManager.setThreadService(threadService);
MockCoreService agent = new MockCoreService();
serviceManager.setCoreService(agent);
ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(config), config);
serviceManager.setConfigService(configService);
StatsService statsService = new StatsServiceImpl();
serviceManager.setStatsService(statsService);
TransactionService txService = new TransactionService();
serviceManager.setTransactionService(txService);
TransactionTraceService ttService = new TransactionTraceService();
serviceManager.setTransactionTraceService(ttService);
MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName(APP_NAME);
rpmServiceManager.setRPMService(rpmService);
ErrorServiceImpl errorService = new ErrorServiceImpl(APP_NAME);
rpmService.setErrorService(errorService);
AttributesService attService = new AttributesService();
serviceManager.setAttributesService(attService);
serviceManager.setDistributedTraceService(new DistributedTraceServiceImpl());
serviceManager.setRPMServiceManager(rpmServiceManager);
}
use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.
the class InsightsServiceImplTest method testCustomEventFasterHarvest.
@Test
public void testCustomEventFasterHarvest() throws Exception {
Map<String, Object> config = new HashMap<>();
config.put(AgentConfigImpl.APP_NAME, EventTestHelper.APP_NAME);
EventTestHelper.createServiceManager(config);
String appName = ServiceFactory.getRPMService().getApplicationName();
InsightsServiceImpl insightsService = new InsightsServiceImpl();
((MockServiceManager) ServiceFactory.getServiceManager()).setInsights(insightsService);
ServiceManager serviceManager = spy(ServiceFactory.getServiceManager());
ServiceFactory.setServiceManager(serviceManager);
HarvestServiceImpl harvestService = spy(new HarvestServiceImpl());
doReturn(harvestService).when(serviceManager).getHarvestService();
doReturn(0L).when(harvestService).getInitialDelay();
insightsService.addHarvestableToService(appName);
insightsService.configureHarvestables(60, 10);
assertEquals(10, insightsService.getMaxSamplesStored());
insightsService.start();
Map<String, Object> connectionInfo = new HashMap<>();
Map<String, Object> eventHarvest = new HashMap<>();
Map<String, Object> harvestLimits = new HashMap<>();
// 5 is the lowest allowable value
eventHarvest.put("report_period_ms", 5000L);
eventHarvest.put("harvest_limits", harvestLimits);
harvestLimits.put("custom_event_data", 1L);
connectionInfo.put("event_harvest_config", eventHarvest);
harvestService.startHarvestables(ServiceFactory.getRPMService(), AgentConfigImpl.createAgentConfig(connectionInfo));
Thread.sleep(500);
Map<String, String> m = Collections.singletonMap("key", "value");
insightsService.recordCustomEvent("CustomEvent", m);
Thread.sleep(5050);
checkForEvent();
((MockRPMService) ServiceFactory.getRPMService()).clearEvents();
insightsService.recordCustomEvent("CustomEvent", m);
Thread.sleep(5050);
checkForEvent();
}
use of com.newrelic.agent.MockServiceManager in project newrelic-java-agent by newrelic.
the class SpringPointCutTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
serviceManager.start();
ThreadService threadService = new ThreadService();
serviceManager.setThreadService(threadService);
Map<String, Object> settings = AgentConfigFactoryTest.createStagingMap();
AgentConfig config = AgentConfigFactory.createAgentConfig(settings, null, null);
MockConfigService configService = new MockConfigService(null);
configService.setAgentConfig(config);
serviceManager.setConfigService(configService);
MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName("Unit Test");
rpmServiceManager.setRPMService(rpmService);
serviceManager.setNormalizationService(new NormalizationServiceImpl());
}
Aggregations