Program: 13815
Project: 13815
Buggy source:
@Test public void testReporter() throws InterruptedException {
  StoredDataPointReceiver dbank=new StoredDataPointReceiver();
  assertEquals(0,dbank.addDataPoints.size());
  MetricRegistry metricRegistery=new MetricRegistry();
  SignalFuseReporter reporter=new SignalFuseReporter.Builder(metricRegistery,new StaticAuthToken("String_Node_Str"),"String_Node_Str").setDataPointReceiverFactory(new StaticDataPointReceiverFactory(dbank)).setDetailsToAdd(ImmutableSet.of(SignalFuseReporter.MetricDetails.COUNT,SignalFuseReporter.MetricDetails.MIN,SignalFuseReporter.MetricDetails.MAX)).build();
  Metric gauge=metricRegistery.register("String_Node_Str",new Gauge<Integer>(){
    public Integer getValue(){
      return 1;
    }
  }
);
  final MetricMetadata metricMetadata=reporter.getMetricMetadata();
  metricMetadata.forMetric(metricRegistery.counter("String_Node_Str")).withMetricName("String_Node_Str").withSourceName("String_Node_Str").withMetricType(SignalFuseProtocolBuffers.MetricType.GAUGE);
  metricMetadata.forMetric(metricRegistery.counter("String_Node_Str")).withMetricName("String_Node_Str");
  metricRegistery.counter("String_Node_Str").inc();
  metricRegistery.counter("String_Node_Str").inc();
  metricRegistery.timer("String_Node_Str").time().close();
  reporter.report();
  assertEquals(6,dbank.addDataPoints.size());
  assertEquals("String_Node_Str",dbank.addDataPoints.get(1).getMetric());
  assertEquals("String_Node_Str",dbank.addDataPoints.get(1).getSource());
  assertEquals(SignalFuseProtocolBuffers.MetricType.GAUGE,dbank.registeredMetrics.get("String_Node_Str"));
  assertEquals(SignalFuseProtocolBuffers.MetricType.CUMULATIVE_COUNTER,dbank.registeredMetrics.get("String_Node_Str"));
  assertEquals(SignalFuseProtocolBuffers.MetricType.GAUGE,dbank.registeredMetrics.get("String_Node_Str"));
  assertEquals(2,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertNotNull(dbank.lastValueFor("String_Node_Str","String_Node_Str"));
  dbank.addDataPoints.clear();
  metricMetadata.forMetric(metricRegistery.counter("String_Node_Str")).withMetricType(SignalFuseProtocolBuffers.MetricType.COUNTER);
  SfUtil.cumulativeCounter(metricRegistery,"String_Node_Str",metricMetadata,new Gauge<Long>(){
    private long i=0;
    @Override public Long getValue(){
      return i++;
    }
  }
);
  final Queue customerQueue=new ArrayBlockingQueue();
  metricMetadata.forMetric(new Gauge<Long>(){
    @Override public Long getValue(){
      return customerQueue.size();
    }
  }
).withDimension("String_Node_Str","String_Node_Str").register(metricRegistery);
  Counter distributedCounter=metricMetadata.forMetric(new IncrementalCounter()).withDimension("String_Node_Str","String_Node_Str").withMetricName("String_Node_Str").withSourceName("String_Node_Str").register(metricRegistery);
  assertNotNull(metricRegistery.getCounters().get("String_Node_Str"));
  distributedCounter.inc(123);
  metricRegistery.counter("String_Node_Str").inc(10);
  metricMetadata.forBuilder(IncrementalCounter.Builder.INSTANCE).withSourceName("String_Node_Str").withMetricName("String_Node_Str").createOrGet(metricRegistery).inc(1);
  try {
    metricMetadata.forBuilder(SettableLongGauge.Builder.INSTANCE).withSourceName("String_Node_Str").withMetricName("String_Node_Str").createOrGet(metricRegistery);
    throw new RuntimeException("String_Node_Str");
  }
 catch (  IllegalArgumentException e) {
  }
  reporter.report();
  assertEquals(10,dbank.addDataPoints.size());
  assertEquals(10,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertEquals(0,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertEquals(123,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertEquals(1,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertEquals(2,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  distributedCounter.inc(1);
  distributedCounter.inc(3);
  assertEquals(SignalFuseProtocolBuffers.MetricType.COUNTER,dbank.registeredMetrics.get("String_Node_Str"));
  assertEquals(SignalFuseProtocolBuffers.MetricType.COUNTER,dbank.registeredMetrics.get("String_Node_Str"));
  assertEquals(SignalFuseProtocolBuffers.MetricType.CUMULATIVE_COUNTER,dbank.registeredMetrics.get("String_Node_Str"));
  metricRegistery.counter("String_Node_Str").inc(14);
  dbank.addDataPoints.clear();
  metricMetadata.forBuilder(IncrementalCounter.Builder.INSTANCE).withSourceName("String_Node_Str").withMetricName("String_Node_Str").createOrGet(metricRegistery).inc(3);
  assertEquals(0,SfUtil.removeMetrics(metricRegistery,new Counter()));
  assertEquals(2,SfUtil.removeMetrics(metricRegistery,gauge,metricRegistery.counter("String_Node_Str")));
  assertEquals(true,dbank.clearValues("String_Node_Str","String_Node_Str"));
  assertEquals(false,dbank.clearValues("String_Node_Str","String_Node_Str"));
  reporter.report();
  assertEquals(8,dbank.addDataPoints.size());
  assertEquals(0,dbank.valuesFor("String_Node_Str","String_Node_Str").size());
  assertEquals(24,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertEquals(1,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertEquals(4,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertEquals(3,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  try {
    metricMetadata.forBuilder(IncrementalCounter.Builder.INSTANCE).withSourceName("String_Node_Str").withMetricName("String_Node_Str").withMetricType(SignalFuseProtocolBuffers.MetricType.GAUGE).createOrGet(metricRegistery);
    throw new RuntimeException("String_Node_Str");
  }
 catch (  IllegalArgumentException e) {
  }
  metricMetadata.forMetric(new Counter()).withSourceName("String_Node_Str").withMetricName("String_Node_Str").register(metricRegistery);
  try {
    metricMetadata.forBuilder(IncrementalCounter.Builder.INSTANCE).withSourceName("String_Node_Str").withMetricName("String_Node_Str").createOrGet(metricRegistery);
    throw new RuntimeException("String_Node_Str");
  }
 catch (  IllegalArgumentException e) {
  }
}

Fixed version (ground truth):
@Test public void testReporter() throws InterruptedException {
  StoredDataPointReceiver dbank=new StoredDataPointReceiver();
  assertEquals(0,dbank.addDataPoints.size());
  MetricRegistry metricRegistery=new MetricRegistry();
  SignalFuseReporter reporter=new SignalFuseReporter.Builder(metricRegistery,new StaticAuthToken("String_Node_Str"),"String_Node_Str").setDataPointReceiverFactory(new StaticDataPointReceiverFactory(dbank)).setDetailsToAdd(ImmutableSet.of(SignalFuseReporter.MetricDetails.COUNT,SignalFuseReporter.MetricDetails.MIN,SignalFuseReporter.MetricDetails.MAX)).build();
  Metric gauge=metricRegistery.register("String_Node_Str",new Gauge<Integer>(){
    public Integer getValue(){
      return 1;
    }
  }
);
  final MetricMetadata metricMetadata=reporter.getMetricMetadata();
  metricMetadata.forMetric(metricRegistery.counter("String_Node_Str")).withMetricName("String_Node_Str").withSourceName("String_Node_Str").withMetricType(SignalFuseProtocolBuffers.MetricType.GAUGE);
  metricMetadata.forMetric(metricRegistery.counter("String_Node_Str")).withMetricName("String_Node_Str");
  metricRegistery.counter("String_Node_Str").inc();
  metricRegistery.counter("String_Node_Str").inc();
  metricRegistery.timer("String_Node_Str").time().close();
  reporter.report();
  assertEquals(6,dbank.addDataPoints.size());
  assertEquals("String_Node_Str",dbank.addDataPoints.get(1).getMetric());
  assertEquals("String_Node_Str",dbank.addDataPoints.get(1).getSource());
  assertEquals(SignalFuseProtocolBuffers.MetricType.GAUGE,dbank.registeredMetrics.get("String_Node_Str"));
  assertEquals(SignalFuseProtocolBuffers.MetricType.CUMULATIVE_COUNTER,dbank.registeredMetrics.get("String_Node_Str"));
  assertEquals(SignalFuseProtocolBuffers.MetricType.GAUGE,dbank.registeredMetrics.get("String_Node_Str"));
  assertEquals(2,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertNotNull(dbank.lastValueFor("String_Node_Str","String_Node_Str"));
  dbank.addDataPoints.clear();
  metricMetadata.forMetric(metricRegistery.counter("String_Node_Str")).withMetricType(SignalFuseProtocolBuffers.MetricType.COUNTER);
  SfUtil.cumulativeCounter(metricRegistery,"String_Node_Str",metricMetadata,new Gauge<Long>(){
    private long i=0;
    @Override public Long getValue(){
      return i++;
    }
  }
);
  Counter distributedCounter=metricMetadata.forMetric(new IncrementalCounter()).withMetricName("String_Node_Str").withSourceName("String_Node_Str").register(metricRegistery);
  assertNotNull(metricRegistery.getCounters().get("String_Node_Str"));
  distributedCounter.inc(123);
  metricRegistery.counter("String_Node_Str").inc(10);
  metricMetadata.forBuilder(IncrementalCounter.Builder.INSTANCE).withSourceName("String_Node_Str").withMetricName("String_Node_Str").createOrGet(metricRegistery).inc(1);
  try {
    metricMetadata.forBuilder(SettableLongGauge.Builder.INSTANCE).withSourceName("String_Node_Str").withMetricName("String_Node_Str").createOrGet(metricRegistery);
    throw new RuntimeException("String_Node_Str");
  }
 catch (  IllegalArgumentException e) {
  }
  reporter.report();
  assertEquals(10,dbank.addDataPoints.size());
  assertEquals(10,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertEquals(0,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertEquals(123,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertEquals(1,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertEquals(2,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  distributedCounter.inc(1);
  distributedCounter.inc(3);
  assertEquals(SignalFuseProtocolBuffers.MetricType.COUNTER,dbank.registeredMetrics.get("String_Node_Str"));
  assertEquals(SignalFuseProtocolBuffers.MetricType.COUNTER,dbank.registeredMetrics.get("String_Node_Str"));
  assertEquals(SignalFuseProtocolBuffers.MetricType.CUMULATIVE_COUNTER,dbank.registeredMetrics.get("String_Node_Str"));
  metricRegistery.counter("String_Node_Str").inc(14);
  dbank.addDataPoints.clear();
  metricMetadata.forBuilder(IncrementalCounter.Builder.INSTANCE).withSourceName("String_Node_Str").withMetricName("String_Node_Str").createOrGet(metricRegistery).inc(3);
  assertEquals(0,SfUtil.removeMetrics(metricRegistery,new Counter()));
  assertEquals(2,SfUtil.removeMetrics(metricRegistery,gauge,metricRegistery.counter("String_Node_Str")));
  assertEquals(true,dbank.clearValues("String_Node_Str","String_Node_Str"));
  assertEquals(false,dbank.clearValues("String_Node_Str","String_Node_Str"));
  reporter.report();
  assertEquals(8,dbank.addDataPoints.size());
  assertEquals(0,dbank.valuesFor("String_Node_Str","String_Node_Str").size());
  assertEquals(24,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertEquals(1,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertEquals(4,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  assertEquals(3,dbank.lastValueFor("String_Node_Str","String_Node_Str").getIntValue());
  try {
    metricMetadata.forBuilder(IncrementalCounter.Builder.INSTANCE).withSourceName("String_Node_Str").withMetricName("String_Node_Str").withMetricType(SignalFuseProtocolBuffers.MetricType.GAUGE).createOrGet(metricRegistery);
    throw new RuntimeException("String_Node_Str");
  }
 catch (  IllegalArgumentException e) {
  }
  metricMetadata.forMetric(new Counter()).withSourceName("String_Node_Str").withMetricName("String_Node_Str").register(metricRegistery);
  try {
    metricMetadata.forBuilder(IncrementalCounter.Builder.INSTANCE).withSourceName("String_Node_Str").withMetricName("String_Node_Str").createOrGet(metricRegistery);
    throw new RuntimeException("String_Node_Str");
  }
 catch (  IllegalArgumentException e) {
  }
}