public static boolean areJobsAvailable(ProcessEngineConfigurationImpl processEngineConfiguration) { return !processEngineConfiguration .getManagementService() .createJobQuery() .executable() .list() .isEmpty(); }
public static boolean areJobsAvailable(ProcessEngineConfigurationImpl processEngineConfiguration) { return !processEngineConfiguration .getManagementService() .createJobQuery() .executable() .list() .isEmpty(); }
public boolean areJobsAvailable(ManagementService managementService) { return !managementService .createJobQuery() .executable() .list() .isEmpty(); }
protected String getNextExecutableJobId() { List<Job> jobs = managementService.createJobQuery().executable().listPage(0, 1); if (jobs.size() == 1) { return jobs.get(0).getId(); } else { return null; } }
private void verifyParameterQueryInvocations() { Map<String, Object> parameters = getCompleteParameters(); verify(mockQuery).jobId((String) parameters.get("jobId")); verify(mockQuery).processInstanceId((String) parameters.get("processInstanceId")); verify(mockQuery).processDefinitionId((String) parameters.get("processDefinitionId")); verify(mockQuery).processDefinitionKey((String) parameters.get("processDefinitionKey")); verify(mockQuery).executionId((String) parameters.get("executionId")); verify(mockQuery).activityId((String) parameters.get("activityId")); verify(mockQuery).withRetriesLeft(); verify(mockQuery).executable(); verify(mockQuery).timers(); verify(mockQuery).withException(); verify(mockQuery).exceptionMessage((String) parameters.get("exceptionMessage")); verify(mockQuery).noRetriesLeft(); verify(mockQuery).active(); verify(mockQuery).suspended(); verify(mockQuery).priorityLowerThanOrEquals(JOB_QUERY_MAX_PRIORITY); verify(mockQuery).priorityHigherThanOrEquals(JOB_QUERY_MIN_PRIORITY); verify(mockQuery).jobDefinitionId(MockProvider.EXAMPLE_JOB_DEFINITION_ID); }
private Date testExpression(String timeExpression) { // Set the clock fixed HashMap<String, Object> variables1 = new HashMap<String, Object>(); variables1.put("dueDate", timeExpression); // After process start, there should be timer created ProcessInstance pi1 = runtimeService.startProcessInstanceByKey("intermediateTimerEventExample", variables1); assertEquals(1, managementService.createJobQuery().processInstanceId(pi1.getId()).count()); List<Job> jobs = managementService.createJobQuery().executable().list(); assertEquals(1, jobs.size()); return jobs.get(0).getDuedate(); }
@Test public void testQueryByExecutable() { long testTime = ensureJobDueDateSet? messageDueDate.getTime() : timerThreeFireTime.getTime(); int expectedCount = ensureJobDueDateSet? 0 : 1; ClockUtil.setCurrentTime(new Date(testTime + ONE_SECOND)); // all jobs should be executable at t3 + 1hour.1second JobQuery query = managementService.createJobQuery().executable(); verifyQueryResults(query, 4); // Setting retries of one job to 0, makes it non-executable setRetries(processInstanceIdOne, 0); verifyQueryResults(query, 3); // Setting the clock before the start of the process instance, makes none of the jobs executable ClockUtil.setCurrentTime(testStartTime); verifyQueryResults(query, expectedCount); // 1, since a message is always executable when retries > 0 }
private Date testExpression(String timeExpression) { // Set the clock fixed HashMap<String, Object> variables1 = new HashMap<String, Object>(); variables1.put("dueDate", timeExpression); // After process start, there should be timer created ProcessInstance pi1 = runtimeService.startProcessInstanceByKey("intermediateTimerEventExample", variables1); Assert.assertEquals(1, managementService.createJobQuery().processInstanceId(pi1.getId()).count()); List<Job> jobs = managementService.createJobQuery().executable().list(); Assert.assertEquals(1, jobs.size()); runtimeService.deleteProcessInstance(pi1.getId(), "test"); return jobs.get(0).getDuedate(); }
@Deployment public void testExpression() { // Set the clock fixed HashMap<String, Object> variables1 = new HashMap<String, Object>(); variables1.put("dueDate", new Date()); HashMap<String, Object> variables2 = new HashMap<String, Object>(); variables2.put("dueDate", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(new Date())); // After process start, there should be timer created ProcessInstance pi1 = runtimeService.startProcessInstanceByKey("intermediateTimerEventExample", variables1); ProcessInstance pi2 = runtimeService.startProcessInstanceByKey("intermediateTimerEventExample", variables2); assertEquals(1, managementService.createJobQuery().processInstanceId(pi1.getId()).count()); assertEquals(1, managementService.createJobQuery().processInstanceId(pi2.getId()).count()); // After setting the clock to one second in the future the timers should fire List<Job> jobs = managementService.createJobQuery().executable().list(); assertEquals(2, jobs.size()); for (Job job : jobs) { managementService.executeJob(job.getId()); } assertEquals(0, managementService.createJobQuery().processInstanceId(pi1.getId()).count()); assertEquals(0, managementService.createJobQuery().processInstanceId(pi2.getId()).count()); assertProcessEnded(pi1.getProcessInstanceId()); assertProcessEnded(pi2.getProcessInstanceId()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/runtime/ProcessInstanceSuspensionTest.testJobNotExecutedAfterProcessInstanceSuspend.bpmn20.xml"}) public void testJobNotExecutedAfterProcessInstanceSuspendByProcessDefinitionKey() { Date now = new Date(); ClockUtil.setCurrentTime(now); // Suspending the process instance should also stop the execution of jobs for that process instance ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); runtimeService.startProcessInstanceById(processDefinition.getId()); assertEquals(1, managementService.createJobQuery().count()); runtimeService.suspendProcessInstanceByProcessDefinitionKey(processDefinition.getKey()); assertEquals(1, managementService.createJobQuery().count()); // The jobs should not be executed now ClockUtil.setCurrentTime(new Date(now.getTime() + (60 * 60 * 1000))); // Timer is set to fire on 5 minutes assertEquals(0, managementService.createJobQuery().executable().count()); // Activation of the process instance should now allow for job execution runtimeService.activateProcessInstanceByProcessDefinitionKey(processDefinition.getKey()); assertEquals(1, managementService.createJobQuery().executable().count()); managementService.executeJob(managementService.createJobQuery().singleResult().getId()); assertEquals(0, managementService.createJobQuery().count()); assertEquals(0, runtimeService.createProcessInstanceQuery().count()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/runtime/ProcessInstanceSuspensionTest.testJobNotExecutedAfterProcessInstanceSuspend.bpmn20.xml"}) public void testJobNotExecutedAfterProcessInstanceSuspendByProcessDefinitionId() { Date now = new Date(); ClockUtil.setCurrentTime(now); // Suspending the process instance should also stop the execution of jobs for that process instance ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); runtimeService.startProcessInstanceById(processDefinition.getId()); assertEquals(1, managementService.createJobQuery().count()); runtimeService.suspendProcessInstanceByProcessDefinitionId(processDefinition.getId()); assertEquals(1, managementService.createJobQuery().count()); // The jobs should not be executed now ClockUtil.setCurrentTime(new Date(now.getTime() + (60 * 60 * 1000))); // Timer is set to fire on 5 minutes assertEquals(0, managementService.createJobQuery().executable().count()); // Activation of the process instance should now allow for job execution runtimeService.activateProcessInstanceByProcessDefinitionId(processDefinition.getId()); assertEquals(1, managementService.createJobQuery().executable().count()); managementService.executeJob(managementService.createJobQuery().singleResult().getId()); assertEquals(0, managementService.createJobQuery().count()); assertEquals(0, runtimeService.createProcessInstanceQuery().count()); }
@Deployment public void testJobNotExecutedAfterProcessInstanceSuspend() { Date now = new Date(); ClockUtil.setCurrentTime(now); // Suspending the process instance should also stop the execution of jobs for that process instance ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId()); assertEquals(1, managementService.createJobQuery().count()); runtimeService.suspendProcessInstanceById(processInstance.getId()); assertEquals(1, managementService.createJobQuery().count()); // The jobs should not be executed now ClockUtil.setCurrentTime(new Date(now.getTime() + (60 * 60 * 1000))); // Timer is set to fire on 5 minutes assertEquals(0, managementService.createJobQuery().executable().count()); // Activation of the process instance should now allow for job execution runtimeService.activateProcessInstanceById(processInstance.getId()); assertEquals(1, managementService.createJobQuery().executable().count()); managementService.executeJob(managementService.createJobQuery().singleResult().getId()); assertEquals(0, managementService.createJobQuery().count()); assertEquals(0, runtimeService.createProcessInstanceQuery().count()); }
@Test public void testSateOfScriptTaskProcessWithTransactionCommitAndException() { BpmnModelInstance instance = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() //add wait state .camundaAsyncAfter() .scriptTask() .scriptText("throw new RuntimeException()") .scriptFormat("groovy") .endEvent() .done(); ProcessDefinition processDefinition = processEngineTestRule.deployAndGetDefinition(instance); try { ProcessInstance pi = processEngineRule.getRuntimeService() .startProcessInstanceById(processDefinition.getId()); processEngineRule.getManagementService().executeJob( processEngineRule.getManagementService().createJobQuery().executable().singleResult().getId()); fail("exception expected"); } catch (Exception e) { //expected } assertThat(processEngineRule.getRuntimeService().createProcessInstanceQuery().active().list().size(), is(1)); HistoricProcessInstance entity = getHistoricProcessInstanceWithAssertion(processDefinition); assertThat(entity.getState(), is(HistoricProcessInstance.STATE_ACTIVE)); assertEquals(1, processEngineRule.getHistoryService().createHistoricProcessInstanceQuery().active().count()); }
public static boolean areJobsAvailable(ProcessEngineConfigurationImpl processEngineConfiguration) { return !processEngineConfiguration .getManagementService() .createJobQuery() .executable() .list() .isEmpty(); }
@Test public void testFailingJobBoundaryTimerWithDelegateVariables() throws InterruptedException { ProcessInstance pi = runtimeService.startProcessInstanceByKey("ImmediatelyFailing"); List<Job> jobs = managementService.createJobQuery().list(); assertEquals(1, jobs.size()); assertEquals(3, jobs.get(0).getRetries()); assertEquals(1, runtimeService.createExecutionQuery().processInstanceId(pi.getProcessInstanceId()).activityId("usertask1").count()); assertEquals(2, runtimeService.createExecutionQuery().processInstanceId(pi.getProcessInstanceId()).count()); assertEquals(1, managementService.createJobQuery().executable().count()); waitForJobExecutorToProcessAllJobs(); assertEquals(0, managementService.createJobQuery().executable().count()); // should be 0, because it has failed 3 times assertEquals(1, managementService.createJobQuery().withException().count()); // should be 1, because job failed! assertEquals(1, runtimeService.createExecutionQuery().processInstanceId(pi.getProcessInstanceId()).activityId("usertask1").count()); assertEquals(2, runtimeService.createExecutionQuery().processInstanceId(pi.getProcessInstanceId()).count()); taskService.complete(taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult().getId()); // complete task with failed job => complete process assertEquals(0, runtimeService.createExecutionQuery().processInstanceId(pi.getProcessInstanceId()).count()); assertEquals(0, managementService.createJobQuery().count()); // should be 0, because process is finished. }
public boolean areJobsAvailable(ManagementService managementService) { return !managementService .createJobQuery() .executable() .list() .isEmpty(); }
.executable() .orderByJobRetries() .asc()
public void testQueryByExecutable() { ClockUtil.setCurrentTime(new Date(timerThreeFireTime.getTime() + ONE_SECOND)); // all jobs should be executable at t3 + 1hour.1second JobQuery query = managementService.createJobQuery().executable(); verifyQueryResults(query, 4); // Setting retries of one job to 0, makes it non-executable setRetries(processInstanceIdOne, 0); verifyQueryResults(query, 3); // Setting the clock before the start of the process instance, makes none of the jobs executable ClockUtil.setCurrentTime(testStartTime); verifyQueryResults(query, 1); // 1, since a message is always executable when retries > 0 }