use of com.newrelic.agent.MockRPMServiceManager in project newrelic-java-agent by newrelic.
the class RequestUriConfigTests method createServiceManager.
private void createServiceManager(Map<String, Object> configMap) throws Exception {
ConfigService configService = ConfigServiceFactory.createConfigServiceUsingSettings(configMap);
MockServiceManager serviceManager = new MockServiceManager(configService);
ServiceFactory.setServiceManager(serviceManager);
serviceManager.setHarvestService(new MockHarvestService());
serviceManager.setSqlTraceService(new SqlTraceServiceImpl());
serviceManager.setAttributesService(new AttributesService());
serviceManager.setNormalizationService(new NormalizationServiceImpl());
MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName(serviceManager.getConfigService().getDefaultAgentConfig().getApplicationName());
rpmService.setEverConnected(true);
rpmService.setIsConnected(true);
rpmService.setErrorService(new ErrorServiceImpl(serviceManager.getConfigService().getDefaultAgentConfig().getApplicationName()));
rpmServiceManager.setRPMService(rpmService);
serviceManager.start();
}
use of com.newrelic.agent.MockRPMServiceManager in project newrelic-java-agent by newrelic.
the class BrowserConfigTest method setupManager.
public void setupManager(boolean captureParams, boolean setSslForHttpToTrue) {
MockServiceManager manager = new MockServiceManager();
ServiceFactory.setServiceManager(manager);
Map<String, Object> params = new HashMap<>();
if (captureParams || setSslForHttpToTrue) {
Map<String, Object> bProps = new HashMap<>();
params.put("browser_monitoring", bProps);
if (captureParams) {
Map<String, Object> baProps = new HashMap<>();
bProps.put("attributes", baProps);
baProps.put("enabled", Boolean.TRUE);
}
if (setSslForHttpToTrue) {
bProps.put("ssl_for_http", Boolean.TRUE);
}
}
params.put("license_key", LICENSE_KEY);
ImmutableMap<String, Object> distributedTracingSettings = ImmutableMap.<String, Object>builder().put(DistributedTracingConfig.ENABLED, Boolean.FALSE).build();
params.put(AgentConfigImpl.DISTRIBUTED_TRACING, distributedTracingSettings);
manager.setConfigService(ConfigServiceFactory.createConfigServiceUsingSettings(params));
manager.setTransactionService(new TransactionService());
manager.setTransactionTraceService(new TransactionTraceService());
MockRPMServiceManager rpmServiceMgr = new MockRPMServiceManager();
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName(APP_NAME);
rpmService.setEverConnected(true);
rpmService.setErrorService(new ErrorServiceImpl(APP_NAME));
rpmServiceMgr.setRPMService(rpmService);
manager.setRPMServiceManager(rpmServiceMgr);
AttributesService attService = new AttributesService();
manager.setAttributesService(attService);
ServiceFactory.setServiceManager(manager);
Transaction.clearTransaction();
}
use of com.newrelic.agent.MockRPMServiceManager in project newrelic-java-agent by newrelic.
the class ConfigServiceTest method connectionListenerAndErrorEvents.
@Test
public void connectionListenerAndErrorEvents() throws Exception {
Map<String, Object> configMap = AgentConfigFactoryTest.createStagingMap();
createServiceManager(configMap);
ConfigService configService = ServiceFactory.getConfigService();
MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
// test defaults
MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
String appName = rpmService.getApplicationName();
String appName2 = "bogus";
Map<String, Object> data = new HashMap<>();
Map<String, Object> agentData = new HashMap<>();
data.put(AgentConfigFactory.AGENT_CONFIG, agentData);
assertTrue(configService.getAgentConfig(appName).getErrorCollectorConfig().isEventsEnabled());
assertTrue(configService.getAgentConfig(appName2).getErrorCollectorConfig().isEventsEnabled());
assertEquals(100, configService.getAgentConfig(appName).getErrorCollectorConfig().getMaxSamplesStored());
assertEquals(100, configService.getAgentConfig(appName2).getErrorCollectorConfig().getMaxSamplesStored());
// test collector shut off
data.put(ErrorCollectorConfigImpl.COLLECT_EVENTS, false);
connectionConfigListener.connected(rpmService, data);
assertFalse(configService.getAgentConfig(appName).getErrorCollectorConfig().isEventsEnabled());
assertTrue(configService.getAgentConfig(appName2).getErrorCollectorConfig().isEventsEnabled());
assertEquals(100, configService.getAgentConfig(appName).getErrorCollectorConfig().getMaxSamplesStored());
assertEquals(100, configService.getAgentConfig(appName2).getErrorCollectorConfig().getMaxSamplesStored());
// test config shut off and max event count
rpmService = new MockRPMService();
rpmService.setApplicationName(appName2);
agentData.put(AgentConfigFactory.CAPTURE_ERROR_EVENTS, false);
agentData.put(AgentConfigFactory.MAX_ERROR_EVENT_SAMPLES_STORED, 20);
connectionConfigListener.connected(rpmService, data);
assertFalse(configService.getAgentConfig(appName).getErrorCollectorConfig().isEventsEnabled());
assertFalse(configService.getAgentConfig(appName2).getErrorCollectorConfig().isEventsEnabled());
assertEquals(100, configService.getAgentConfig(appName).getErrorCollectorConfig().getMaxSamplesStored());
assertEquals(20, configService.getAgentConfig(appName2).getErrorCollectorConfig().getMaxSamplesStored());
}
use of com.newrelic.agent.MockRPMServiceManager in project newrelic-java-agent by newrelic.
the class ConfigServiceTest method createServiceManager.
private void createServiceManager(Map<String, Object> configMap) throws Exception {
ConfigService configService = ConfigServiceFactory.createConfigServiceUsingSettings(configMap);
MockServiceManager serviceManager = new MockServiceManager(configService);
ServiceFactory.setServiceManager(serviceManager);
MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName("Unit Test");
rpmServiceManager.setRPMService(rpmService);
HarvestService harvestService = new MockHarvestService();
serviceManager.setHarvestService(harvestService);
configService.start();
serviceManager.start();
}
use of com.newrelic.agent.MockRPMServiceManager in project newrelic-java-agent by newrelic.
the class ConfigServiceTest method connectionListener.
@Test
public void connectionListener() throws Exception {
Map<String, Object> configMap = AgentConfigFactoryTest.createStagingMap();
createServiceManager(configMap);
ConfigService configService = ServiceFactory.getConfigService();
MockRPMServiceManager rpmServiceManager = (MockRPMServiceManager) ServiceFactory.getRPMServiceManager();
ConnectionConfigListener connectionConfigListener = rpmServiceManager.getConnectionConfigListener();
MockRPMService rpmService = (MockRPMService) rpmServiceManager.getRPMService();
String appName = rpmService.getApplicationName();
String appName2 = "bogus";
Map<String, Object> data = new HashMap<>();
Map<String, Object> agentData = new HashMap<>();
data.put(AgentConfigFactory.AGENT_CONFIG, agentData);
data.put(AgentConfigImpl.APDEX_T, 0.500d);
data.put(TransactionTracerConfigImpl.COLLECT_TRACES, true);
data.put(ErrorCollectorConfigImpl.COLLECT_ERRORS, true);
agentData.put(AgentConfigFactory.TRANSACTION_TRACER_PREFIX + TransactionTracerConfigImpl.ENABLED, true);
agentData.put(AgentConfigFactory.ERROR_COLLECTOR_PREFIX + ErrorCollectorConfigImpl.ENABLED, true);
assertFalse(configService.getAgentConfig(appName).getTransactionTracerConfig().isEnabled());
assertFalse(configService.getAgentConfig(appName2).getTransactionTracerConfig().isEnabled());
assertTrue(configService.getAgentConfig(appName).getErrorCollectorConfig().isEnabled());
assertTrue(configService.getAgentConfig(appName2).getErrorCollectorConfig().isEnabled());
connectionConfigListener.connected(rpmService, data);
assertEquals(500L, configService.getAgentConfig(appName).getApdexTInMillis());
assertEquals(1000L, configService.getAgentConfig(appName2).getApdexTInMillis());
assertTrue(configService.getAgentConfig(appName).getTransactionTracerConfig().isEnabled());
assertFalse(configService.getAgentConfig(appName2).getTransactionTracerConfig().isEnabled());
assertTrue(configService.getAgentConfig(appName).getErrorCollectorConfig().isEnabled());
assertTrue(configService.getAgentConfig(appName2).getErrorCollectorConfig().isEnabled());
data.put(AgentConfigImpl.APDEX_T, 1.500d);
connectionConfigListener.connected(rpmService, data);
assertEquals(1500L, configService.getAgentConfig(appName).getApdexTInMillis());
assertEquals(1000L, configService.getAgentConfig(appName2).getApdexTInMillis());
rpmService = new MockRPMService();
rpmService.setApplicationName(appName2);
data.put(AgentConfigImpl.APDEX_T, 2.000d);
connectionConfigListener.connected(rpmService, data);
assertEquals(1500L, configService.getAgentConfig(appName).getApdexTInMillis());
assertEquals(2000L, configService.getAgentConfig(appName2).getApdexTInMillis());
}
Aggregations