Search in sources :

Example 51 with MockServiceManager

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

the class ErrorServiceTest method harvest.

@Test
public void harvest() throws Exception {
    Map<String, Object> config = createConfig("java.lang.Exception");
    EventTestHelper.createServiceManager(config);
    MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMService();
    rpmService.setIsConnected(false);
    ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
    ErrorCollectorConfig errorCollectorConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getErrorCollectorConfig();
    TracedError error = HttpTracedError.builder(errorCollectorConfig, APP_NAME, "dude", System.currentTimeMillis()).statusCodeAndMessage(403, null).requestUri("/dude").build();
    errorService.reportError(error);
    StatsService spy = spy(new StatsServiceImpl());
    StatsEngine statsEngine = spy.getStatsEngineForHarvest(APP_NAME);
    ((MockServiceManager) ServiceFactory.getServiceManager()).setStatsService(spy);
    List<TracedError> actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
    Assert.assertEquals(0, actualErrors.size());
    Assert.assertEquals(1, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
    rpmService.setIsConnected(true);
    actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
    Assert.assertEquals(1, actualErrors.size());
    Assert.assertEquals(1, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
}
Also used : StatsService(com.newrelic.agent.stats.StatsService) ErrorCollectorConfig(com.newrelic.agent.config.ErrorCollectorConfig) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) StatsEngine(com.newrelic.agent.stats.StatsEngine) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 52 with MockServiceManager

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

the class ErrorServiceTest method errorCountMetrics.

@Test
public void errorCountMetrics() throws Exception {
    Map<String, Object> config = createConfig("java.lang.Exception");
    EventTestHelper.createServiceManager(config);
    MockRPMService rpmService = (MockRPMService) ServiceFactory.getRPMService();
    rpmService.setIsConnected(true);
    TransactionService txService = ServiceFactory.getTransactionService();
    Throwable error = new ArrayIndexOutOfBoundsException();
    TransactionData data = createTransactionData(true, 0, error, false);
    TransactionStats transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats("Errors/WebTransaction/Uri/dude").getCallCount());
    Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats(MetricNames.WEB_TRANSACTION_ERRORS_ALL).getCallCount());
    data = createTransactionData(true, 0, null, false);
    transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats("Errors/WebTransaction/Uri/dude").getCallCount());
    Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats(MetricNames.WEB_TRANSACTION_ERRORS_ALL).getCallCount());
    data = createTransactionData(false, 0, error, false);
    transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats("Errors/OtherTransaction/Custom/dude").getCallCount());
    Assert.assertEquals(1, transactionStats.getUnscopedStats().getStats(MetricNames.OTHER_TRANSACTION_ERRORS_ALL).getCallCount());
    data = createTransactionData(false, 0, null, false);
    transactionStats = new TransactionStats();
    txService.transactionFinished(data, transactionStats);
    Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats("Errors/OtherTransaction/Custom/dude").getCallCount());
    Assert.assertEquals(0, transactionStats.getUnscopedStats().getStats(MetricNames.WEB_TRANSACTION_ERRORS_ALL).getCallCount());
    StatsService spy = spy(new StatsServiceImpl());
    ((MockServiceManager) ServiceFactory.getServiceManager()).setStatsService(spy);
    ErrorServiceImpl errorService = (ErrorServiceImpl) ServiceFactory.getRPMService().getErrorService();
    StatsEngine statsEngine = spy.getStatsEngineForHarvest(APP_NAME);
    List<TracedError> actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
    Assert.assertEquals(2, actualErrors.size());
    Assert.assertEquals(2, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
    spy = spy(new StatsServiceImpl());
    ((MockServiceManager) ServiceFactory.getServiceManager()).setStatsService(spy);
    statsEngine = spy.getStatsEngineForHarvest(APP_NAME);
    actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
    Assert.assertEquals(0, actualErrors.size());
    Assert.assertEquals(0, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
    data = createTransactionData(true, 0, error, false);
    txService.transactionFinished(data, new TransactionStats());
    spy = spy(new StatsServiceImpl());
    ((MockServiceManager) ServiceFactory.getServiceManager()).setStatsService(spy);
    statsEngine = spy.getStatsEngineForHarvest(APP_NAME);
    actualErrors = errorService.getAndClearTracedErrors(APP_NAME, statsEngine);
    Assert.assertEquals(1, actualErrors.size());
    Assert.assertEquals(1, statsEngine.getStats(MetricNames.ERRORS_ALL).getCallCount());
}
Also used : TransactionService(com.newrelic.agent.TransactionService) StatsService(com.newrelic.agent.stats.StatsService) StatsEngine(com.newrelic.agent.stats.StatsEngine) TransactionStats(com.newrelic.agent.stats.TransactionStats) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) TransactionData(com.newrelic.agent.TransactionData) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 53 with MockServiceManager

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

the class AgentTestUtils method createServiceManager.

public static MockServiceManager createServiceManager(Map<String, Object> configMap) throws Exception {
    AgentConfig config = AgentConfigImpl.createAgentConfig(configMap);
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    ConfigService configService = ConfigServiceFactory.createConfigService(config, configMap);
    serviceManager.setConfigService(configService);
    ThreadService threadService = new ThreadService();
    serviceManager.setThreadService(threadService);
    HarvestService harvestService = new MockHarvestService();
    serviceManager.setHarvestService(harvestService);
    TransactionService transactionService = new TransactionService();
    serviceManager.setTransactionService(transactionService);
    StatsService statsService = new StatsServiceImpl();
    serviceManager.setStatsService(statsService);
    DatabaseService dbService = new DatabaseService();
    serviceManager.setDatabaseService(dbService);
    SqlTraceService sqlTraceService = new SqlTraceServiceImpl();
    serviceManager.setSqlTraceService(sqlTraceService);
    MockCoreService agent = new MockCoreService();
    serviceManager.setCoreService(agent);
    TransactionTraceService transactionTraceService = new TransactionTraceService();
    serviceManager.setTransactionTraceService(transactionTraceService);
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    MockRPMService rpmService = new MockRPMService();
    rpmService.setApplicationName("name");
    rpmService.setEverConnected(true);
    rpmService.setErrorService(new ErrorServiceImpl("name"));
    rpmServiceManager.setRPMService(rpmService);
    configService.start();
    serviceManager.start();
    sqlTraceService.start();
    return serviceManager;
}
Also used : SqlTraceServiceImpl(com.newrelic.agent.sql.SqlTraceServiceImpl) MockHarvestService(com.newrelic.agent.MockHarvestService) HarvestService(com.newrelic.agent.HarvestService) TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) StatsService(com.newrelic.agent.stats.StatsService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) DatabaseService(com.newrelic.agent.database.DatabaseService) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) AgentConfig(com.newrelic.agent.config.AgentConfig) ThreadService(com.newrelic.agent.ThreadService) SqlTraceService(com.newrelic.agent.sql.SqlTraceService) ConfigService(com.newrelic.agent.config.ConfigService) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) MockHarvestService(com.newrelic.agent.MockHarvestService) MockCoreService(com.newrelic.agent.MockCoreService) MockRPMService(com.newrelic.agent.MockRPMService)

Example 54 with MockServiceManager

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

the class OptimizedClassMatcherTest method initializeServiceManager.

private void initializeServiceManager() {
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    Map<String, Object> confProps = new HashMap<>();
    confProps.put(AgentConfigImpl.APP_NAME, "Hello");
    MockConfigService service = new MockConfigService(AgentConfigImpl.createAgentConfig(confProps));
    serviceManager.setConfigService(service);
}
Also used : HashMap(java.util.HashMap) MockServiceManager(com.newrelic.agent.MockServiceManager) MockConfigService(com.newrelic.agent.MockConfigService)

Example 55 with MockServiceManager

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

the class IncludeExcludeTest method createServiceManager.

private void createServiceManager(Map<String, Object> configMap) throws Exception {
    ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(configMap), configMap);
    MockServiceManager serviceManager = new MockServiceManager(configService);
    ServiceFactory.setServiceManager(serviceManager);
    JarCollectorService mockJarCollector = serviceManager.getJarCollectorService();
    when(mockJarCollector.getSourceVisitor()).thenReturn(ClassMatchVisitorFactory.NO_OP_FACTORY);
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) JarCollectorService(com.newrelic.agent.service.module.JarCollectorService) MockServiceManager(com.newrelic.agent.MockServiceManager)

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