@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"}) public void testActivationByJobDefinitionId_shouldActivateJob() { // given // a running process instance with a failed job Map<String, Object> params = new HashMap<String, Object>(); params.put("fail", Boolean.TRUE); runtimeService.startProcessInstanceByKey("suspensionProcess", params); // suspended job definitions and corresponding jobs managementService.suspendJobDefinitionByProcessDefinitionKey("suspensionProcess", true); // the job definition JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult(); // the failed job JobQuery jobQuery = managementService.createJobQuery(); Job job = jobQuery.singleResult(); assertTrue(job.isSuspended()); // when // the job will be activated managementService.activateJobByJobDefinitionId(jobDefinition.getId()); // then // the job should be activated assertEquals(0, jobQuery.suspended().count()); assertEquals(1, jobQuery.active().count()); Job activeJob = jobQuery.active().singleResult(); assertEquals(job.getId(), activeJob.getId()); assertEquals(jobDefinition.getId(), activeJob.getJobDefinitionId()); assertFalse(activeJob.isSuspended()); }
@Deployment public void testExclusiveJobs() { JobDefinition jobDefinition = managementService.createJobDefinitionQuery().activityIdIn("task2").singleResult(); // given that the second task is suspended managementService.suspendJobDefinitionById(jobDefinition.getId()); // if I start a process instance runtimeService.startProcessInstanceByKey("testProcess"); waitForJobExecutorToProcessAllJobs(6000); // then the second task is not executed assertEquals(1, runtimeService.createProcessInstanceQuery().count()); // there is a suspended job instance Job job = managementService.createJobQuery().singleResult(); assertEquals(job.getJobDefinitionId(), jobDefinition.getId()); assertTrue(job.isSuspended()); // if I unsuspend the job definition, the job is executed: managementService.activateJobDefinitionById(jobDefinition.getId(), true); waitForJobExecutorToProcessAllJobs(5000); assertEquals(0, runtimeService.createProcessInstanceQuery().count()); // clean up log TestHelper.clearOpLog(processEngineConfiguration); }