Search in sources :

Example 46 with StatsEngine

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());
}
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 47 with StatsEngine

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());
}
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 48 with StatsEngine

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();
    }
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 49 with StatsEngine

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();
    }
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionData(com.newrelic.agent.TransactionData) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 50 with StatsEngine

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();
    }
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Aggregations

StatsEngine (com.newrelic.agent.stats.StatsEngine)96 Test (org.junit.Test)78 TransactionDataList (com.newrelic.agent.TransactionDataList)36 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)31 TransactionData (com.newrelic.agent.TransactionData)29 HashMap (java.util.HashMap)25 JmxMetric (com.newrelic.agent.jmx.metrics.JmxMetric)20 StatsWork (com.newrelic.agent.stats.StatsWork)8 MockRPMService (com.newrelic.agent.MockRPMService)7 ArrayList (java.util.ArrayList)6 AgentConfigFactoryTest (com.newrelic.agent.config.AgentConfigFactoryTest)5 Environment (com.newrelic.agent.environment.Environment)5 MetricName (com.newrelic.agent.metric.MetricName)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 Attribute (javax.management.Attribute)5 MBeanServer (javax.management.MBeanServer)5 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)4 Stats (com.newrelic.agent.stats.Stats)4 HttpError (com.newrelic.agent.transport.HttpError)4 CountStatistic (javax.management.j2ee.statistics.CountStatistic)4