Search in sources :

Example 6 with AcquiredJobs

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());
}
Also used : AcquiredJobs(org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs) JobAcquisitionContext(org.camunda.bpm.engine.impl.jobexecutor.JobAcquisitionContext) Test(org.junit.Test)

Example 7 with AcquiredJobs

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()));
}
Also used : AcquireJobsCmd(org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd) JobExecutor(org.camunda.bpm.engine.impl.jobexecutor.JobExecutor) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) AcquiredJobs(org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Job(org.camunda.bpm.engine.runtime.Job) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest) Test(org.junit.Test)

Example 8 with AcquiredJobs

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;
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) AcquiredJobs(org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs) Page(org.camunda.bpm.engine.impl.Page)

Example 9 with 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());
}
Also used : AcquiredJobs(org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Job(org.camunda.bpm.engine.runtime.Job) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 10 with AcquiredJobs

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());
}
Also used : AcquiredJobs(org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Job(org.camunda.bpm.engine.runtime.Job) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

AcquiredJobs (org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs)17 Job (org.camunda.bpm.engine.runtime.Job)6 Test (org.junit.Test)6 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)5 Deployment (org.camunda.bpm.engine.test.Deployment)5 List (java.util.List)4 AcquireJobsCmd (org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd)4 JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)4 ArrayList (java.util.ArrayList)3 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)3 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)3 Page (org.camunda.bpm.engine.impl.Page)2 JobAcquisitionContext (org.camunda.bpm.engine.impl.jobexecutor.JobAcquisitionContext)2 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)2 MessageEntity (org.camunda.bpm.engine.impl.persistence.entity.MessageEntity)2 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)2 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)2 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1