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());
}
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());
}
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());
}
}
Aggregations