Search in sources :

Example 1 with RecordDataUsageMetric

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);
}
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 RecordDataUsageMetric

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);
}
Also used : Invocation(org.mockito.invocation.Invocation) RecordDataUsageMetric(com.newrelic.agent.stats.RecordDataUsageMetric) MockingDetails(org.mockito.MockingDetails) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Aggregations

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