@Test
    public void shouldReturnPresenceOfMetrics() {
        final Metrics metrics = new Metrics();
        final Sensor sensor = metrics.sensor("sensor");

        assertFalse(sensor.hasMetrics());

        sensor.add(
            new MetricName("name1", "group1", "description1", Collections.emptyMap()),
            new WindowedSum()
        );

        assertTrue(sensor.hasMetrics());

        sensor.add(
            new MetricName("name2", "group2", "description2", Collections.emptyMap()),
            new CumulativeCount()
        );

        assertTrue(sensor.hasMetrics());
    }
The Sensor#checkQuotas should be thread-safe since the method may be used by many ReplicaFetcherThreads.
clients/src/test/java/org/apache/kafka/common/metrics/SensorTest.java