Search in sources :

Example 61 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class AcquireJobCmdUnitTest method exclusiveJobsDifferentInstance.

@Test
public void exclusiveJobsDifferentInstance() {
    // given: two exclusive jobs for a different process instance
    JobEntity job1 = createExclusiveJob(JOB_ID_1, PROCESS_INSTANCE_ID_1);
    JobEntity job2 = createExclusiveJob(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();
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) Page(org.camunda.bpm.engine.impl.Page) Test(org.junit.Test)

Example 62 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class AcquireJobCmdUnitTest method createNonExclusiveJob.

protected JobEntity createNonExclusiveJob(String id, String processInstanceId) {
    JobEntity job = mock(JobEntity.class);
    when(job.getId()).thenReturn(id);
    when(job.getProcessInstanceId()).thenReturn(processInstanceId);
    return job;
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity)

Example 63 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class DeploymentAwareJobExecutorTest method testTimerStartEvent.

@Deployment(resources = "org/camunda/bpm/engine/test/jobexecutor/processWithTimerStart.bpmn20.xml")
public void testTimerStartEvent() {
    Set<String> registeredDeployments = processEngineConfiguration.getRegisteredDeployments();
    Job existingJob = managementService.createJobQuery().singleResult();
    ClockUtil.setCurrentTime(new Date(System.currentTimeMillis() + 1000));
    List<JobEntity> acquirableJobs = findAcquirableJobs();
    assertEquals(1, acquirableJobs.size());
    assertEquals(existingJob.getId(), acquirableJobs.get(0).getId());
    registeredDeployments.clear();
    acquirableJobs = findAcquirableJobs();
    assertEquals(0, acquirableJobs.size());
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) Job(org.camunda.bpm.engine.runtime.Job) Date(java.util.Date) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 64 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class JobExecutorFollowUpTest method testExecuteExclusiveFollowUpJobInSameProcessInstance.

@Test
public void testExecuteExclusiveFollowUpJobInSameProcessInstance() {
    testHelper.deploy(TWO_TASKS_PROCESS);
    // given
    // a process instance with a single job
    ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("process");
    jobExecutor.start();
    // and first job acquisition that acquires the job
    acquisitionThread.waitForSync();
    acquisitionThread.makeContinueAndWaitForSync();
    // and first job execution
    acquisitionThread.makeContinue();
    // waiting inside delegate
    executionThread.waitForSync();
    // completing delegate
    executionThread.makeContinueAndWaitForSync();
    // then
    // the follow-up job should be executed right away
    // i.e., there is a transition instance for the second service task
    ActivityInstance activityInstance = engineRule.getRuntimeService().getActivityInstance(processInstance.getId());
    Assert.assertEquals(1, activityInstance.getTransitionInstances("serviceTask2").length);
    // and the corresponding job is locked
    JobEntity followUpJob = (JobEntity) engineRule.getManagementService().createJobQuery().singleResult();
    Assert.assertNotNull(followUpJob);
    Assert.assertNotNull(followUpJob.getLockOwner());
    Assert.assertNotNull(followUpJob.getLockExpirationTime());
    // and the job can be completed successfully such that the process instance ends
    executionThread.makeContinue();
    acquisitionThread.waitForSync();
    // and the process instance has finished
    testHelper.assertProcessEnded(processInstance.getId());
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test)

Example 65 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class JobExecutorAcquireJobsByDueDateTest method testOldJobsArePreferred.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/jobexecutor/simpleAsyncProcess.bpmn20.xml", "org/camunda/bpm/engine/test/jobexecutor/processWithTimerCatch.bpmn20.xml" })
public void testOldJobsArePreferred() {
    // 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(messageJob1.getId(), acquirableJobs.get(0).getId());
    assertEquals(timerJob1.getId(), acquirableJobs.get(1).getId());
    assertEquals(timerJob2.getId(), acquirableJobs.get(2).getId());
    assertEquals(messageJob2.getId(), acquirableJobs.get(3).getId());
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Job(org.camunda.bpm.engine.runtime.Job) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)68 Test (org.junit.Test)26 Date (java.util.Date)18 Job (org.camunda.bpm.engine.runtime.Job)13 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)11 HistoryCleanupJobHandlerConfiguration (org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration)9 Deployment (org.camunda.bpm.engine.test.Deployment)9 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)7 SimpleDateFormat (java.text.SimpleDateFormat)6 List (java.util.List)6 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)6 Page (org.camunda.bpm.engine.impl.Page)5 JobDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity)5 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)4 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)4 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)4 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)4 ArrayList (java.util.ArrayList)3 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)3