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