Program: 4604
Project: 4604
Buggy source:
@Test public void testHistoryDeletion() throws Exception {
  ApplicationSpecification spec=Specifications.from(new AllProgramsApp());
  NamespaceId namespaceId=new NamespaceId("String_Node_Str");
  ApplicationId appId1=namespaceId.app(spec.getName());
  store.addApplication(appId1,spec);
  spec=Specifications.from(new WordCountApp());
  ApplicationId appId2=namespaceId.app(spec.getName());
  store.addApplication(appId2,spec);
  ProgramId flowProgramId1=appId1.flow("String_Node_Str");
  ProgramId mapreduceProgramId1=appId1.mr("String_Node_Str");
  ProgramId workflowProgramId1=appId1.workflow("String_Node_Str");
  ProgramId flowProgramId2=appId2.flow("String_Node_Str");
  Assert.assertNotNull(store.getApplication(appId1));
  Assert.assertNotNull(store.getApplication(appId2));
  long now=System.currentTimeMillis();
  setStartAndRunning(flowProgramId1,"String_Node_Str",now - 1000);
  store.setStop(flowProgramId1,"String_Node_Str",now,ProgramController.State.COMPLETED.getRunStatus(),AppFabricTestHelper.createSourceId(++sourceId));
  setStartAndRunning(mapreduceProgramId1,"String_Node_Str",now - 1000);
  store.setStop(mapreduceProgramId1,"String_Node_Str",now,ProgramController.State.COMPLETED.getRunStatus(),AppFabricTestHelper.createSourceId(++sourceId));
  RunId runId=RunIds.generate(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(1000));
  setStartAndRunning(workflowProgramId1,runId.getId(),now - 1000);
  store.setStop(workflowProgramId1,runId.getId(),now,ProgramController.State.COMPLETED.getRunStatus(),AppFabricTestHelper.createSourceId(++sourceId));
  setStartAndRunning(flowProgramId2,"String_Node_Str",now - 1000);
  store.setStop(flowProgramId2,"String_Node_Str",now,ProgramController.State.COMPLETED.getRunStatus(),AppFabricTestHelper.createSourceId(++sourceId));
  verifyRunHistory(flowProgramId1,1);
  verifyRunHistory(mapreduceProgramId1,1);
  verifyRunHistory(workflowProgramId1,1);
  verifyRunHistory(flowProgramId2,1);
  store.removeApplication(appId1);
  Assert.assertNull(store.getApplication(appId1));
  Assert.assertNotNull(store.getApplication(appId2));
  verifyRunHistory(flowProgramId1,0);
  verifyRunHistory(mapreduceProgramId1,0);
  verifyRunHistory(workflowProgramId1,0);
  verifyRunHistory(flowProgramId2,1);
  store.removeAll(namespaceId);
  verifyRunHistory(flowProgramId2,0);
}

Fixed version (ground truth):
@Test public void testHistoryDeletion() throws Exception {
  ApplicationSpecification spec=Specifications.from(new AllProgramsApp());
  NamespaceId namespaceId=new NamespaceId("String_Node_Str");
  ApplicationId appId1=namespaceId.app(spec.getName());
  store.addApplication(appId1,spec);
  spec=Specifications.from(new WordCountApp());
  ApplicationId appId2=namespaceId.app(spec.getName());
  store.addApplication(appId2,spec);
  ProgramId flowProgramId1=appId1.flow("String_Node_Str");
  ProgramId mapreduceProgramId1=appId1.mr("String_Node_Str");
  ProgramId workflowProgramId1=appId1.workflow("String_Node_Str");
  ProgramId flowProgramId2=appId2.flow("String_Node_Str");
  Assert.assertNotNull(store.getApplication(appId1));
  Assert.assertNotNull(store.getApplication(appId2));
  long now=System.currentTimeMillis();
  String runId=RunIds.generate().getId();
  setStartAndRunning(flowProgramId1,runId,now - 1000);
  store.setStop(flowProgramId1,runId,now,ProgramController.State.COMPLETED.getRunStatus(),AppFabricTestHelper.createSourceId(++sourceId));
  runId=RunIds.generate().getId();
  setStartAndRunning(mapreduceProgramId1,runId,now - 1000);
  store.setStop(mapreduceProgramId1,runId,now,ProgramController.State.COMPLETED.getRunStatus(),AppFabricTestHelper.createSourceId(++sourceId));
  runId=RunIds.generate(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(1000)).getId();
  setStartAndRunning(workflowProgramId1,runId,now - 1000);
  store.setStop(workflowProgramId1,runId,now,ProgramController.State.COMPLETED.getRunStatus(),AppFabricTestHelper.createSourceId(++sourceId));
  runId=RunIds.generate().getId();
  setStartAndRunning(flowProgramId2,runId,now - 1000);
  store.setStop(flowProgramId2,runId,now,ProgramController.State.COMPLETED.getRunStatus(),AppFabricTestHelper.createSourceId(++sourceId));
  verifyRunHistory(flowProgramId1,1);
  verifyRunHistory(mapreduceProgramId1,1);
  verifyRunHistory(workflowProgramId1,1);
  verifyRunHistory(flowProgramId2,1);
  store.removeApplication(appId1);
  Assert.assertNull(store.getApplication(appId1));
  Assert.assertNotNull(store.getApplication(appId2));
  verifyRunHistory(flowProgramId1,0);
  verifyRunHistory(mapreduceProgramId1,0);
  verifyRunHistory(workflowProgramId1,0);
  verifyRunHistory(flowProgramId2,1);
  store.removeAll(namespaceId);
  verifyRunHistory(flowProgramId2,0);
}