@Test
    public void metrics_for_different_consumers_are_cached_separately() {
        updateSnapshot(defaultMetricsConsumerId, TTL);
        List<MetricsPacket> defaultMetrics = nodeMetricsClient.getMetrics(defaultMetricsConsumerId);
        assertEquals(1, nodeMetricsClient.snapshotsRetrieved());
        assertEquals(4, defaultMetrics.size());

        updateSnapshot(toConsumerId(CUSTOM_CONSUMER), TTL);
        List<MetricsPacket> customMetrics = nodeMetricsClient.getMetrics(toConsumerId(CUSTOM_CONSUMER));
        assertEquals(2, nodeMetricsClient.snapshotsRetrieved());
        assertEquals(4, customMetrics.size());

        MetricsPacket replacedCpuMetric = customMetrics.get(0);
        assertTrue(replacedCpuMetric.metrics().containsKey(toMetricId(REPLACED_CPU_METRIC)));
    }
Two optimizations worth noting:
<p>
1. Using a ClassRule for the wire mocking means it is reused between test methods.
2. Configuring stubs on the rule is faster than using the static WireMock.stubFor method.

@author gjoranv
metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/NodeMetricsClientTest.java