Java Code Examples for org.camunda.bpm.engine.runtime.Job#getId()
The following examples show how to use
org.camunda.bpm.engine.runtime.Job#getId() .
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: ConcurrentJobExecutorTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testCompetingJobExecutionDeleteJobDuringExecution() { //given a simple process with a async service task testRule.deploy(Bpmn .createExecutableProcess("process") .startEvent() .serviceTask("task") .camundaAsyncBefore() .camundaExpression("${true}") .endEvent() .done()); runtimeService.startProcessInstanceByKey("process"); Job currentJob = managementService.createJobQuery().singleResult(); // when a job is executed JobExecutionThread threadOne = new JobExecutionThread(currentJob.getId()); threadOne.startAndWaitUntilControlIsReturned(); //and deleted in parallel managementService.deleteJob(currentJob.getId()); // then the job fails with a OLE and the failed job listener throws no NPE LOG.debug("test thread notifies thread 1"); threadOne.proceedAndWaitTillDone(); assertTrue(threadOne.exception instanceof OptimisticLockingException); }
Example 2
Source File: HistoryCleanupRemovalTimeTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected void assumeWhenThenParallelizedCleanup(List<Job> jobs, Supplier<Long> supplier, long initialInstanceCount) { // assume assertThat(jobs.size(), is(3)); assertThat(supplier.get(), is(initialInstanceCount)); long expectedInstanceCount = initialInstanceCount-(initialInstanceCount/3); for (Job job : jobs) { String jobId = job.getId(); jobIds.add(jobId); // when managementService.executeJob(jobId); // then assertThat(supplier.get(), is(expectedInstanceCount)); expectedInstanceCount = expectedInstanceCount - (initialInstanceCount / 3); } }
Example 3
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 4
Source File: ConcurrentJobExecutorTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void testCompletingJobExecutionSuspendDuringExecution() { testRule.deploy(SIMPLE_ASYNC_PROCESS); runtimeService.startProcessInstanceByKey("simpleAsyncProcess"); Job job = managementService.createJobQuery().singleResult(); // given a waiting execution and a waiting suspension JobExecutionThread executionthread = new JobExecutionThread(job.getId()); executionthread.startAndWaitUntilControlIsReturned(); JobSuspensionThread jobSuspensionThread = new JobSuspensionThread("simpleAsyncProcess"); jobSuspensionThread.startAndWaitUntilControlIsReturned(); // first complete suspension: jobSuspensionThread.proceedAndWaitTillDone(); executionthread.proceedAndWaitTillDone(); // then the execution will fail with optimistic locking assertNull(jobSuspensionThread.exception); assertNotNull(executionthread.exception); //-------------------------------------------- // given a waiting execution and a waiting suspension executionthread = new JobExecutionThread(job.getId()); executionthread.startAndWaitUntilControlIsReturned(); jobSuspensionThread = new JobSuspensionThread("simpleAsyncProcess"); jobSuspensionThread.startAndWaitUntilControlIsReturned(); // first complete execution: executionthread.proceedAndWaitTillDone(); jobSuspensionThread.proceedAndWaitTillDone(); // then there are no optimistic locking exceptions assertNull(jobSuspensionThread.exception); assertNull(executionthread.exception); }
Example 5
Source File: JobDefinitionPriorityTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected Job getJobThatIsNot(Job other) { List<Job> jobs = managementService.createJobQuery().list(); assertEquals(2, jobs.size()); if (jobs.get(0).getId().equals(other.getId())) { return jobs.get(1); } else if (jobs.get(1).getId().equals(other.getId())){ return jobs.get(0); } else { throw new ProcessEngineException("Job with id " + other.getId() + " does not exist anymore"); } }
Example 6
Source File: IncidentTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/IncidentTest.testShouldCreateIncidentOnFailedStartTimerEvent.bpmn"}) public void testShouldCreateIncidentOnFailedStartTimerEvent() { // After process start, there should be timer created JobQuery jobQuery = managementService.createJobQuery(); assertEquals(1, jobQuery.count()); Job job = jobQuery.singleResult(); String jobId = job.getId(); while(0 != job.getRetries()) { try { managementService.executeJob(jobId); fail(); } catch (Exception e) { // expected } job = jobQuery.jobId(jobId).singleResult(); } // job exists job = jobQuery.singleResult(); assertNotNull(job); assertEquals(0, job.getRetries()); // incident was created Incident incident = runtimeService.createIncidentQuery().configuration(job.getId()).singleResult(); assertNotNull(incident); // manually delete job for timer start event managementService.deleteJob(job.getId()); }
Example 7
Source File: IncidentAuthorizationTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public void testQueryForStandaloneIncidents() { // given disableAuthorization(); repositoryService.suspendProcessDefinitionByKey(ONE_INCIDENT_PROCESS_KEY, true, new Date()); String jobId = null; List<Job> jobs = managementService.createJobQuery().list(); for (Job job : jobs) { if (job.getProcessDefinitionKey() == null) { jobId = job.getId(); break; } } managementService.setJobRetries(jobId, 0); enableAuthorization(); // when IncidentQuery query = runtimeService.createIncidentQuery(); // then verifyQueryResults(query, 1); disableAuthorization(); managementService.deleteJob(jobId); enableAuthorization(); clearDatabase(); }
Example 8
Source File: HistoricIncidentAuthorizationTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public void testQueryForStandaloneHistoricIncidents() { // given disableAuthorization(); repositoryService.suspendProcessDefinitionByKey(ONE_INCIDENT_PROCESS_KEY, true, new Date()); String jobId = null; List<Job> jobs = managementService.createJobQuery().list(); for (Job job : jobs) { if (job.getProcessDefinitionKey() == null) { jobId = job.getId(); break; } } managementService.setJobRetries(jobId, 0); enableAuthorization(); // when HistoricIncidentQuery query = historyService.createHistoricIncidentQuery(); // then verifyQueryResults(query, 1); disableAuthorization(); managementService.deleteJob(jobId); enableAuthorization(); clearDatabase(); }
Example 9
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 10
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 11
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 12
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 13
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 14
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 15
Source File: FoxJobRetryCmdTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/async/FoxJobRetryCmdTest.testFailedStartTimerEvent.bpmn20.xml" }) public void testFailedTimerStartEvent() { // After process start, there should be timer created JobQuery jobQuery = managementService.createJobQuery(); assertEquals(1, jobQuery.count()); Job job = managementService.createJobQuery().list().get(0); assertNotNull(job); String jobId = job.getId(); waitForExecutedJobWithRetriesLeft(4, jobId); stillOneJobWithExceptionAndRetriesLeft(jobId); job = refreshJob(jobId); assertNotNull(job); assertEquals(4, job.getRetries()); waitForExecutedJobWithRetriesLeft(3, jobId); job = refreshJob(jobId); assertEquals(3, job.getRetries()); stillOneJobWithExceptionAndRetriesLeft(jobId); waitForExecutedJobWithRetriesLeft(2, jobId); job = refreshJob(jobId); assertEquals(2, job.getRetries()); stillOneJobWithExceptionAndRetriesLeft(jobId); waitForExecutedJobWithRetriesLeft(1, jobId); job = refreshJob(jobId); assertEquals(1, job.getRetries()); stillOneJobWithExceptionAndRetriesLeft(jobId); waitForExecutedJobWithRetriesLeft(0, jobId); job = refreshJob(jobId); assertEquals(0, job.getRetries()); assertEquals(1, managementService.createJobQuery().withException().count()); assertEquals(0, managementService.createJobQuery().jobId(jobId).withRetriesLeft().count()); assertEquals(1, managementService.createJobQuery().noRetriesLeft().count()); }