Program: 7114
Project: 7114
Buggy source:
@Test public void testLogProgramRunHistory() throws Exception {
  Id.Program programId=Id.Program.from("String_Node_Str","String_Node_Str",ProgramType.FLOW,"String_Node_Str");
  long now=System.currentTimeMillis();
  long nowSecs=TimeUnit.MILLISECONDS.toSeconds(now);
  RunId run1=RunIds.generate(now - 20000);
  store.setStart(programId,run1.getId(),runIdToSecs(run1));
  store.setStop(programId,run1.getId(),nowSecs - 10,ProgramController.State.ERROR.getRunStatus());
  RunId run2=RunIds.generate(now - 10000);
  store.setStart(programId,run2.getId(),runIdToSecs(run2));
  store.setStop(programId,run2.getId(),nowSecs - 5,ProgramController.State.COMPLETED.getRunStatus());
  RunId run3=RunIds.generate(now);
  store.setStart(programId,run3.getId(),runIdToSecs(run3));
  Id.Program programId2=Id.Program.from("String_Node_Str","String_Node_Str",ProgramType.FLOW,"String_Node_Str");
  RunId run4=RunIds.generate(now - 5000);
  store.setStart(programId2,run4.getId(),runIdToSecs(run4));
  store.setStop(programId2,run4.getId(),nowSecs - 4,ProgramController.State.COMPLETED.getRunStatus());
  store.setStart(Id.Program.from("String_Node_Str","String_Node_Str",ProgramType.FLOW,"String_Node_Str"),run3.getId(),RunIds.getTime(run3,TimeUnit.MILLISECONDS));
  List<RunRecord> successHistory=store.getRuns(programId,ProgramRunStatus.COMPLETED,0,Long.MAX_VALUE,Integer.MAX_VALUE);
  List<RunRecord> failureHistory=store.getRuns(programId,ProgramRunStatus.FAILED,nowSecs - 20,nowSecs - 10,Integer.MAX_VALUE);
  Assert.assertEquals(failureHistory,store.getRuns(programId,ProgramRunStatus.FAILED,0,Long.MAX_VALUE,Integer.MAX_VALUE));
  Assert.assertEquals(1,successHistory.size());
  Assert.assertEquals(1,failureHistory.size());
  RunRecord run=successHistory.get(0);
  Assert.assertEquals(nowSecs - 10,run.getStartTs());
  Assert.assertEquals(nowSecs - 5,run.getStopTs());
  Assert.assertEquals(ProgramController.State.COMPLETED.getRunStatus(),run.getStatus());
  run=failureHistory.get(0);
  Assert.assertEquals(nowSecs - 20,run.getStartTs());
  Assert.assertEquals(nowSecs - 10,run.getStopTs());
  Assert.assertEquals(ProgramController.State.ERROR.getRunStatus(),run.getStatus());
  List<RunRecord> allHistory=store.getRuns(programId,ProgramRunStatus.ALL,nowSecs - 20,nowSecs + 1,Integer.MAX_VALUE);
  Assert.assertEquals(allHistory.toString(),3,allHistory.size());
  List<RunRecord> runningHistory=store.getRuns(programId,ProgramRunStatus.RUNNING,nowSecs,nowSecs + 1,100);
  Assert.assertEquals(1,runningHistory.size());
  Assert.assertEquals(runningHistory,store.getRuns(programId,ProgramRunStatus.RUNNING,0,Long.MAX_VALUE,100));
  RunRecord expectedRunning=runningHistory.get(0);
  Assert.assertNotNull(expectedRunning);
  RunRecord actualRunning=store.getRun(programId,expectedRunning.getPid());
  Assert.assertEquals(expectedRunning,actualRunning);
  RunRecord expectedCompleted=successHistory.get(0);
  Assert.assertNotNull(expectedCompleted);
  RunRecord actualCompleted=store.getRun(programId,expectedCompleted.getPid());
  Assert.assertEquals(expectedCompleted,actualCompleted);
  RunId run5=RunIds.fromString(UUID.randomUUID().toString());
  store.setStart(programId,run5.getId(),nowSecs - 8);
  store.setStop(programId,run5.getId(),nowSecs - 4,ProgramController.State.COMPLETED.getRunStatus());
  RunId run6=RunIds.fromString(UUID.randomUUID().toString());
  store.setStart(programId,run6.getId(),nowSecs - 2);
  RunRecord expectedRecord5=new RunRecord(run5.getId(),nowSecs - 8,nowSecs - 4,ProgramRunStatus.COMPLETED);
  RunRecord actualRecord5=store.getRun(programId,run5.getId());
  Assert.assertEquals(expectedRecord5,actualRecord5);
  RunRecord expectedRecord6=new RunRecord(run6.getId(),nowSecs - 2,null,ProgramRunStatus.RUNNING);
  RunRecord actualRecord6=store.getRun(programId,run6.getId());
  Assert.assertEquals(expectedRecord6,actualRecord6);
  Assert.assertNull(store.getRun(programId,UUID.randomUUID().toString()));
  Assert.assertTrue(store.getRuns(programId,ProgramRunStatus.COMPLETED,nowSecs - 5000,nowSecs - 2000,Integer.MAX_VALUE).isEmpty());
  Assert.assertTrue(store.getRuns(programId,ProgramRunStatus.ALL,nowSecs - 5000,nowSecs - 2000,Integer.MAX_VALUE).isEmpty());
}

Fixed version (ground truth):
@Test public void testLogProgramRunHistory() throws Exception {
  Id.Program programId=Id.Program.from("String_Node_Str","String_Node_Str",ProgramType.FLOW,"String_Node_Str");
  long now=System.currentTimeMillis();
  long nowSecs=TimeUnit.MILLISECONDS.toSeconds(now);
  RunId run1=RunIds.generate(now - 20000);
  store.setStart(programId,run1.getId(),runIdToSecs(run1));
  store.setStop(programId,run1.getId(),nowSecs - 10,ProgramController.State.ERROR.getRunStatus());
  RunId run2=RunIds.generate(now - 10000);
  store.setStart(programId,run2.getId(),runIdToSecs(run2));
  store.setStop(programId,run2.getId(),nowSecs - 5,ProgramController.State.COMPLETED.getRunStatus());
  RunId run3=RunIds.generate(now);
  store.setStart(programId,run3.getId(),runIdToSecs(run3));
  RunRecord runRecord=store.getRun(programId,run3.getId());
  Assert.assertNull(runRecord.getStopTs());
  Id.Program programId2=Id.Program.from("String_Node_Str","String_Node_Str",ProgramType.FLOW,"String_Node_Str");
  RunId run4=RunIds.generate(now - 5000);
  store.setStart(programId2,run4.getId(),runIdToSecs(run4));
  store.setStop(programId2,run4.getId(),nowSecs - 4,ProgramController.State.COMPLETED.getRunStatus());
  store.setStart(Id.Program.from("String_Node_Str","String_Node_Str",ProgramType.FLOW,"String_Node_Str"),run3.getId(),RunIds.getTime(run3,TimeUnit.MILLISECONDS));
  List<RunRecord> successHistory=store.getRuns(programId,ProgramRunStatus.COMPLETED,0,Long.MAX_VALUE,Integer.MAX_VALUE);
  List<RunRecord> failureHistory=store.getRuns(programId,ProgramRunStatus.FAILED,nowSecs - 20,nowSecs - 10,Integer.MAX_VALUE);
  Assert.assertEquals(failureHistory,store.getRuns(programId,ProgramRunStatus.FAILED,0,Long.MAX_VALUE,Integer.MAX_VALUE));
  Assert.assertEquals(1,successHistory.size());
  Assert.assertEquals(1,failureHistory.size());
  RunRecord run=successHistory.get(0);
  Assert.assertEquals(nowSecs - 10,run.getStartTs());
  Assert.assertEquals(Long.valueOf(nowSecs - 5),run.getStopTs());
  Assert.assertEquals(ProgramController.State.COMPLETED.getRunStatus(),run.getStatus());
  run=failureHistory.get(0);
  Assert.assertEquals(nowSecs - 20,run.getStartTs());
  Assert.assertEquals(Long.valueOf(nowSecs - 10),run.getStopTs());
  Assert.assertEquals(ProgramController.State.ERROR.getRunStatus(),run.getStatus());
  List<RunRecord> allHistory=store.getRuns(programId,ProgramRunStatus.ALL,nowSecs - 20,nowSecs + 1,Integer.MAX_VALUE);
  Assert.assertEquals(allHistory.toString(),3,allHistory.size());
  List<RunRecord> runningHistory=store.getRuns(programId,ProgramRunStatus.RUNNING,nowSecs,nowSecs + 1,100);
  Assert.assertEquals(1,runningHistory.size());
  Assert.assertEquals(runningHistory,store.getRuns(programId,ProgramRunStatus.RUNNING,0,Long.MAX_VALUE,100));
  RunRecord expectedRunning=runningHistory.get(0);
  Assert.assertNotNull(expectedRunning);
  RunRecord actualRunning=store.getRun(programId,expectedRunning.getPid());
  Assert.assertEquals(expectedRunning,actualRunning);
  RunRecord expectedCompleted=successHistory.get(0);
  Assert.assertNotNull(expectedCompleted);
  RunRecord actualCompleted=store.getRun(programId,expectedCompleted.getPid());
  Assert.assertEquals(expectedCompleted,actualCompleted);
  RunId run5=RunIds.fromString(UUID.randomUUID().toString());
  store.setStart(programId,run5.getId(),nowSecs - 8);
  store.setStop(programId,run5.getId(),nowSecs - 4,ProgramController.State.COMPLETED.getRunStatus());
  RunId run6=RunIds.fromString(UUID.randomUUID().toString());
  store.setStart(programId,run6.getId(),nowSecs - 2);
  RunRecord expectedRecord5=new RunRecord(run5.getId(),nowSecs - 8,nowSecs - 4,ProgramRunStatus.COMPLETED);
  RunRecord actualRecord5=store.getRun(programId,run5.getId());
  Assert.assertEquals(expectedRecord5,actualRecord5);
  RunRecord expectedRecord6=new RunRecord(run6.getId(),nowSecs - 2,null,ProgramRunStatus.RUNNING);
  RunRecord actualRecord6=store.getRun(programId,run6.getId());
  Assert.assertEquals(expectedRecord6,actualRecord6);
  Assert.assertNull(store.getRun(programId,UUID.randomUUID().toString()));
  Assert.assertTrue(store.getRuns(programId,ProgramRunStatus.COMPLETED,nowSecs - 5000,nowSecs - 2000,Integer.MAX_VALUE).isEmpty());
  Assert.assertTrue(store.getRuns(programId,ProgramRunStatus.ALL,nowSecs - 5000,nowSecs - 2000,Integer.MAX_VALUE).isEmpty());
}