use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class JobExecutorAcquireJobsByTypeAndDueDateTest method testTimerAndOldJobsArePreferred.
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/jobexecutor/simpleAsyncProcess.bpmn20.xml", "org/camunda/bpm/engine/test/jobexecutor/processWithTimerCatch.bpmn20.xml" })
public void testTimerAndOldJobsArePreferred() {
// first start process with timer job
ProcessInstance timerProcess1 = runtimeService.startProcessInstanceByKey("testProcess");
// then start process with async task
incrementClock(1);
ProcessInstance asyncProcess1 = runtimeService.startProcessInstanceByKey("simpleAsyncProcess");
// then start process with timer job
incrementClock(1);
ProcessInstance timerProcess2 = runtimeService.startProcessInstanceByKey("testProcess");
// and another process with async task after the timers are acquirable
incrementClock(61);
ProcessInstance asyncProcess2 = runtimeService.startProcessInstanceByKey("simpleAsyncProcess");
Job timerJob1 = managementService.createJobQuery().processInstanceId(timerProcess1.getId()).singleResult();
Job timerJob2 = managementService.createJobQuery().processInstanceId(timerProcess2.getId()).singleResult();
Job messageJob1 = managementService.createJobQuery().processInstanceId(asyncProcess1.getId()).singleResult();
Job messageJob2 = managementService.createJobQuery().processInstanceId(asyncProcess2.getId()).singleResult();
assertNotNull(timerJob1.getDuedate());
assertNotNull(timerJob2.getDuedate());
assertNotNull(messageJob1.getDuedate());
assertNotNull(messageJob2.getDuedate());
assertTrue(messageJob1.getDuedate().before(timerJob1.getDuedate()));
assertTrue(timerJob1.getDuedate().before(timerJob2.getDuedate()));
assertTrue(timerJob2.getDuedate().before(messageJob2.getDuedate()));
List<JobEntity> acquirableJobs = findAcquirableJobs();
assertEquals(4, acquirableJobs.size());
assertEquals(timerJob1.getId(), acquirableJobs.get(0).getId());
assertEquals(timerJob2.getId(), acquirableJobs.get(1).getId());
assertEquals(messageJob1.getId(), acquirableJobs.get(2).getId());
assertEquals(messageJob2.getId(), acquirableJobs.get(3).getId());
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class AcquireJobCmdUnitTest method nonExclusiveJobsSameInstance.
@Test
public void nonExclusiveJobsSameInstance() {
// given: two non-exclusive jobs for a different process instance
JobEntity job1 = createNonExclusiveJob(JOB_ID_1, PROCESS_INSTANCE_ID_1);
JobEntity job2 = createNonExclusiveJob(JOB_ID_2, PROCESS_INSTANCE_ID_1);
// when the job executor acquire new jobs
when(jobManager.findNextJobsToExecute(any(Page.class))).thenReturn(Arrays.asList(job1, job2));
// then the job executor should acquire job1 and job 2 in different batches
checkThatAcquiredJobsInDifferentBatches();
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class AcquireJobCmdUnitTest method nonExclusiveDifferentInstance.
@Test
public void nonExclusiveDifferentInstance() {
// given: two non-exclusive jobs for the same process instance
JobEntity job1 = createNonExclusiveJob(JOB_ID_1, PROCESS_INSTANCE_ID_1);
JobEntity job2 = createNonExclusiveJob(JOB_ID_2, PROCESS_INSTANCE_ID_2);
// when the job executor acquire new jobs
when(jobManager.findNextJobsToExecute(any(Page.class))).thenReturn(Arrays.asList(job1, job2));
// then the job executor should acquire job1 and job 2 in different batches
checkThatAcquiredJobsInDifferentBatches();
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class AcquireJobCmdUnitTest method exclusiveJobsSameInstance.
@Test
public void exclusiveJobsSameInstance() {
// given: two exclusive jobs for the same process instance
JobEntity job1 = createExclusiveJob(JOB_ID_1, PROCESS_INSTANCE_ID_1);
JobEntity job2 = createExclusiveJob(JOB_ID_2, PROCESS_INSTANCE_ID_1);
// when the job executor acquire new jobs
when(jobManager.findNextJobsToExecute(any(Page.class))).thenReturn(Arrays.asList(job1, job2));
// then the job executor should acquire job1 and job 2 in one batch
AcquiredJobs acquiredJobs = acquireJobsCmd.execute(commandContext);
List<List<String>> jobIdBatches = acquiredJobs.getJobIdBatches();
assertThat(jobIdBatches.size(), is(1));
assertThat(jobIdBatches.get(0).size(), is(2));
assertThat(jobIdBatches.get(0), hasItems(JOB_ID_1, JOB_ID_2));
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class AcquireJobCmdUnitTest method createExclusiveJob.
protected JobEntity createExclusiveJob(String id, String processInstanceId) {
JobEntity job = createNonExclusiveJob(id, processInstanceId);
when(job.isExclusive()).thenReturn(true);
return job;
}
Aggregations