use of org.opendaylight.infrautils.metrics.Labeled 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;
}
});
}
use of org.opendaylight.infrautils.metrics.Labeled in project infrautils by opendaylight.
the class MetricProviderTest method testCounterWith2Labels.
@Test
public void testCounterWith2Labels() {
Labeled<Labeled<Counter>> counterWithTwoLabels = metrics.newCounter(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_counter1").build(), "port", "mac");
Counter counterA = counterWithTwoLabels.label(/* port */
"456").label(/* MAC */
"1A:0B:F2:25:1C:68");
counterA.increment(3);
assertThat(counterA.get()).isEqualTo(3);
Counter counterB = counterWithTwoLabels.label(/* port */
"789").label(/* MAC */
"1A:0B:F2:25:1C:68");
counterB.increment(1);
assertThat(counterB.get()).isEqualTo(1);
assertThat(counterA.get()).isEqualTo(3);
Counter againCounterA = counterWithTwoLabels.label(/* port */
"456").label(/* MAC */
"1A:0B:F2:25:1C:68");
assertThat(againCounterA.get()).isEqualTo(3);
}
use of org.opendaylight.infrautils.metrics.Labeled in project infrautils by opendaylight.
the class MetricProviderTest method testSameCounterUpdateOperationsWithLabels.
@Test
public void testSameCounterUpdateOperationsWithLabels() {
Labeled<Labeled<Counter>> counterWithTwoLabels = metrics.newCounter(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_counter_upd_opers").build(), "l1", "l2");
Counter counterA = counterWithTwoLabels.label("l1value").label("l2value");
counterA.increment(51);
assertThat(counterA.get()).isEqualTo(51);
counterA.decrement();
assertThat(counterA.get()).isEqualTo(50);
Labeled<Labeled<Counter>> sameCounterWithTwoLabels = metrics.newCounter(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_counter_upd_opers").build(), "l1", "l2");
Counter sameCounterA = sameCounterWithTwoLabels.label("l1value").label("l2value");
assertThat(sameCounterA).isEqualTo(counterA);
assertThat(sameCounterA.get()).isEqualTo(50);
sameCounterA.increment(5);
assertThat(sameCounterA.get()).isEqualTo(55);
sameCounterA.decrement(10);
assertThat(sameCounterA.get()).isEqualTo(45);
sameCounterA.close();
}
use of org.opendaylight.infrautils.metrics.Labeled in project infrautils by opendaylight.
the class MetricProviderTest method testCounterOperationsWithLabels.
@Test
public void testCounterOperationsWithLabels() {
Labeled<Labeled<Counter>> counterWithTwoLabels = metrics.newCounter(MetricDescriptor.builder().anchor(this).project("infrautils").module("metrics").id("test_counter_opers").build(), "l1", "l2");
Counter counterA = counterWithTwoLabels.label("l1value").label("l2value");
counterA.increment();
counterA.increment();
assertThat(counterA.get()).isEqualTo(2);
counterA.decrement();
assertThat(counterA.get()).isEqualTo(1);
counterA.increment(5);
assertThat(counterA.get()).isEqualTo(6);
counterA.decrement(2);
assertThat(counterA.get()).isEqualTo(4);
counterA.close();
}
Aggregations