Java Code Examples for org.camunda.bpm.engine.runtime.Job#getDuedate()
The following examples show how to use
org.camunda.bpm.engine.runtime.Job#getDuedate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobDto.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
public static JobDto fromJob(Job job) { JobDto dto = new JobDto(); dto.id = job.getId(); dto.jobDefinitionId = job.getJobDefinitionId(); dto.processInstanceId = job.getProcessInstanceId(); dto.processDefinitionId = job.getProcessDefinitionId(); dto.processDefinitionKey = job.getProcessDefinitionKey(); dto.executionId = job.getExecutionId(); dto.exceptionMessage = job.getExceptionMessage(); dto.failedActivityId = job.getFailedActivityId(); dto.retries = job.getRetries(); dto.dueDate = job.getDuedate(); dto.suspended = job.isSuspended(); dto.priority = job.getPriority(); dto.tenantId = job.getTenantId(); dto.createTime = job.getCreateTime(); return dto; }
Example 2
Source File: TaskListenerTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test @Deployment public void testRecalculateTimeoutTaskListenerDuedateCreationDateBased() { // given ProcessInstance pi = runtimeService.startProcessInstanceByKey("process", Variables.putValue("duration", "PT1H")); JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId()); List<Job> jobs = jobQuery.list(); assertEquals(1, jobs.size()); Job job = jobs.get(0); Date oldDate = job.getDuedate(); // when runtimeService.setVariable(pi.getId(), "duration", "PT15M"); managementService.recalculateJobDuedate(job.getId(), true); // then Job jobUpdated = jobQuery.singleResult(); assertEquals(job.getId(), jobUpdated.getId()); assertNotEquals(oldDate, jobUpdated.getDuedate()); assertTrue(oldDate.after(jobUpdated.getDuedate())); assertEquals(LocalDateTime.fromDateFields(jobUpdated.getCreateTime()).plusMinutes(15).toDate(), jobUpdated.getDuedate()); }
Example 3
Source File: TaskListenerTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = "org/camunda/bpm/engine/test/bpmn/tasklistener/TaskListenerTest.testRecalculateTimeoutTaskListenerDuedateCreationDateBased.bpmn20.xml") public void testRecalculateTimeoutTaskListenerDuedateCurrentDateBased() { // given ProcessInstance pi = runtimeService.startProcessInstanceByKey("process", Variables.putValue("duration", "PT1H")); JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId()); List<Job> jobs = jobQuery.list(); assertEquals(1, jobs.size()); Job job = jobs.get(0); Date oldDate = job.getDuedate(); ClockUtil.offset(2000L); // when managementService.recalculateJobDuedate(job.getId(), false); // then Job jobUpdated = jobQuery.singleResult(); assertEquals(job.getId(), jobUpdated.getId()); assertNotEquals(oldDate, jobUpdated.getDuedate()); assertTrue(oldDate.before(jobUpdated.getDuedate())); }
Example 4
Source File: TaskListenerTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test @Deployment public void testRecalculateTimeoutTaskListenerDuedateCreationDateBasedWithDefinedBoundaryEvent() { // given ProcessInstance pi = runtimeService.startProcessInstanceByKey("process", Variables.putValue("duration", "PT1H")); JobQuery jobQuery = managementService.createJobQuery() .processInstanceId(pi.getId()) .activityId("userTask"); List<Job> jobs = jobQuery.list(); assertEquals(1, jobs.size()); Job job = jobs.get(0); Date oldDate = job.getDuedate(); // when runtimeService.setVariable(pi.getId(), "duration", "PT15M"); managementService.recalculateJobDuedate(job.getId(), true); // then Job jobUpdated = jobQuery.singleResult(); assertEquals(job.getId(), jobUpdated.getId()); assertNotEquals(oldDate, jobUpdated.getDuedate()); assertTrue(oldDate.after(jobUpdated.getDuedate())); assertEquals(LocalDateTime.fromDateFields(jobUpdated.getCreateTime()).plusMinutes(15).toDate(), jobUpdated.getDuedate()); }
Example 5
Source File: StartTimerEventTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Deployment public void testRecalculateExpressionStartTimerEvent() throws Exception { // given JobQuery jobQuery = managementService.createJobQuery(); ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionKey("startTimerEventExample"); assertEquals(1, jobQuery.count()); assertEquals(0, processInstanceQuery.count()); Job job = jobQuery.singleResult(); Date oldDate = job.getDuedate(); // when moveByMinutes(2); Date currentTime = ClockUtil.getCurrentTime(); managementService.recalculateJobDuedate(job.getId(), false); // then assertEquals(1, jobQuery.count()); assertEquals(0, processInstanceQuery.count()); Date newDate = jobQuery.singleResult().getDuedate(); assertNotEquals(oldDate, newDate); assertTrue(oldDate.before(newDate)); Date expectedDate = LocalDateTime.fromDateFields(currentTime).plusHours(2).toDate(); assertThat(newDate).isCloseTo(expectedDate, 1000l); // move the clock forward 2 hours and 2 min moveByMinutes(122); executeAllJobs(); List<ProcessInstance> pi = processInstanceQuery.list(); assertEquals(1, pi.size()); assertEquals(0, jobQuery.count()); }
Example 6
Source File: TimerRecalculationTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void testTimerRecalculationBasedOnProcessVariable() { // given Map<String, Object> variables = new HashMap<>(); variables.put("timerExpression", "PT10S"); ProcessInstance instance = runtimeService.startProcessInstanceByKey("TimerRecalculationProcess", variables); ProcessInstanceQuery instancesQuery = runtimeService.createProcessInstanceQuery().processInstanceId(instance.getId()); JobQuery jobQuery = managementService.createJobQuery(); assertEquals(1, instancesQuery.count()); assertEquals(1, jobQuery.count()); Job job = jobQuery.singleResult(); Date oldDueDate = job.getDuedate(); // when runtimeService.setVariable(instance.getId(), "timerExpression", "PT1S"); managementService.recalculateJobDuedate(job.getId(), true); // then assertEquals(1, jobQuery.count()); Job jobRecalculated = jobQuery.singleResult(); assertNotEquals(oldDueDate, jobRecalculated.getDuedate()); Calendar calendar = Calendar.getInstance(); calendar.setTime(jobRecalculated.getCreateTime()); calendar.add(Calendar.SECOND, 1); Date expectedDate = calendar.getTime(); assertEquals(expectedDate, jobRecalculated.getDuedate()); waitForJobExecutorToProcessAllJobs(); assertEquals(0, instancesQuery.count()); }
Example 7
Source File: BoundaryTimerEventTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/timer/BoundaryTimerEventTest.testRecalculateUnchangedExpressionOnTimerCurrentDateBased.bpmn20.xml") public void testRecalculateChangedExpressionOnTimerCreationDateBased(){ // Set the clock fixed Date startTime = new Date(); HashMap<String, Object> variables = new HashMap<String, Object>(); variables.put("duedate", "PT1H"); // After process start, there should be a timer created ProcessInstance pi = runtimeService.startProcessInstanceByKey("testExpressionOnTimer", variables); JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId()); List<Job> jobs = jobQuery.list(); assertEquals(1, jobs.size()); Job job = jobs.get(0); Date oldDate = job.getDuedate(); // After recalculation of the timer, the job's duedate should be the same runtimeService.setVariable(pi.getId(), "duedate", "PT15M"); managementService.recalculateJobDuedate(job.getId(), true); Job jobUpdated = jobQuery.singleResult(); assertEquals(job.getId(), jobUpdated.getId()); assertNotEquals(oldDate, jobUpdated.getDuedate()); assertEquals(LocalDateTime.fromDateFields(jobUpdated.getCreateTime()).plusMinutes(15).toDate(), jobUpdated.getDuedate()); // After setting the clock to time '16 minutes', the timer should fire ClockUtil.setCurrentTime(new Date(startTime.getTime() + TimeUnit.MINUTES.toMillis(16L))); waitForJobExecutorToProcessAllJobs(5000L); assertEquals(0L, jobQuery.count()); // which means the process has ended assertProcessEnded(pi.getId()); }
Example 8
Source File: BoundaryTimerEventTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/timer/BoundaryTimerEventTest.testRecalculateUnchangedExpressionOnTimerCurrentDateBased.bpmn20.xml") public void testRecalculateChangedExpressionOnTimerCurrentDateBased(){ // Set the clock fixed Date startTime = new Date(); HashMap<String, Object> variables = new HashMap<String, Object>(); variables.put("duedate", "PT1H"); // After process start, there should be a timer created ProcessInstance pi = runtimeService.startProcessInstanceByKey("testExpressionOnTimer", variables); JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId()); List<Job> jobs = jobQuery.list(); assertEquals(1, jobs.size()); Job job = jobs.get(0); Date oldDate = job.getDuedate(); ClockUtil.offset(2000L); // After recalculation of the timer, the job's duedate should be changed managementService.recalculateJobDuedate(job.getId(), false); Job jobUpdated = jobQuery.singleResult(); assertEquals(job.getId(), jobUpdated.getId()); assertNotEquals(oldDate, jobUpdated.getDuedate()); assertTrue(oldDate.before(jobUpdated.getDuedate())); // After setting the clock to time '16 minutes', the timer should fire ClockUtil.setCurrentTime(new Date(startTime.getTime() + TimeUnit.HOURS.toMillis(2L))); waitForJobExecutorToProcessAllJobs(5000L); assertEquals(0L, jobQuery.count()); // which means the process has ended assertProcessEnded(pi.getId()); }
Example 9
Source File: BoundaryTimerEventTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Deployment public void testRecalculateUnchangedExpressionOnTimerCurrentDateBased(){ // Set the clock fixed Date startTime = new Date(); HashMap<String, Object> variables = new HashMap<String, Object>(); variables.put("duedate", "PT1H"); // After process start, there should be a timer created ProcessInstance pi = runtimeService.startProcessInstanceByKey("testExpressionOnTimer", variables); JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId()); List<Job> jobs = jobQuery.list(); assertEquals(1, jobs.size()); Job job = jobs.get(0); Date oldDate = job.getDuedate(); // After recalculation of the timer, the job's duedate should be changed Date currentTime = new Date(startTime.getTime() + TimeUnit.MINUTES.toMillis(5)); ClockUtil.setCurrentTime(currentTime); managementService.recalculateJobDuedate(job.getId(), false); Job jobUpdated = jobQuery.singleResult(); assertEquals(job.getId(), jobUpdated.getId()); assertNotEquals(oldDate, jobUpdated.getDuedate()); assertTrue(oldDate.before(jobUpdated.getDuedate())); Date expectedDate = LocalDateTime.fromDateFields(currentTime).plusHours(1).toDate(); assertThat(jobUpdated.getDuedate()).isCloseTo(expectedDate, 1000l); // After setting the clock to time '1 hour and 6 min', the second timer should fire ClockUtil.setCurrentTime(new Date(startTime.getTime() + TimeUnit.HOURS.toMillis(1L) + TimeUnit.MINUTES.toMillis(6L))); waitForJobExecutorToProcessAllJobs(5000L); assertEquals(0L, jobQuery.count()); // which means the process has ended assertProcessEnded(pi.getId()); }
Example 10
Source File: StartTimerEventTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public void testRecalculateNonInterruptingWithChangedDurationExpressionInEventSubprocessCreationDateBased() throws Exception { // given ProcessBuilder processBuilder = Bpmn.createExecutableProcess("process"); BpmnModelInstance modelInstance = processBuilder .startEvent() .userTask() .endEvent().done(); processBuilder.eventSubProcess() .startEvent().interrupting(false).timerWithDuration("${duration}") .userTask("taskInSubprocess") .endEvent(); deploymentId = repositoryService.createDeployment() .addModelInstance("process.bpmn", modelInstance).deploy() .getId(); ProcessInstance pi = runtimeService.startProcessInstanceByKey("process", Variables.createVariables().putValue("duration", "PT60S")); JobQuery jobQuery = managementService.createJobQuery(); Job job = jobQuery.singleResult(); String jobId = job.getId(); Date oldDueDate = job.getDuedate(); // when runtimeService.setVariable(pi.getId(), "duration", "PT2M"); managementService.recalculateJobDuedate(jobId, true); // then assertEquals(1L, jobQuery.count()); Date newDuedate = jobQuery.singleResult().getDuedate(); Date expectedDate = LocalDateTime.fromDateFields(jobQuery.singleResult().getCreateTime()).plusMinutes(2).toDate(); assertTrue(oldDueDate.before(newDuedate)); assertTrue(expectedDate.equals(newDuedate)); managementService.executeJob(jobId); assertEquals(1, taskService.createTaskQuery().taskName("taskInSubprocess").list().size()); }
Example 11
Source File: TestBPMModule.java From Orienteer with Apache License 2.0 | 5 votes |
public boolean areJobsAvailable() { List<Job> list = processEngineRule.getManagementService().createJobQuery().list(); for (Job job : list) { if (!job.isSuspended() && job.getRetries() > 0 && (job.getDuedate() == null || ClockUtil.getCurrentTime().after(job.getDuedate()))) { return true; } } return false; }
Example 12
Source File: IntermediateTimerEventTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/timer/IntermediateTimerEventTest.testRecalculateTimeCycleExpressionCurrentDateBased.bpmn20.xml") public void testRecalculateTimeCycleExpressionCreationDateBased() { // given Map<String, Object> variables = new HashMap<>(); variables.put("cycle", "R/PT15M"); String processInstanceId = runtimeService.startProcessInstanceByKey("process", variables).getId(); JobQuery query = managementService.createJobQuery(); assertEquals(1, query.count()); Job job = query.singleResult(); Date oldDuedate = job.getDuedate(); String jobId = job.getId(); // when runtimeService.setVariable(processInstanceId, "cycle", "R/PT10M"); managementService.recalculateJobDuedate(jobId, true); // then assertEquals(1, query.count()); Date newDuedate = query.singleResult().getDuedate(); assertTrue(oldDuedate.after(newDuedate)); Date expectedDate = LocalDateTime.fromDateFields(job.getCreateTime()).plusMinutes(10).toDate(); assertEquals(expectedDate, newDuedate); managementService.executeJob(jobId); String taskId = taskService.createTaskQuery().singleResult().getId(); taskService.complete(taskId); assertProcessEnded(processInstanceId); }
Example 13
Source File: IntermediateTimerEventTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Deployment public void testRecalculateTimeCycleExpressionCurrentDateBased() { // given Map<String, Object> variables = new HashMap<>(); variables.put("cycle", "R/PT15M"); String processInstanceId = runtimeService.startProcessInstanceByKey("process", variables).getId(); JobQuery query = managementService.createJobQuery(); assertEquals(1, query.count()); Job job = query.singleResult(); Date oldDuedate = job.getDuedate(); String jobId = job.getId(); // when runtimeService.setVariable(processInstanceId, "cycle", "R/PT10M"); managementService.recalculateJobDuedate(jobId, false); // then assertEquals(1, query.count()); assertTrue(oldDuedate.after(query.singleResult().getDuedate())); managementService.executeJob(jobId); String taskId = taskService.createTaskQuery().singleResult().getId(); taskService.complete(taskId); assertProcessEnded(processInstanceId); }
Example 14
Source File: IntermediateTimerEventTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/timer/IntermediateTimerEventTest.testExpressionRecalculateCurrentDateBased.bpmn20.xml") public void testExpressionRecalculateCreationDateBased() throws Exception { // Set the clock fixed HashMap<String, Object> variables = new HashMap<String, Object>(); variables.put("duration", "PT1H"); // After process start, there should be timer created ProcessInstanceWithVariables pi1 = (ProcessInstanceWithVariables) runtimeService.startProcessInstanceByKey("intermediateTimerEventExample", variables); JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi1.getId()); assertEquals(1, jobQuery.count()); Job job = jobQuery.singleResult(); Date firstDate = job.getDuedate(); // After variable change and recalculation, there should still be one timer only, with a changed due date moveByMinutes(65);// move past first due date runtimeService.setVariable(pi1.getProcessInstanceId(), "duration", "PT15M"); processEngine.getManagementService().recalculateJobDuedate(job.getId(), true); assertEquals(1, jobQuery.count()); job = jobQuery.singleResult(); assertNotEquals(firstDate, job.getDuedate()); assertTrue(firstDate.after(job.getDuedate())); Date expectedDate = LocalDateTime.fromDateFields(job.getCreateTime()).plusMinutes(15).toDate(); assertEquals(expectedDate, job.getDuedate()); // After waiting for sixteen minutes the timer should fire ClockUtil.setCurrentTime(new Date(firstDate.getTime() + TimeUnit.MINUTES.toMillis(16L))); waitForJobExecutorToProcessAllJobs(5000L); assertEquals(0, managementService.createJobQuery().processInstanceId(pi1.getId()).count()); assertProcessEnded(pi1.getProcessInstanceId()); }
Example 15
Source File: ProcessEngineTestRule.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected boolean areJobsAvailable() { List<Job> list = processEngine.getManagementService().createJobQuery().list(); for (Job job : list) { if (!job.isSuspended() && job.getRetries() > 0 && (job.getDuedate() == null || ClockUtil.getCurrentTime().after(job.getDuedate()))) { return true; } } return false; }
Example 16
Source File: AbstractProcessEngineTestCase.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public boolean areJobsAvailable() { List<Job> list = managementService.createJobQuery().list(); for (Job job : list) { if (!job.isSuspended() && job.getRetries() > 0 && (job.getDuedate() == null || ClockUtil.getCurrentTime().after(job.getDuedate()))) { return true; } } return false; }
Example 17
Source File: StartTimerEventTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
public void testRecalculateTimeCycleExpressionCurrentDateBased() throws Exception { // given Mocks.register("cycle", "R/PT15M"); ProcessBuilder processBuilder = Bpmn.createExecutableProcess("process"); BpmnModelInstance modelInstance = processBuilder .startEvent().timerWithCycle("${cycle}") .userTask("aTaskName") .endEvent() .done(); deploymentId = repositoryService.createDeployment() .addModelInstance("process.bpmn", modelInstance).deploy() .getId(); JobQuery jobQuery = managementService.createJobQuery(); assertEquals(1, jobQuery.count()); Job job = jobQuery.singleResult(); String jobId = job.getId(); Date oldDuedate = job.getDuedate(); // when moveByMinutes(1); managementService.recalculateJobDuedate(jobId, false); // then Job jobUpdated = jobQuery.singleResult(); assertEquals(jobId, jobUpdated.getId()); assertNotEquals(oldDuedate, jobUpdated.getDuedate()); assertTrue(oldDuedate.before(jobUpdated.getDuedate())); // when Mocks.register("cycle", "R/PT10M"); managementService.recalculateJobDuedate(jobId, false); // then jobUpdated = jobQuery.singleResult(); assertEquals(jobId, jobUpdated.getId()); assertNotEquals(oldDuedate, jobUpdated.getDuedate()); assertTrue(oldDuedate.after(jobUpdated.getDuedate())); Mocks.reset(); }
Example 18
Source File: StartTimerEventTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
public void testRecalculateTimeCycleExpressionCreationDateBased() throws Exception { // given Mocks.register("cycle", "R/PT15M"); ProcessBuilder processBuilder = Bpmn.createExecutableProcess("process"); BpmnModelInstance modelInstance = processBuilder .startEvent().timerWithCycle("${cycle}") .userTask("aTaskName") .endEvent() .done(); deploymentId = repositoryService.createDeployment() .addModelInstance("process.bpmn", modelInstance).deploy() .getId(); JobQuery jobQuery = managementService.createJobQuery(); assertEquals(1, jobQuery.count()); Job job = jobQuery.singleResult(); String jobId = job.getId(); Date oldDuedate = job.getDuedate(); // when moveByMinutes(1); managementService.recalculateJobDuedate(jobId, true); // then Job jobUpdated = jobQuery.singleResult(); assertEquals(jobId, jobUpdated.getId()); Date expectedDate = LocalDateTime.fromDateFields(jobUpdated.getCreateTime()).plusMinutes(15).toDate(); assertEquals(expectedDate, jobUpdated.getDuedate()); // when Mocks.register("cycle", "R/PT10M"); managementService.recalculateJobDuedate(jobId, true); // then jobUpdated = jobQuery.singleResult(); assertEquals(jobId, jobUpdated.getId()); assertNotEquals(oldDuedate, jobUpdated.getDuedate()); assertTrue(oldDuedate.after(jobUpdated.getDuedate())); expectedDate = LocalDateTime.fromDateFields(jobUpdated.getCreateTime()).plusMinutes(10).toDate(); assertEquals(expectedDate, jobUpdated.getDuedate()); Mocks.reset(); }
Example 19
Source File: StartTimerEventTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
public void testRecalculateNonInterruptingWithUnchangedDurationExpressionInEventSubprocessCurrentDateBased() throws Exception { // given ProcessBuilder processBuilder = Bpmn.createExecutableProcess("process"); BpmnModelInstance modelInstance = processBuilder .startEvent() .userTask() .endEvent().done(); processBuilder.eventSubProcess() .startEvent().interrupting(false).timerWithDuration("${duration}") .userTask("taskInSubprocess") .endEvent(); deploymentId = repositoryService.createDeployment() .addModelInstance("process.bpmn", modelInstance).deploy() .getId(); runtimeService.startProcessInstanceByKey("process", Variables.createVariables().putValue("duration", "PT70S")); JobQuery jobQuery = managementService.createJobQuery(); Job job = jobQuery.singleResult(); String jobId = job.getId(); Date oldDueDate = job.getDuedate(); // when moveByMinutes(2); Date currentTime = ClockUtil.getCurrentTime(); managementService.recalculateJobDuedate(jobId, false); // then assertEquals(1L, jobQuery.count()); Date newDuedate = jobQuery.singleResult().getDuedate(); assertNotEquals(oldDueDate, newDuedate); assertTrue(oldDueDate.before(newDuedate)); Date expectedDate = LocalDateTime.fromDateFields(currentTime).plusSeconds(70).toDate(); assertThat(newDuedate).isCloseTo(expectedDate, 1000l); managementService.executeJob(jobId); assertEquals(1, taskService.createTaskQuery().taskName("taskInSubprocess").list().size()); }
Example 20
Source File: AbstractFoxPlatformIntegrationTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
public boolean isJobAvailable(Job job) { return job.getRetries() > 0 && (job.getDuedate() == null || ClockUtil.getCurrentTime().after(job.getDuedate())); }