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();
}
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());
}
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());
}
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;
}
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);
}
Aggregations