Search in sources :

Example 1 with Timer

use of org.opendaylight.infrautils.metrics.Timer in project infrautils by opendaylight.

the class MetricProviderTest method testTimeCallableWithLabels.

@Test
public void testTimeCallableWithLabels() {
    Labeled<Labeled<Timer>> timerWithTwoLabels = metrics.newTimer(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_timer_with_labels").build(), "l1", "l2");
    Timer timerA = timerWithTwoLabels.label("l1value").label("l2value");
    assertThat(timerA.time(() -> {
        @Var int sum = 0;
        for (int i = 1; i < 101; i++) {
            sum += i;
        }
        return sum;
    })).isEqualTo(5050);
}
Also used : Timer(org.opendaylight.infrautils.metrics.Timer) Var(com.google.errorprone.annotations.Var) Labeled(org.opendaylight.infrautils.metrics.Labeled) Test(org.junit.Test)

Example 2 with Timer

use of org.opendaylight.infrautils.metrics.Timer in project infrautils by opendaylight.

the class MetricProviderTest method testTimeRunnableOKWithLabels.

@Test
public void testTimeRunnableOKWithLabels() {
    Labeled<Labeled<Timer>> timerWithTwoLabels = metrics.newTimer(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_timer_with_labels").build(), "l1", "l2");
    Timer timerA = timerWithTwoLabels.label("l1value").label("l2value");
    timerA.time(() -> {
        for (@SuppressWarnings("unused") int sum = 0, i = 1; i < 101; i++) {
            sum += i;
        }
    });
}
Also used : Timer(org.opendaylight.infrautils.metrics.Timer) Labeled(org.opendaylight.infrautils.metrics.Labeled) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 Labeled (org.opendaylight.infrautils.metrics.Labeled)2 Timer (org.opendaylight.infrautils.metrics.Timer)2 Var (com.google.errorprone.annotations.Var)1