public static BundleCounter bundleProcessingThreadCounter(String shortId, MetricName name) {
    return new BundleProcessingThreadCounter(shortId, name);
  }
@Test
  public void testAccurateBundleCounterWithMutations() throws Exception {
    Map<String, ByteString> report = new HashMap<>();
    BundleCounter bundleCounter = Metrics.bundleProcessingThreadCounter(TEST_ID, TEST_NAME);

    bundleCounter.inc(7);
    bundleCounter.updateIntermediateMonitoringData(report);
    assertEquals(
        report, Collections.singletonMap(TEST_ID, MonitoringInfoEncodings.encodeInt64Counter(7)));
    report.clear();

    bundleCounter.updateIntermediateMonitoringData(report);
    assertEquals(report, Collections.emptyMap());

    bundleCounter.inc();
    bundleCounter.updateIntermediateMonitoringData(report);
    assertEquals(
        report, Collections.singletonMap(TEST_ID, MonitoringInfoEncodings.encodeInt64Counter(8)));
    report.clear();

    bundleCounter.dec(4);
    bundleCounter.updateIntermediateMonitoringData(report);
    assertEquals(
        report, Collections.singletonMap(TEST_ID, MonitoringInfoEncodings.encodeInt64Counter(4)));

    bundleCounter.dec();
    bundleCounter.updateFinalMonitoringData(report);
    assertEquals(
        report, Collections.singletonMap(TEST_ID, MonitoringInfoEncodings.encodeInt64Counter(3)));

    // Test re-use of the metrics after reset
    bundleCounter.reset();
    bundleCounter.inc(7);
    bundleCounter.updateIntermediateMonitoringData(report);
    assertEquals(
        report, Collections.singletonMap(TEST_ID, MonitoringInfoEncodings.encodeInt64Counter(7)));
    report.clear();

    bundleCounter.updateIntermediateMonitoringData(report);
    assertEquals(report, Collections.emptyMap());

    bundleCounter.inc();
    bundleCounter.updateIntermediateMonitoringData(report);
    assertEquals(
        report, Collections.singletonMap(TEST_ID, MonitoringInfoEncodings.encodeInt64Counter(8)));
    report.clear();

    bundleCounter.dec(4);
    bundleCounter.updateIntermediateMonitoringData(report);
    assertEquals(
        report, Collections.singletonMap(TEST_ID, MonitoringInfoEncodings.encodeInt64Counter(4)));

    bundleCounter.dec();
    bundleCounter.updateFinalMonitoringData(report);
    assertEquals(
        report, Collections.singletonMap(TEST_ID, MonitoringInfoEncodings.encodeInt64Counter(3)));
  }