Search in sources :

Example 11 with WindowedCount

use of org.apache.kafka.common.metrics.stats.WindowedCount in project kafka by apache.

the class MetricsTest method testRemoveSensor.

@Test
public void testRemoveSensor() {
    int size = metrics.metrics().size();
    Sensor parent1 = metrics.sensor("test.parent1");
    parent1.add(metrics.metricName("test.parent1.count", "grp1"), new WindowedCount());
    Sensor parent2 = metrics.sensor("test.parent2");
    parent2.add(metrics.metricName("test.parent2.count", "grp1"), new WindowedCount());
    Sensor child1 = metrics.sensor("test.child1", parent1, parent2);
    child1.add(metrics.metricName("test.child1.count", "grp1"), new WindowedCount());
    Sensor child2 = metrics.sensor("test.child2", parent2);
    child2.add(metrics.metricName("test.child2.count", "grp1"), new WindowedCount());
    Sensor grandChild1 = metrics.sensor("test.gchild2", child2);
    grandChild1.add(metrics.metricName("test.gchild2.count", "grp1"), new WindowedCount());
    Sensor sensor = metrics.getSensor("test.parent1");
    assertNotNull(sensor);
    metrics.removeSensor("test.parent1");
    assertNull(metrics.getSensor("test.parent1"));
    assertNull(metrics.metrics().get(metrics.metricName("test.parent1.count", "grp1")));
    assertNull(metrics.getSensor("test.child1"));
    assertNull(metrics.childrenSensors().get(sensor));
    assertNull(metrics.metrics().get(metrics.metricName("test.child1.count", "grp1")));
    sensor = metrics.getSensor("test.gchild2");
    assertNotNull(sensor);
    metrics.removeSensor("test.gchild2");
    assertNull(metrics.getSensor("test.gchild2"));
    assertNull(metrics.childrenSensors().get(sensor));
    assertNull(metrics.metrics().get(metrics.metricName("test.gchild2.count", "grp1")));
    sensor = metrics.getSensor("test.child2");
    assertNotNull(sensor);
    metrics.removeSensor("test.child2");
    assertNull(metrics.getSensor("test.child2"));
    assertNull(metrics.childrenSensors().get(sensor));
    assertNull(metrics.metrics().get(metrics.metricName("test.child2.count", "grp1")));
    sensor = metrics.getSensor("test.parent2");
    assertNotNull(sensor);
    metrics.removeSensor("test.parent2");
    assertNull(metrics.getSensor("test.parent2"));
    assertNull(metrics.childrenSensors().get(sensor));
    assertNull(metrics.metrics().get(metrics.metricName("test.parent2.count", "grp1")));
    assertEquals(size, metrics.metrics().size());
}
Also used : WindowedCount(org.apache.kafka.common.metrics.stats.WindowedCount) Test(org.junit.jupiter.api.Test)

Aggregations

WindowedCount (org.apache.kafka.common.metrics.stats.WindowedCount)11 Test (org.junit.jupiter.api.Test)8 Avg (org.apache.kafka.common.metrics.stats.Avg)2 Max (org.apache.kafka.common.metrics.stats.Max)2 Meter (org.apache.kafka.common.metrics.stats.Meter)2 Percentile (org.apache.kafka.common.metrics.stats.Percentile)2 Percentiles (org.apache.kafka.common.metrics.stats.Percentiles)2 WindowedSum (org.apache.kafka.common.metrics.stats.WindowedSum)2 MetricName (org.apache.kafka.common.MetricName)1 Metrics (org.apache.kafka.common.metrics.Metrics)1 Sensor (org.apache.kafka.common.metrics.Sensor)1 CumulativeSum (org.apache.kafka.common.metrics.stats.CumulativeSum)1 Min (org.apache.kafka.common.metrics.stats.Min)1 Rate (org.apache.kafka.common.metrics.stats.Rate)1 SimpleRate (org.apache.kafka.common.metrics.stats.SimpleRate)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1