/** * Test : verify the PreconditionException is thrown when actionCheckDelay > 0 * * @throws Exception */ public void testActionCheckPreCondition1() throws Exception { Instrumentation inst = Services.get().get(InstrumentationService.class).get(); WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING); WorkflowActionBean action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.PREP); ActionCheckXCommand checkCmd = new ActionCheckXCommand(action.getId(), 10); long counterVal; try { counterVal = inst.getCounters() .get(XCommand.INSTRUMENTATION_GROUP) .get(checkCmd.getName() + ".preconditionfailed") .getValue(); } catch (NullPointerException e) { // counter might be null counterVal = 0L; } assertEquals(0L, counterVal); checkCmd.call(); // precondition failed because of actionCheckDelay > 0 counterVal = inst.getCounters() .get(XCommand.INSTRUMENTATION_GROUP) .get(checkCmd.getName() + ".preconditionfailed") .getValue(); assertEquals(1L, counterVal); }
/** * Test : verify the PreconditionException is thrown when job != RUNNING && job != SUSPENDED * * @throws Exception */ public void testActionCheckPreCondition4() throws Exception { Instrumentation inst = Services.get().get(InstrumentationService.class).get(); WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.FAILED, WorkflowInstance.Status.FAILED); WorkflowActionBean action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.RUNNING); ActionCheckXCommand checkCmd = new ActionCheckXCommand(action.getId()); long counterVal; try { counterVal = inst.getCounters() .get(XCommand.INSTRUMENTATION_GROUP) .get(checkCmd.getName() + ".preconditionfailed") .getValue(); } catch (NullPointerException e) { // counter might be null counterVal = 0L; } assertEquals(0L, counterVal); checkCmd.call(); // precondition failed because of job != RUNNING && job != SUSPENDED counterVal = inst.getCounters() .get(XCommand.INSTRUMENTATION_GROUP) .get(checkCmd.getName() + ".preconditionfailed") .getValue(); assertEquals(1L, counterVal); job = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING); action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.RUNNING); checkCmd = new ActionCheckXCommand(action.getId()); checkCmd.call(); // precondition passed because job == RUNNING so counter shouldn't have incremented counterVal = inst.getCounters() .get(XCommand.INSTRUMENTATION_GROUP) .get(checkCmd.getName() + ".preconditionfailed") .getValue(); assertEquals(1L, counterVal); job = this.addRecordToWfJobTable(WorkflowJob.Status.SUSPENDED, WorkflowInstance.Status.SUSPENDED); action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.RUNNING); checkCmd = new ActionCheckXCommand(action.getId()); checkCmd.call(); // precondition passed because job == SUSPENDED so counter shouldn't have incremented counterVal = inst.getCounters() .get(XCommand.INSTRUMENTATION_GROUP) .get(checkCmd.getName() + ".preconditionfailed") .getValue(); assertEquals(1L, counterVal); job = this.addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED); action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.RUNNING); checkCmd = new ActionCheckXCommand(action.getId()); checkCmd.call(); // precondition failed because of job != RUNNING && job != SUSPENDED counterVal = inst.getCounters() .get(XCommand.INSTRUMENTATION_GROUP) .get(checkCmd.getName() + ".preconditionfailed") .getValue(); assertEquals(2L, counterVal); job = this.addRecordToWfJobTable(WorkflowJob.Status.KILLED, WorkflowInstance.Status.KILLED); action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.RUNNING); checkCmd = new ActionCheckXCommand(action.getId()); checkCmd.call(); // precondition failed because of job != RUNNING && job != SUSPENDED counterVal = inst.getCounters() .get(XCommand.INSTRUMENTATION_GROUP) .get(checkCmd.getName() + ".preconditionfailed") .getValue(); assertEquals(3L, counterVal); }