Search in sources :

Example 1 with IncrementCounter

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

the class DataSenderImplTest method assertMetricWasRecorded.

/**
 * Verify that a given metric was created
 *
 * @param expectedMetricName name of metric to verify
 */
private void assertMetricWasRecorded(String expectedMetricName) {
    boolean found = false;
    MockingDetails output = Mockito.mockingDetails(mockStatsService);
    for (Invocation invocation : output.getInvocations()) {
        if (found) {
            break;
        }
        String methodName = invocation.getMethod().getName();
        Object rawArgument = invocation.getRawArguments()[0];
        if (rawArgument instanceof IncrementCounter) {
            String metricName = invocation.<IncrementCounter>getArgument(0).getName();
            found = methodName.equals("doStatsWork") && metricName.equals(expectedMetricName);
        } else if (rawArgument instanceof RecordDataUsageMetric) {
            String metricName = invocation.<RecordDataUsageMetric>getArgument(0).getName();
            found = methodName.equals("doStatsWork") && metricName.equals(expectedMetricName);
        }
    }
    assertTrue("Could not find metric: " + expectedMetricName, found);
}
Also used : IncrementCounter(com.newrelic.agent.stats.IncrementCounter) Invocation(org.mockito.invocation.Invocation) RecordDataUsageMetric(com.newrelic.agent.stats.RecordDataUsageMetric) MockingDetails(org.mockito.MockingDetails) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 2 with IncrementCounter

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

the class CloudUtilityTest method recordsMetric.

@Test
public void recordsMetric() {
    ArgumentCaptor<StatsWork> captor = ArgumentCaptor.forClass(StatsWork.class);
    doNothing().when(mockStatsService).doStatsWork(captor.capture(), anyString());
    new CloudUtility().recordError("some error");
    verify(mockStatsService, times(1)).doStatsWork(any(StatsWork.class), anyString());
    StatsWork argument = captor.getValue();
    assertTrue(argument instanceof IncrementCounter);
    assertEquals("some error", ((IncrementCounter) argument).getName());
}
Also used : IncrementCounter(com.newrelic.agent.stats.IncrementCounter) StatsWork(com.newrelic.agent.stats.StatsWork) Test(org.junit.Test)

Aggregations

IncrementCounter (com.newrelic.agent.stats.IncrementCounter)2 RecordDataUsageMetric (com.newrelic.agent.stats.RecordDataUsageMetric)1 StatsWork (com.newrelic.agent.stats.StatsWork)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 MockingDetails (org.mockito.MockingDetails)1 Invocation (org.mockito.invocation.Invocation)1