calc1.setLastModifiedTime(new Date());
SLASummaryBean slaSummaryBean = new SLASummaryBean(calc1);
List<JsonBean> list = new ArrayList<JsonBean>();
list.add(slaSummaryBean);
jpaService.execute(new SLACalculationInsertUpdateJPAExecutor(null, list));
SLASummaryBean slaSummary = jpaService.execute(new SLASummaryGetJPAExecutor(jobId1));
// Simulate a lost success event
WorkflowJobBean wjb = new WorkflowJobBean();
wjb.setId(jobId1);
wjb.setStatus(WorkflowJob.Status.SUCCEEDED);
wjb.setStartTime(sdf.parse("2012-02-07"));
wjb.setEndTime(sdf.parse("2013-02-07"));
WorkflowJobInsertJPAExecutor wfInsertCmd = new WorkflowJobInsertJPAExecutor(wjb);
jpaService.execute(wfInsertCmd);
slaCalcMemory = new SLACalculatorMemory();
slaCalcMemory.init(new Configuration(false));
// As job succeeded, it should not be in memory
assertEquals(0, slaCalcMemory.size());
slaSummary = jpaService.execute(new SLASummaryGetJPAExecutor(jobId1));
assertEquals("job-1", slaSummary.getId());
assertEquals(8, slaSummary.getEventProcessed());
assertEquals(AppType.WORKFLOW_JOB, slaSummary.getAppType());
assertEquals("SUCCEEDED", slaSummary.getJobStatus());
assertEquals(SLAEvent.SLAStatus.MET, slaSummary.getSLAStatus());
assertEquals(sdf.parse("2012-02-07"), slaSummary.getActualStart());
assertEquals(sdf.parse("2013-02-07"), slaSummary.getActualEnd());
assertEquals(sdf.parse("2013-02-07").getTime() - sdf.parse("2012-02-07").getTime(),
slaSummary.getActualDuration());
// Simulate a lost failed event
wjb.setStatus(WorkflowJob.Status.FAILED);
jpaService.execute(new WorkflowJobUpdateJPAExecutor(wjb));
// Reset the summary Bean
calc1.setEventProcessed(1);
calc1.setSLAStatus(SLAEvent.SLAStatus.IN_PROCESS);
calc1.setJobStatus(WorkflowJob.Status.RUNNING.name());
slaSummaryBean = new SLASummaryBean(calc1);
list = new ArrayList<JsonBean>();
list.add(slaSummaryBean);
jpaService.execute(new SLACalculationInsertUpdateJPAExecutor(null, list));
slaCalcMemory = new SLACalculatorMemory();
slaCalcMemory.init(new Configuration(false));
assertEquals(0, slaCalcMemory.size());
slaSummary = jpaService.execute(new SLASummaryGetJPAExecutor(jobId1));
assertEquals("FAILED", slaSummary.getJobStatus());
assertEquals(8, slaSummary.getEventProcessed());
assertEquals(sdf.parse("2012-02-07"), slaSummary.getActualStart());
assertEquals(sdf.parse("2013-02-07"), slaSummary.getActualEnd());
assertEquals(SLAEvent.SLAStatus.MISS, slaSummary.getSLAStatus());
// Simulate a lost RUNNING event
wjb.setStatus(WorkflowJob.Status.RUNNING);
jpaService.execute(new WorkflowJobUpdateJPAExecutor(wjb));
// Reset the summary Bean
calc1.setEventProcessed(0);
calc1.setSLAStatus(SLAEvent.SLAStatus.NOT_STARTED);
calc1.setJobStatus(null);
slaSummaryBean = new SLASummaryBean(calc1);
list = new ArrayList<JsonBean>();
list.add(slaSummaryBean);
jpaService.execute(new SLACalculationInsertUpdateJPAExecutor(null, list));
slaCalcMemory = new SLACalculatorMemory();
slaCalcMemory.init(new Configuration(false));
assertEquals(1, slaCalcMemory.size());