Search in sources :

Example 11 with MockRPMService

use of com.newrelic.agent.MockRPMService 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 12 with MockRPMService

use of com.newrelic.agent.MockRPMService 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)

Example 13 with MockRPMService

use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.

the class TransactionTraceServiceTest method createServiceManager.

private void createServiceManager(Map<String, Object> configMap) throws Exception {
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(configMap), configMap);
    serviceManager.setConfigService(configService);
    DatabaseService dbService = new DatabaseService();
    serviceManager.setDatabaseService(dbService);
    HarvestService harvestService = new MockHarvestService();
    serviceManager.setHarvestService(harvestService);
    TransactionService transactionService = new TransactionService();
    serviceManager.setTransactionService(transactionService);
    rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    MockRPMService rpmService = new MockRPMService();
    rpmService.setApplicationName(APP_NAME);
    rpmService.setIsConnected(true);
    rpmServiceManager.setRPMService(rpmService);
    CommandParser commandParser = new CommandParser();
    serviceManager.setCommandParser(commandParser);
    AttributesService attService = new AttributesService();
    serviceManager.setAttributesService(attService);
    TransactionTraceService ttService = new TransactionTraceService();
    serviceManager.setTransactionTraceService(ttService);
    ttService.start();
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) MockHarvestService(com.newrelic.agent.MockHarvestService) HarvestService(com.newrelic.agent.HarvestService) TransactionService(com.newrelic.agent.TransactionService) MockServiceManager(com.newrelic.agent.MockServiceManager) AttributesService(com.newrelic.agent.attributes.AttributesService) MockHarvestService(com.newrelic.agent.MockHarvestService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) DatabaseService(com.newrelic.agent.database.DatabaseService) MockRPMService(com.newrelic.agent.MockRPMService) CommandParser(com.newrelic.agent.commands.CommandParser)

Example 14 with MockRPMService

use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.

the class TransactionTraceServiceTest method transactionSamplers.

@Test
public void transactionSamplers() throws Exception {
    Map<String, Object> configMap = createConfigMap();
    Map<String, Object> ttConfigMap = new HashMap<>();
    configMap.put("transaction_tracer", ttConfigMap);
    ttConfigMap.put(TransactionTracerConfigImpl.ENABLED, true);
    ttConfigMap.put(TransactionTracerConfigImpl.COLLECT_TRACES, true);
    createServiceManager(configMap);
    TransactionTraceService ttService = ServiceFactory.getTransactionTraceService();
    ITransactionSampler transactionSampler = new ITransactionSampler() {

        private final List<TransactionData> tds = new ArrayList<>();

        @Override
        public boolean noticeTransaction(TransactionData td) {
            tds.add(td);
            return true;
        }

        @Override
        public List<TransactionTrace> harvest(String appName) {
            List<TransactionTrace> traces = new ArrayList<>();
            for (TransactionData td : tds) {
                TransactionTrace trace = TransactionTrace.getTransactionTrace(td);
                traces.add(trace);
            }
            return traces;
        }

        @Override
        public void stop() {
            tds.clear();
        }
    };
    ITransactionSampler transactionSampler2 = new ITransactionSampler() {

        private final List<TransactionData> tds = new ArrayList<>();

        @Override
        public boolean noticeTransaction(TransactionData td) {
            tds.add(td);
            return true;
        }

        @Override
        public List<TransactionTrace> harvest(String appName) {
            List<TransactionTrace> traces = new ArrayList<>();
            for (TransactionData td : tds) {
                TransactionTrace trace = TransactionTrace.getTransactionTrace(td);
                traces.add(trace);
            }
            return traces;
        }

        @Override
        public void stop() {
            tds.clear();
        }
    };
    ttService.addTransactionTraceSampler(transactionSampler);
    ttService.addTransactionTraceSampler(transactionSampler2);
    TransactionData td = createTransactionData("/en/betting/Baseball/*", APP_NAME, 100L);
    ttService.dispatcherTransactionFinished(td, null);
    ttService.afterHarvest(APP_NAME);
    MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMServiceManager().getOrCreateRPMService(APP_NAME);
    List<TransactionTrace> traces = rpmService.getTraces();
    Assert.assertEquals(1, traces.size());
    Assert.assertEquals("/en/betting/Baseball/*", traces.get(0).getRequestUri());
    Assert.assertEquals(100L, traces.get(0).getDuration());
    traces.clear();
    traces = rpmService.getTraces();
    Assert.assertEquals(0, traces.size());
    ttService.removeTransactionTraceSampler(transactionSampler);
    ttService.removeTransactionTraceSampler(transactionSampler2);
    ttService.dispatcherTransactionFinished(td, null);
    ttService.afterHarvest(APP_NAME);
    Assert.assertEquals(0, transactionSampler.harvest(APP_NAME).size());
    Assert.assertEquals(0, transactionSampler2.harvest(APP_NAME).size());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TransactionData(com.newrelic.agent.TransactionData) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 15 with MockRPMService

use of com.newrelic.agent.MockRPMService in project newrelic-java-agent by newrelic.

the class TransactionEventsServiceTest method setup.

private void setup(boolean enabled, boolean isAttsEnabled, int size) throws Exception {
    MockServiceManager manager = new MockServiceManager();
    ServiceFactory.setServiceManager(manager);
    Map<String, Object> settings = new HashMap<>();
    settings.put("app_name", APP_NAME);
    Map<String, Object> events = new HashMap<>();
    settings.put("transaction_events", events);
    events.put("max_samples_stored", size);
    events.put("enabled", enabled);
    Map<String, Object> atts = new HashMap<>();
    settings.put("attributes", atts);
    atts.put("enabled", isAttsEnabled);
    Map<String, Object> distributedTracing = new HashMap<>();
    distributedTracing.put("enabled", true);
    settings.put("distributed_tracing", distributedTracing);
    Map<String, Object> spanConfig = new HashMap<>();
    spanConfig.put("collect_span_events", true);
    settings.put("span_events", spanConfig);
    iAgentConfig = AgentConfigImpl.createAgentConfig(settings);
    configService = ConfigServiceFactory.createConfigService(iAgentConfig, settings);
    manager.setConfigService(configService);
    TransactionTraceService transactionTraceService = new TransactionTraceService();
    manager.setTransactionTraceService(transactionTraceService);
    environmentService = new EnvironmentServiceImpl();
    manager.setEnvironmentService(environmentService);
    AttributesService attService = new AttributesService();
    manager.setAttributesService(attService);
    TransactionService transactionService = new TransactionService();
    manager.setTransactionService(transactionService);
    StatsService statsService = new StatsServiceImpl();
    manager.setStatsService(statsService);
    HarvestService harvestService = new MockHarvestService();
    manager.setHarvestService(harvestService);
    // manager.setTransactionEventsService(new TransactionEventsService(mockDistributedTraceIntrinsics));
    DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
    Map<String, Object> connectInfo = new HashMap<>();
    connectInfo.put(DistributedTracingConfig.ACCOUNT_ID, "1acct234");
    connectInfo.put(DistributedTracingConfig.TRUSTED_ACCOUNT_KEY, "67890");
    AgentConfig agentConfig = AgentHelper.createAgentConfig(true, Collections.<String, Object>emptyMap(), connectInfo);
    distributedTraceService.connected(null, agentConfig);
    manager.setDistributedTraceService(distributedTraceService);
    rpmServiceManager = new MockRPMServiceManager();
    rpmService = new MockRPMService();
    rpmService.setApplicationName(APP_NAME);
    rpmServiceManager.setRPMService(rpmService);
    ErrorServiceImpl errorService = new ErrorServiceImpl(APP_NAME);
    rpmService.setErrorService(errorService);
    rpmServiceAppName2 = (MockRPMService) rpmServiceManager.getOrCreateRPMService(APP_NAME_2);
    rpmServiceAppName2.setErrorService(new ErrorServiceImpl(APP_NAME_2));
    mockDistributedTraceIntrinsics = mock(TransactionDataToDistributedTraceIntrinsics.class);
    service = new TransactionEventsService(mockDistributedTraceIntrinsics);
    manager.setTransactionEventsService(service);
    manager.setRPMServiceManager(rpmServiceManager);
    service.addHarvestableToService(APP_NAME);
    service.doStart();
}
Also used : TransactionService(com.newrelic.agent.TransactionService) MockHarvestService(com.newrelic.agent.MockHarvestService) HarvestService(com.newrelic.agent.HarvestService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) StatsService(com.newrelic.agent.stats.StatsService) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) AgentConfig(com.newrelic.agent.config.AgentConfig) EnvironmentServiceImpl(com.newrelic.agent.environment.EnvironmentServiceImpl) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) MockHarvestService(com.newrelic.agent.MockHarvestService) MockRPMService(com.newrelic.agent.MockRPMService)

Aggregations

MockRPMService (com.newrelic.agent.MockRPMService)97 Test (org.junit.Test)59 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)44 MockServiceManager (com.newrelic.agent.MockServiceManager)39 MockHarvestService (com.newrelic.agent.MockHarvestService)30 HashMap (java.util.HashMap)28 TransactionService (com.newrelic.agent.TransactionService)26 ConfigService (com.newrelic.agent.config.ConfigService)21 MockCoreService (com.newrelic.agent.MockCoreService)20 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)18 HarvestService (com.newrelic.agent.HarvestService)17 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)17 ThreadService (com.newrelic.agent.ThreadService)15 StatsService (com.newrelic.agent.stats.StatsService)15 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)15 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)15 SqlTracer (com.newrelic.agent.tracers.SqlTracer)15 Tracer (com.newrelic.agent.tracers.Tracer)15 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)15 TransactionData (com.newrelic.agent.TransactionData)14