use of com.newrelic.agent.stats.StatsEngine 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.StatsEngine 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.StatsEngine in project newrelic-java-agent by newrelic.
the class ExpectedErrorsTest method expectedErrorNoTransaction.
@Test
public void expectedErrorNoTransaction() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("expected_error_test");
try {
try {
throwExceptionNoTransaction("something");
fail("The expected exception was not thrown");
} catch (Throwable t) {
}
// Verify the transaction was created and finished
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(0, transactionList.size());
StatsEngine statsEngine = holder.getStatsEngine();
assertEquals(0, statsEngine.getStats("Errors/all").getCallCount());
assertEquals(1, statsEngine.getStats("ErrorsExpected/all").getCallCount());
verifyExpectedErrorSupportabilityApiCalls(statsEngine, 0, 0, 1, 0);
verifyIgnoreErrorSupportabilityApiCalls(statsEngine, 0, 0, 0);
} finally {
holder.close();
}
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class ExpectedErrorsTest method expectedErrorWrongMessage.
@Test
public void expectedErrorWrongMessage() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("expected_error_bad_message_test");
try {
try {
throwException("pleasen be right");
fail("The expected exception was not thrown");
} catch (Throwable t) {
}
// Verify the transaction was created and finished
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(1, transactionList.size());
TransactionData td = transactionList.get(0);
assertEquals("OtherTransaction/Custom/test.newrelic.test.agent.ExpectedErrorsTest/throwException", td.getPriorityTransactionName().getName());
StatsEngine statsEngine = holder.getStatsEngine();
assertEquals(0, statsEngine.getStats("ErrorsExpected/all").getCallCount());
assertEquals(1, statsEngine.getStats("Errors/all").getCallCount());
verifyExpectedErrorSupportabilityApiCalls(statsEngine, 0, 0, 0, 1);
verifyIgnoreErrorSupportabilityApiCalls(statsEngine, 0, 1, 0);
} finally {
holder.close();
}
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class ExpectedErrorsTest method nonExpectedErrorNoTransaction.
@Test
public void nonExpectedErrorNoTransaction() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("non_expected_error_test");
try {
try {
throwExceptionNoTransaction("something");
fail("The expected exception was not thrown");
} catch (Throwable t) {
}
// Verify the transaction was created and finished
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(0, transactionList.size());
StatsEngine statsEngine = holder.getStatsEngine();
assertEquals(0, statsEngine.getStats("ErrorsExpected/all").getCallCount());
assertEquals(1, statsEngine.getStats("Errors/all").getCallCount());
verifyExpectedErrorSupportabilityApiCalls(statsEngine, 0, 0, 1, 0);
verifyIgnoreErrorSupportabilityApiCalls(statsEngine, 0, 0, 0);
} finally {
holder.close();
}
}
Aggregations