Program: 6405
Project: 6405
Buggy source:
@Test public void testWorkerDatasetWithMetrics() throws Throwable {
  final ApplicationWithPrograms app=AppFabricTestHelper.deployApplicationWithManager(AppWithWorker.class,TEMP_FOLDER_SUPPLIER);
  ProgramController controller=startProgram(app,AppWithWorker.TableWriter.class);
  final TransactionExecutor executor=txExecutorFactory.createExecutor(datasetCache);
  Tasks.waitFor(AppWithWorker.RUN,new Callable<String>(){
    @Override public String call() throws Exception {
      return executor.execute(new Callable<String>(){
        @Override public String call() throws Exception {
          KeyValueTable kvTable=datasetCache.getDataset(AppWithWorker.DATASET);
          return Bytes.toString(kvTable.read(AppWithWorker.RUN));
        }
      }
);
    }
  }
,5,TimeUnit.SECONDS,50,TimeUnit.MILLISECONDS);
  stopProgram(controller);
  txExecutorFactory.createExecutor(datasetCache.getTransactionAwares()).execute(new TransactionExecutor.Subroutine(){
    @Override public void apply() throws Exception {
      KeyValueTable kvTable=datasetCache.getDataset(AppWithWorker.DATASET);
      Assert.assertEquals(AppWithWorker.RUN,Bytes.toString(kvTable.read(AppWithWorker.RUN)));
      Assert.assertEquals(AppWithWorker.INITIALIZE,Bytes.toString(kvTable.read(AppWithWorker.INITIALIZE)));
      Assert.assertEquals(AppWithWorker.STOP,Bytes.toString(kvTable.read(AppWithWorker.STOP)));
    }
  }
);
  Tasks.waitFor(3L,new Callable<Long>(){
    @Override public Long call() throws Exception {
      Collection<MetricTimeSeries> metrics=metricStore.query(new MetricDataQuery(0,System.currentTimeMillis() / 1000L,60,"String_Node_Str" + Constants.Metrics.Name.Dataset.OP_COUNT,AggregationFunction.SUM,ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE,DefaultId.NAMESPACE.getId(),Constants.Metrics.Tag.APP,AppWithWorker.NAME,Constants.Metrics.Tag.WORKER,AppWithWorker.WORKER,Constants.Metrics.Tag.DATASET,AppWithWorker.DATASET),Collections.<String>emptyList()));
      if (metrics.isEmpty()) {
        return 0L;
      }
      Assert.assertEquals(1,metrics.size());
      MetricTimeSeries ts=metrics.iterator().next();
      Assert.assertEquals(1,ts.getTimeValues().size());
      return ts.getTimeValues().get(0).getValue();
    }
  }
,5L,TimeUnit.SECONDS,50L,TimeUnit.MILLISECONDS);
}

Fixed version (ground truth):
@Test public void testWorkerDatasetWithMetrics() throws Throwable {
  final ApplicationWithPrograms app=AppFabricTestHelper.deployApplicationWithManager(AppWithWorker.class,TEMP_FOLDER_SUPPLIER);
  ProgramController controller=startProgram(app,AppWithWorker.TableWriter.class);
  final TransactionExecutor executor=txExecutorFactory.createExecutor(datasetCache);
  Tasks.waitFor(AppWithWorker.RUN,new Callable<String>(){
    @Override public String call() throws Exception {
      return executor.execute(new Callable<String>(){
        @Override public String call() throws Exception {
          KeyValueTable kvTable=datasetCache.getDataset(AppWithWorker.DATASET);
          return Bytes.toString(kvTable.read(AppWithWorker.RUN));
        }
      }
);
    }
  }
,5,TimeUnit.SECONDS);
  stopProgram(controller);
  txExecutorFactory.createExecutor(datasetCache.getTransactionAwares()).execute(new TransactionExecutor.Subroutine(){
    @Override public void apply() throws Exception {
      KeyValueTable kvTable=datasetCache.getDataset(AppWithWorker.DATASET);
      Assert.assertEquals(AppWithWorker.RUN,Bytes.toString(kvTable.read(AppWithWorker.RUN)));
      Assert.assertEquals(AppWithWorker.INITIALIZE,Bytes.toString(kvTable.read(AppWithWorker.INITIALIZE)));
      Assert.assertEquals(AppWithWorker.STOP,Bytes.toString(kvTable.read(AppWithWorker.STOP)));
    }
  }
);
  Tasks.waitFor(3L,new Callable<Long>(){
    @Override public Long call() throws Exception {
      Collection<MetricTimeSeries> metrics=metricStore.query(new MetricDataQuery(0,System.currentTimeMillis() / 1000L,60,"String_Node_Str" + Constants.Metrics.Name.Dataset.OP_COUNT,AggregationFunction.SUM,ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE,DefaultId.NAMESPACE.getId(),Constants.Metrics.Tag.APP,AppWithWorker.NAME,Constants.Metrics.Tag.WORKER,AppWithWorker.WORKER,Constants.Metrics.Tag.DATASET,AppWithWorker.DATASET),Collections.<String>emptyList()));
      if (metrics.isEmpty()) {
        return 0L;
      }
      Assert.assertEquals(1,metrics.size());
      MetricTimeSeries ts=metrics.iterator().next();
      Assert.assertEquals(1,ts.getTimeValues().size());
      return ts.getTimeValues().get(0).getValue();
    }
  }
,5L,TimeUnit.SECONDS,50L,TimeUnit.MILLISECONDS);
}