use of com.newrelic.agent.stats.RecordDataUsageMetric 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.RecordDataUsageMetric in project newrelic-java-agent by newrelic.
the class DataSenderImplTest method assertDataUsageMetricValues.
/**
* Verify the sent/received payload sizes recorded by a given RecordDataUsageMetric
*
* @param expectedMetricName name of metric to verify
* @param expectedBytesSent expected size of sent payload in bytes
* @param expectedBytesReceived expected size of received payload in bytes
*/
private void assertDataUsageMetricValues(String expectedMetricName, int expectedBytesSent, int expectedBytesReceived) {
boolean found = false;
MockingDetails output = Mockito.mockingDetails(mockStatsService);
for (Invocation invocation : output.getInvocations()) {
String methodName = invocation.getMethod().getName();
Object rawArgument = invocation.getRawArguments()[0];
if (rawArgument instanceof RecordDataUsageMetric) {
String metricName = invocation.<RecordDataUsageMetric>getArgument(0).getName();
found = methodName.equals("doStatsWork") && metricName.equals(expectedMetricName);
if (found) {
assertEquals(expectedBytesSent, ((RecordDataUsageMetric) rawArgument).getBytesSent());
assertEquals(expectedBytesReceived, ((RecordDataUsageMetric) rawArgument).getBytesReceived());
break;
}
}
}
assertTrue("Could not find metric: " + expectedMetricName, found);
}
Aggregations