Search in sources :

Example 16 with Counter

use of org.opendaylight.infrautils.metrics.Counter 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);
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter) Labeled(org.opendaylight.infrautils.metrics.Labeled) Test(org.junit.Test)

Example 17 with Counter

use of org.opendaylight.infrautils.metrics.Counter 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();
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter) Labeled(org.opendaylight.infrautils.metrics.Labeled) Test(org.junit.Test)

Example 18 with Counter

use of org.opendaylight.infrautils.metrics.Counter 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();
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter) Labeled(org.opendaylight.infrautils.metrics.Labeled) Test(org.junit.Test)

Example 19 with Counter

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

the class MetricsIntegrationTest method testMetrics.

@Test
public void testMetrics() {
    // The main point here is just to make sure that Dropwizard Codahale Metrics really works at runtime under OSGi
    Counter counter1 = metricProvider.newCounter(this, "odl.infrautils.metrics.IntegrationTest.counter1");
    counter1.increment();
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter) AbstractIntegrationTest(org.opendaylight.infrautils.itestutils.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

Counter (org.opendaylight.infrautils.metrics.Counter)19 Labeled (org.opendaylight.infrautils.metrics.Labeled)7 Test (org.junit.Test)5 BigInteger (java.math.BigInteger)3 List (java.util.List)3 UncheckedCloseable (org.opendaylight.infrautils.utils.UncheckedCloseable)3 FlowAndStatisticsMapList (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList)3 NodeConnectorId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)3 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)3 NodeConnectorStatisticsAndPortNumberMap (org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap)3 Optional (com.google.common.base.Optional)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 Futures (com.google.common.util.concurrent.Futures)2 JdkFutureAdapters (com.google.common.util.concurrent.JdkFutureAdapters)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2