}
@Test
public void testOnJobEvent() throws Exception {
SLAService slas = services.get(SLAService.class);
SLAJobEventListener listener = new SLAJobEventListener();
listener.init(services.getConf());
// add dummy registration events to the SLAService map
SLARegistrationBean job = _createSLARegBean("wf1", AppType.WORKFLOW_JOB);
job.setExpectedStart(DateUtils.parseDateUTC("2012-07-22T00:00Z"));
slas.addRegistrationEvent(job);
assertEquals(1, slas.getSLACalculator().size());
Date actualStart = DateUtils.parseDateUTC("2012-07-22T01:00Z");
WorkflowJobEvent wfe = new WorkflowJobEvent("wf1", "caId1", WorkflowJob.Status.RUNNING, "user1",
"wf-app-name1", actualStart, null);
listener.onWorkflowJobEvent(wfe);
SLACalcStatus serviceObj = slas.getSLACalculator().get("wf1");
// check that start sla has been calculated
assertEquals(EventStatus.START_MISS, serviceObj.getEventStatus());
assertEquals(1, serviceObj.getEventProcessed()); //Job switching to running is only partially
//sla processed. so state = 1
job = _createSLARegBean("wfId1@wa1", AppType.WORKFLOW_ACTION);
slas.addRegistrationEvent(job);
assertEquals(2, slas.getSLACalculator().size());
job.setExpectedStart(DateUtils.parseDateUTC("2012-07-22T00:00Z"));
WorkflowActionEvent wae = new WorkflowActionEvent("wfId1@wa1", "wfId1", WorkflowAction.Status.RUNNING, "user1",
"wf-app-name1", actualStart, null);
listener.onWorkflowActionEvent(wae);
serviceObj = slas.getSLACalculator().get("wfId1@wa1");
// check that start sla has been calculated
assertEquals(EventStatus.START_MISS, serviceObj.getEventStatus());
job = _createSLARegBean("cj1", AppType.COORDINATOR_JOB);
job.setExpectedEnd(DateUtils.parseDateUTC("2012-07-22T01:00Z"));
slas.addRegistrationEvent(job);
assertEquals(3, slas.getSLACalculator().size());
Date actualEnd = DateUtils.parseDateUTC("2012-07-22T00:00Z");
CoordinatorJobEvent cje = new CoordinatorJobEvent("cj1", "bj1", CoordinatorJob.Status.SUCCEEDED, "user1",
"coord-app-name1", actualStart, actualEnd);
listener.onCoordinatorJobEvent(cje);
SLASummaryBean summary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, "cj1");
// check that end and duration sla has been calculated
assertEquals(6, summary.getEventProcessed());
assertEquals(EventStatus.END_MET, summary.getEventStatus());
job = _createSLARegBean("cj1@ca1", AppType.COORDINATOR_ACTION);
actualEnd = DateUtils.parseDateUTC("2012-07-22T02:00Z");
slas.addRegistrationEvent(job);
assertEquals(4, slas.getSLACalculator().size());
CoordinatorActionEvent cae = new CoordinatorActionEvent("cj1@ca1", "cj1", CoordinatorAction.Status.RUNNING, "user1",
"coord-app-name1", null, actualEnd, null);
listener.onCoordinatorActionEvent(cae);
cae = new CoordinatorActionEvent("cj1@ca1", "cj1", CoordinatorAction.Status.KILLED, "user1",
"coord-app-name1", null, actualEnd, null);
listener.onCoordinatorActionEvent(cae);
summary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, "cj1@ca1");
// check that all events are processed
assertEquals(8, summary.getEventProcessed());
assertEquals(EventStatus.END_MISS, summary.getEventStatus());
assertEquals(3, slas.getSLACalculator().size());