Search in sources :

Example 11 with StatsService

use of com.newrelic.agent.stats.StatsService in project newrelic-java-agent by newrelic.

the class HarvestServiceTest method setup.

@Before
public void setup() throws Exception {
    AgentHelper.initializeConfig();
    ConfigService configService = ConfigServiceFactory.createConfigService(mock(Logger.class), false);
    MockServiceManager serviceManager = new MockServiceManager(configService);
    ServiceFactory.setServiceManager(serviceManager);
    serviceManager.start();
    Map<String, Object> settings = AgentConfigFactoryTest.createStagingMap();
    AgentConfig config = AgentConfigFactory.createAgentConfig(settings, null, null);
    Environment env = new Environment(config, "c:\\test\\log");
    EnvironmentService envService = Mockito.mock(EnvironmentService.class, new Returns(env));
    Mockito.doNothing().when(envService).stop();
    serviceManager.setEnvironmentService(envService);
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    ThreadService threadService = new ThreadService();
    serviceManager.setThreadService(threadService);
    StatsService statsService = new StatsServiceImpl();
    serviceManager.setStatsService(statsService);
    statsService.start();
}
Also used : StatsService(com.newrelic.agent.stats.StatsService) Logger(com.newrelic.api.agent.Logger) AgentConfig(com.newrelic.agent.config.AgentConfig) Returns(org.mockito.internal.stubbing.answers.Returns) ConfigService(com.newrelic.agent.config.ConfigService) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) Environment(com.newrelic.agent.environment.Environment) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) Before(org.junit.Before)

Example 12 with StatsService

use of com.newrelic.agent.stats.StatsService 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 13 with StatsService

use of com.newrelic.agent.stats.StatsService 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 14 with StatsService

use of com.newrelic.agent.stats.StatsService 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 15 with StatsService

use of com.newrelic.agent.stats.StatsService in project newrelic-java-agent by newrelic.

the class SegmentTest method createServiceManager.

private static void createServiceManager(Map<String, Object> map, ExpirationService expirationService) throws Exception {
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    serviceManager.start();
    ThreadService threadService = new ThreadService();
    serviceManager.setThreadService(threadService);
    AgentConfig agentConfig = AgentHelper.createAgentConfig(true, map, Collections.<String, Object>emptyMap());
    ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, map);
    serviceManager.setConfigService(configService);
    StatsService statsService = new StatsServiceImpl();
    serviceManager.setStatsService(statsService);
    MockCoreService agent = new MockCoreService();
    serviceManager.setCoreService(agent);
    HarvestService harvestService = new MockHarvestService();
    serviceManager.setHarvestService(harvestService);
    AsyncTransactionService asyncTxService = new AsyncTransactionService();
    serviceManager.setAsyncTransactionService(asyncTxService);
    TransactionService transactionService = new TransactionService();
    serviceManager.setTransactionService(transactionService);
    EnvironmentService envService = new EnvironmentServiceImpl();
    serviceManager.setEnvironmentService(envService);
    TransactionTraceService transactionTraceService = new TransactionTraceService();
    serviceManager.setTransactionTraceService(transactionTraceService);
    SqlTraceService sqlTraceService = new SqlTraceServiceImpl();
    serviceManager.setSqlTraceService(sqlTraceService);
    serviceManager.setAttributesService(new AttributesService());
    DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
    serviceManager.setDistributedTraceService(distributedTraceService);
    TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = new TransactionDataToDistributedTraceIntrinsics(distributedTraceService);
    serviceManager.setTransactionEventsService(new TransactionEventsService(transactionDataToDistributedTraceIntrinsics));
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    serviceManager.setExpirationService(expirationService);
}
Also used : SqlTraceServiceImpl(com.newrelic.agent.sql.SqlTraceServiceImpl) MockHarvestService(com.newrelic.agent.MockHarvestService) HarvestService(com.newrelic.agent.HarvestService) AsyncTransactionService(com.newrelic.agent.service.async.AsyncTransactionService) TransactionService(com.newrelic.agent.TransactionService) StatsService(com.newrelic.agent.stats.StatsService) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) AsyncTransactionService(com.newrelic.agent.service.async.AsyncTransactionService) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) TransactionDataToDistributedTraceIntrinsics(com.newrelic.agent.service.analytics.TransactionDataToDistributedTraceIntrinsics) ThreadService(com.newrelic.agent.ThreadService) AgentConfig(com.newrelic.agent.config.AgentConfig) SqlTraceService(com.newrelic.agent.sql.SqlTraceService) ConfigService(com.newrelic.agent.config.ConfigService) EnvironmentServiceImpl(com.newrelic.agent.environment.EnvironmentServiceImpl) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) TransactionEventsService(com.newrelic.agent.service.analytics.TransactionEventsService) MockCoreService(com.newrelic.agent.MockCoreService) MockHarvestService(com.newrelic.agent.MockHarvestService) EnvironmentService(com.newrelic.agent.environment.EnvironmentService)

Aggregations

StatsService (com.newrelic.agent.stats.StatsService)33 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)24 MockServiceManager (com.newrelic.agent.MockServiceManager)18 ConfigService (com.newrelic.agent.config.ConfigService)17 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)16 MockRPMService (com.newrelic.agent.MockRPMService)14 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)13 TransactionService (com.newrelic.agent.TransactionService)13 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)13 HarvestService (com.newrelic.agent.HarvestService)11 MockCoreService (com.newrelic.agent.MockCoreService)11 MockHarvestService (com.newrelic.agent.MockHarvestService)11 ThreadService (com.newrelic.agent.ThreadService)11 AgentConfig (com.newrelic.agent.config.AgentConfig)11 SqlTraceService (com.newrelic.agent.sql.SqlTraceService)10 SqlTraceServiceImpl (com.newrelic.agent.sql.SqlTraceServiceImpl)10 AttributesService (com.newrelic.agent.attributes.AttributesService)9 DistributedTraceServiceImpl (com.newrelic.agent.tracing.DistributedTraceServiceImpl)8 EnvironmentService (com.newrelic.agent.environment.EnvironmentService)7 EnvironmentServiceImpl (com.newrelic.agent.environment.EnvironmentServiceImpl)7