Search in sources :

Example 66 with JobEntity

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

the class JobExecutorShutdownTest method testConcurrentShutdownAndExclusiveFollowUpJob.

@Test
public void testConcurrentShutdownAndExclusiveFollowUpJob() {
    // given
    Deployment deployment = engineRule.getRepositoryService().createDeployment().addModelInstance("foo.bpmn", TWO_ASYNC_TASKS).deploy();
    engineRule.manageDeployment(deployment);
    engineRule.getRuntimeService().startProcessInstanceByKey("process");
    Job firstAsyncJob = engineRule.getManagementService().createJobQuery().singleResult();
    jobExecutor.start();
    // wait before acquisition
    acquisitionThread.waitForSync();
    // wait for no more acquisition syncs
    acquisitionThread.ignoreFutureSyncs();
    acquisitionThread.makeContinue();
    // when waiting during execution of first job
    executionThread.waitForSync();
    // and shutting down the job executor
    jobExecutor.shutdown();
    // and continuing job execution
    executionThread.waitUntilDone();
    // then the current job has completed successfully
    Assert.assertEquals(0, engineRule.getManagementService().createJobQuery().jobId(firstAsyncJob.getId()).count());
    // but the exclusive follow-up job is not executed and is not locked
    JobEntity secondAsyncJob = (JobEntity) engineRule.getManagementService().createJobQuery().singleResult();
    Assert.assertNotNull(secondAsyncJob);
    Assert.assertFalse(secondAsyncJob.getId().equals(firstAsyncJob.getId()));
    Assert.assertNull(secondAsyncJob.getLockOwner());
    Assert.assertNull(secondAsyncJob.getLockExpirationTime());
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) Deployment(org.camunda.bpm.engine.repository.Deployment) Job(org.camunda.bpm.engine.runtime.Job) Test(org.junit.Test)

Example 67 with JobEntity

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

the class JobExecutorShutdownTest method testShutdownAndMultipleLockedJobs.

@Test
public void testShutdownAndMultipleLockedJobs() {
    // given
    Deployment deployment = engineRule.getRepositoryService().createDeployment().addModelInstance("foo.bpmn", SINGLE_ASYNC_TASK).deploy();
    engineRule.manageDeployment(deployment);
    // add two jobs by starting two process instances
    engineRule.getRuntimeService().startProcessInstanceByKey("process");
    engineRule.getRuntimeService().startProcessInstanceByKey("process");
    jobExecutor.start();
    // wait before acquisition
    acquisitionThread.waitForSync();
    // wait for no more acquisition syncs
    acquisitionThread.ignoreFutureSyncs();
    acquisitionThread.makeContinue();
    // when waiting during execution of first job
    executionThread.waitForSync();
    // jobs must now be locked
    List<Job> lockedJobList = engineRule.getManagementService().createJobQuery().list();
    Assert.assertEquals(2, lockedJobList.size());
    for (Job job : lockedJobList) {
        JobEntity jobEntity = (JobEntity) job;
        Assert.assertNotNull(jobEntity.getLockOwner());
    }
    // shut down the job executor while first job is executing
    jobExecutor.shutdown();
    // then let first job continue
    executionThread.waitUntilDone();
    // check that only one job left, which is not executed nor locked
    JobEntity jobEntity = (JobEntity) engineRule.getManagementService().createJobQuery().singleResult();
    Assert.assertNotNull(jobEntity);
    Assert.assertTrue(lockedJobList.get(1).getId().equals(jobEntity.getId()) || lockedJobList.get(0).getId().equals(jobEntity.getId()));
    Assert.assertNull(jobEntity.getLockOwner());
    Assert.assertNull(jobEntity.getLockExpirationTime());
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) Deployment(org.camunda.bpm.engine.repository.Deployment) Job(org.camunda.bpm.engine.runtime.Job) Test(org.junit.Test)

Example 68 with JobEntity

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

the class FailedJobListenerWithRetriesTest method testFailedJobListenerRetries.

@Test
@org.camunda.bpm.engine.test.Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/IncidentTest.testShouldCreateOneIncident.bpmn" })
public void testFailedJobListenerRetries() {
    // given
    runtimeService.startProcessInstanceByKey("failingProcess");
    // when the job is run several times till the incident creation
    Job job = getJob();
    while (job.getRetries() > 0 && ((JobEntity) job).getLockOwner() == null) {
        try {
            lockTheJob(job.getId());
            engineRule.getManagementService().executeJob(job.getId());
        } catch (Exception ex) {
        }
        job = getJob();
    }
    // then
    JobEntity jobFinalState = (JobEntity) engineRule.getManagementService().createJobQuery().jobId(job.getId()).list().get(0);
    assertEquals(jobRetries, jobFinalState.getRetries());
    if (jobLocked) {
        assertNotNull(jobFinalState.getLockOwner());
        assertNotNull(jobFinalState.getLockExpirationTime());
    } else {
        assertNull(jobFinalState.getLockOwner());
        assertNull(jobFinalState.getLockExpirationTime());
    }
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) Job(org.camunda.bpm.engine.runtime.Job) OptimisticLockingException(org.camunda.bpm.engine.OptimisticLockingException) Test(org.junit.Test)

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