use of org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs in project camunda-bpm-platform by camunda.
the class BackoffJobAcquisitionStrategyTest method testWaitTimeOnFullRejection.
@Test
public void testWaitTimeOnFullRejection() {
// given a job acquisition strategy and a job acquisition context
// with acquired jobs all of which have been rejected for execution
JobAcquisitionContext context = new JobAcquisitionContext();
AcquiredJobs acquiredJobs = buildAcquiredJobs(NUM_JOBS_TO_ACQUIRE, NUM_JOBS_TO_ACQUIRE, 0);
context.submitAcquiredJobs(ENGINE_NAME, acquiredJobs);
for (int i = 0; i < NUM_JOBS_TO_ACQUIRE; i++) {
context.submitRejectedBatch(ENGINE_NAME, acquiredJobs.getJobIdBatches().get(i));
}
// when reconfiguring the strategy
strategy.reconfigure(context);
// then there is a slight wait time to avoid constant spinning while
// no execution resources are available
Assert.assertEquals(BackoffJobAcquisitionStrategy.DEFAULT_EXECUTION_SATURATION_WAIT_TIME, strategy.getWaitTime());
}
use of org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs in project camunda-bpm-platform by camunda.
the class IndependentJobExecutionTest method testDeploymentAwareJobAcquisition.
@OperateOnDeployment("pa1")
@Test
public void testDeploymentAwareJobAcquisition() {
JobExecutor jobExecutor1 = engine1Configuration.getJobExecutor();
ProcessInstance instance1 = engine1.getRuntimeService().startProcessInstanceByKey("archive1Process");
ProcessInstance instance2 = processEngine.getRuntimeService().startProcessInstanceByKey("archive2Process");
Job job1 = managementService.createJobQuery().processInstanceId(instance1.getId()).singleResult();
Job job2 = managementService.createJobQuery().processInstanceId(instance2.getId()).singleResult();
// the deployment aware configuration should only return the jobs of the registered deployments
CommandExecutor commandExecutor = engine1Configuration.getCommandExecutorTxRequired();
AcquiredJobs acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor1));
Assert.assertEquals(1, acquiredJobs.size());
Assert.assertTrue(acquiredJobs.contains(job1.getId()));
Assert.assertFalse(acquiredJobs.contains(job2.getId()));
}
use of org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs in project camunda-bpm-platform by camunda.
the class AcquireJobsCmd method execute.
public AcquiredJobs execute(CommandContext commandContext) {
acquiredJobs = new AcquiredJobs(numJobsToAcquire);
List<JobEntity> jobs = commandContext.getJobManager().findNextJobsToExecute(new Page(0, numJobsToAcquire));
Map<String, List<String>> exclusiveJobsByProcessInstance = new HashMap<String, List<String>>();
for (JobEntity job : jobs) {
lockJob(job);
if (job.isExclusive()) {
List<String> list = exclusiveJobsByProcessInstance.get(job.getProcessInstanceId());
if (list == null) {
list = new ArrayList<String>();
exclusiveJobsByProcessInstance.put(job.getProcessInstanceId(), list);
}
list.add(job.getId());
} else {
acquiredJobs.addJobIdBatch(job.getId());
}
}
for (List<String> jobIds : exclusiveJobsByProcessInstance.values()) {
acquiredJobs.addJobIdBatch(jobIds);
}
// register an OptimisticLockingListener which is notified about jobs which cannot be acquired.
// the listener removes them from the list of acquired jobs.
commandContext.getDbEntityManager().registerOptimisticLockingListener(this);
return acquiredJobs;
}
use of org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs in project camunda-bpm-platform by camunda.
the class AcquireJobsCmdTest method testJobsNotVisisbleToAcquisitionIfInstanceSuspended.
@Deployment(resources = { "org/camunda/bpm/engine/test/standalone/jobexecutor/oneJobProcess.bpmn20.xml" })
public void testJobsNotVisisbleToAcquisitionIfInstanceSuspended() {
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().singleResult();
ProcessInstance pi = runtimeService.startProcessInstanceByKey(pd.getKey());
// now there is one job:
Job job = managementService.createJobQuery().singleResult();
assertNotNull(job);
makeSureJobDue(job);
// the acquirejobs command sees the job:
AcquiredJobs acquiredJobs = executeAcquireJobsCommand();
assertEquals(1, acquiredJobs.size());
// suspend the process instance:
runtimeService.suspendProcessInstanceById(pi.getId());
// now, the acquirejobs command does not see the job:
acquiredJobs = executeAcquireJobsCommand();
assertEquals(0, acquiredJobs.size());
}
use of org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs in project camunda-bpm-platform by camunda.
the class AcquireJobsCmdTest method testJobsNotVisisbleToAcquisitionIfDefinitionSuspended.
@Deployment(resources = { "org/camunda/bpm/engine/test/standalone/jobexecutor/oneJobProcess.bpmn20.xml" })
public void testJobsNotVisisbleToAcquisitionIfDefinitionSuspended() {
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().singleResult();
runtimeService.startProcessInstanceByKey(pd.getKey());
// now there is one job:
Job job = managementService.createJobQuery().singleResult();
assertNotNull(job);
makeSureJobDue(job);
// the acquirejobs command sees the job:
AcquiredJobs acquiredJobs = executeAcquireJobsCommand();
assertEquals(1, acquiredJobs.size());
// suspend the process instance:
repositoryService.suspendProcessDefinitionById(pd.getId());
// now, the acquirejobs command does not see the job:
acquiredJobs = executeAcquireJobsCommand();
assertEquals(0, acquiredJobs.size());
}
Aggregations