Search in sources :

Example 1 with MetricSet

use of com.codahale.metrics.MetricSet in project alluxio by Alluxio.

the class AlluxioMasterRestServiceHandlerTest method getMetrics.

@Test
public void getMetrics() {
    final int FILES_PINNED_TEST_VALUE = 100;
    String filesPinnedProperty = MetricsSystem.getMasterMetricName(FileSystemMaster.Metrics.FILES_PINNED);
    Gauge<Integer> filesPinnedGauge = new Gauge<Integer>() {

        @Override
        public Integer getValue() {
            return FILES_PINNED_TEST_VALUE;
        }
    };
    MetricSet mockMetricsSet = mock(MetricSet.class);
    Map<String, Metric> map = new HashMap<>();
    map.put(filesPinnedProperty, filesPinnedGauge);
    when(mockMetricsSet.getMetrics()).thenReturn(map);
    MetricsSystem.METRIC_REGISTRY.registerAll(mockMetricsSet);
    Response response = mHandler.getMetrics();
    try {
        assertNotNull("Response must be not null!", response);
        assertNotNull("Response must have a entry!", response.getEntity());
        assertTrue("Entry must be a SortedMap!", (response.getEntity() instanceof SortedMap));
        SortedMap<String, Long> metricsMap = (SortedMap<String, Long>) response.getEntity();
        assertFalse("Metrics Map must be not empty!", (metricsMap.isEmpty()));
        assertTrue("Map must contain key " + filesPinnedProperty + "!", metricsMap.containsKey(filesPinnedProperty));
        assertEquals(FILES_PINNED_TEST_VALUE, metricsMap.get(filesPinnedProperty).longValue());
    } finally {
        response.close();
    }
}
Also used : HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) Gauge(com.codahale.metrics.Gauge) MetricSet(com.codahale.metrics.MetricSet) Response(javax.ws.rs.core.Response) SortedMap(java.util.SortedMap) Metric(com.codahale.metrics.Metric) Test(org.junit.Test)

Aggregations

Gauge (com.codahale.metrics.Gauge)1 Metric (com.codahale.metrics.Metric)1 MetricSet (com.codahale.metrics.MetricSet)1 HashMap (java.util.HashMap)1 SortedMap (java.util.SortedMap)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1