Search in sources :

Example 1 with MockRPMServiceManager

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();
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) SqlTraceServiceImpl(com.newrelic.agent.sql.SqlTraceServiceImpl) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) MockHarvestService(com.newrelic.agent.MockHarvestService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) NormalizationServiceImpl(com.newrelic.agent.normalization.NormalizationServiceImpl)

Example 2 with MockRPMServiceManager

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();
}
Also used : TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) AttributesService(com.newrelic.agent.attributes.AttributesService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) MockRPMService(com.newrelic.agent.MockRPMService)

Example 3 with MockRPMServiceManager

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());
}
Also used : HashMap(java.util.HashMap) ConnectionConfigListener(com.newrelic.agent.ConnectionConfigListener) JSONObject(org.json.simple.JSONObject) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 4 with MockRPMServiceManager

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();
}
Also used : MockHarvestService(com.newrelic.agent.MockHarvestService) HarvestService(com.newrelic.agent.HarvestService) MockServiceManager(com.newrelic.agent.MockServiceManager) MockHarvestService(com.newrelic.agent.MockHarvestService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService)

Example 5 with MockRPMServiceManager

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());
}
Also used : HashMap(java.util.HashMap) ConnectionConfigListener(com.newrelic.agent.ConnectionConfigListener) JSONObject(org.json.simple.JSONObject) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Aggregations

MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)57 MockServiceManager (com.newrelic.agent.MockServiceManager)46 MockRPMService (com.newrelic.agent.MockRPMService)44 TransactionService (com.newrelic.agent.TransactionService)31 ConfigService (com.newrelic.agent.config.ConfigService)29 MockHarvestService (com.newrelic.agent.MockHarvestService)25 HarvestService (com.newrelic.agent.HarvestService)24 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)24 ThreadService (com.newrelic.agent.ThreadService)23 AttributesService (com.newrelic.agent.attributes.AttributesService)22 MockCoreService (com.newrelic.agent.MockCoreService)19 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)17 SqlTraceServiceImpl (com.newrelic.agent.sql.SqlTraceServiceImpl)16 HashMap (java.util.HashMap)16 Test (org.junit.Test)16 SqlTraceService (com.newrelic.agent.sql.SqlTraceService)15 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)15 AgentConfig (com.newrelic.agent.config.AgentConfig)14 StatsService (com.newrelic.agent.stats.StatsService)14 DistributedTraceServiceImpl (com.newrelic.agent.tracing.DistributedTraceServiceImpl)9