Search in sources :

Example 1 with MetricValue

use of com.yahoo.container.jdisc.state.MetricValue in project vespa by vespa-engine.

the class SnapshotConverterTest method testConversion.

@Test
public void testConversion() {
    MetricReceiver mock = new MetricReceiver.MockReceiver();
    mock.declareCounter("foo").add(1);
    mock.declareGauge("quuux").sample(42.25);
    mock.declareCounter("bar", new Point(new HashMap<String, String>())).add(4);
    MetricSnapshot snapshot = new SnapshotConverter(mock.getSnapshot()).convert();
    for (Map.Entry<MetricDimensions, MetricSet> entry : snapshot) {
        for (Map.Entry<String, String> dv : entry.getKey()) {
            assertTrue(false);
        }
        int cnt = 0;
        for (Map.Entry<String, MetricValue> mv : entry.getValue()) {
            ++cnt;
            if ("foo".equals(mv.getKey())) {
                assertTrue(mv.getValue() instanceof CountMetric);
                assertEquals(1, ((CountMetric) mv.getValue()).getCount());
            } else if ("bar".equals(mv.getKey())) {
                assertTrue(mv.getValue() instanceof CountMetric);
                assertEquals(4, ((CountMetric) mv.getValue()).getCount());
            } else if ("quuux".equals(mv.getKey())) {
                assertTrue(mv.getValue() instanceof GaugeMetric);
                assertEquals(42.25, ((GaugeMetric) mv.getValue()).getLast(), 0.001);
                assertEquals(1, ((GaugeMetric) mv.getValue()).getCount());
            } else {
                assertTrue(false);
            }
        }
        assertEquals(3, cnt);
    }
}
Also used : MetricReceiver(com.yahoo.metrics.simple.MetricReceiver) MetricDimensions(com.yahoo.container.jdisc.state.MetricDimensions) CountMetric(com.yahoo.container.jdisc.state.CountMetric) GaugeMetric(com.yahoo.container.jdisc.state.GaugeMetric) Point(com.yahoo.metrics.simple.Point) Point(com.yahoo.metrics.simple.Point) MetricSet(com.yahoo.container.jdisc.state.MetricSet) MetricValue(com.yahoo.container.jdisc.state.MetricValue) MetricSnapshot(com.yahoo.container.jdisc.state.MetricSnapshot) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

CountMetric (com.yahoo.container.jdisc.state.CountMetric)1 GaugeMetric (com.yahoo.container.jdisc.state.GaugeMetric)1 MetricDimensions (com.yahoo.container.jdisc.state.MetricDimensions)1 MetricSet (com.yahoo.container.jdisc.state.MetricSet)1 MetricSnapshot (com.yahoo.container.jdisc.state.MetricSnapshot)1 MetricValue (com.yahoo.container.jdisc.state.MetricValue)1 MetricReceiver (com.yahoo.metrics.simple.MetricReceiver)1 Point (com.yahoo.metrics.simple.Point)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1