Search in sources :

Example 1 with AcquiredJobs

use of org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs in project camunda-bpm-platform by camunda.

the class JobDefinitionFunctionalTest method testJobExecutorOnlyAcquiresActiveJobs.

@Test
public void testJobExecutorOnlyAcquiresActiveJobs() {
    testRule.deploy(SIMPLE_ASYNC_PROCESS);
    // given suspended job definition:
    managementService.suspendJobDefinitionByProcessDefinitionKey("simpleAsyncProcess");
    // if I start a new instance
    runtimeService.startProcessInstanceByKey("simpleAsyncProcess");
    // then the new job executor will not acquire the job:
    AcquiredJobs acquiredJobs = acquireJobs();
    assertEquals(0, acquiredJobs.size());
    // -------------------------
    // given a active job definition:
    managementService.activateJobDefinitionByProcessDefinitionKey("simpleAsyncProcess", true);
    // then the new job executor will not acquire the job:
    acquiredJobs = acquireJobs();
    assertEquals(1, acquiredJobs.size());
}
Also used : AcquiredJobs(org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs) Test(org.junit.Test)

Example 2 with AcquiredJobs

use of org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs in project camunda-bpm-platform by camunda.

the class JobExecutorCmdHappyTest method testJobCommandsWithTimer.

public void testJobCommandsWithTimer() {
    // clock gets automatically reset in LogTestCase.runTest
    ClockUtil.setCurrentTime(new Date(SOME_TIME));
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
    String jobId = commandExecutor.execute(new Command<String>() {

        public String execute(CommandContext commandContext) {
            TimerEntity timer = createTweetTimer("i'm coding a test", new Date(SOME_TIME + (10 * SECOND)));
            commandContext.getJobManager().schedule(timer);
            return timer.getId();
        }
    });
    AcquiredJobs acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor));
    List<List<String>> jobIdsList = acquiredJobs.getJobIdBatches();
    assertEquals(0, jobIdsList.size());
    List<String> expectedJobIds = new ArrayList<String>();
    ClockUtil.setCurrentTime(new Date(SOME_TIME + (20 * SECOND)));
    acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor, jobExecutor.getMaxJobsPerAcquisition()));
    jobIdsList = acquiredJobs.getJobIdBatches();
    assertEquals(1, jobIdsList.size());
    List<String> jobIds = jobIdsList.get(0);
    expectedJobIds.add(jobId);
    assertEquals(expectedJobIds, new ArrayList<String>(jobIds));
    assertEquals(0, tweetHandler.getMessages().size());
    ExecuteJobHelper.executeJob(jobId, commandExecutor);
    assertEquals("i'm coding a test", tweetHandler.getMessages().get(0));
    assertEquals(1, tweetHandler.getMessages().size());
    clearDatabase();
}
Also used : AcquireJobsCmd(org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) TimerEntity(org.camunda.bpm.engine.impl.persistence.entity.TimerEntity) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) ArrayList(java.util.ArrayList) Date(java.util.Date) JobExecutor(org.camunda.bpm.engine.impl.jobexecutor.JobExecutor) AcquiredJobs(org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with AcquiredJobs

use of org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs in project camunda-bpm-platform by camunda.

the class JobExecutorCmdHappyTest method testJobCommandsWithMessage.

public void testJobCommandsWithMessage() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
    String jobId = commandExecutor.execute(new Command<String>() {

        public String execute(CommandContext commandContext) {
            MessageEntity message = createTweetMessage("i'm coding a test");
            commandContext.getJobManager().send(message);
            return message.getId();
        }
    });
    AcquiredJobs acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor));
    List<List<String>> jobIdsList = acquiredJobs.getJobIdBatches();
    assertEquals(1, jobIdsList.size());
    List<String> jobIds = jobIdsList.get(0);
    List<String> expectedJobIds = new ArrayList<String>();
    expectedJobIds.add(jobId);
    assertEquals(expectedJobIds, new ArrayList<String>(jobIds));
    assertEquals(0, tweetHandler.getMessages().size());
    ExecuteJobHelper.executeJob(jobId, commandExecutor);
    assertEquals("i'm coding a test", tweetHandler.getMessages().get(0));
    assertEquals(1, tweetHandler.getMessages().size());
    clearDatabase();
}
Also used : AcquireJobsCmd(org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) ArrayList(java.util.ArrayList) MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity) JobExecutor(org.camunda.bpm.engine.impl.jobexecutor.JobExecutor) AcquiredJobs(org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with AcquiredJobs

use of org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs in project camunda-bpm-platform by camunda.

the class AcquireJobCmdUnitTest method exclusiveJobsSameInstance.

@Test
public void exclusiveJobsSameInstance() {
    // given: two exclusive jobs for the same process instance
    JobEntity job1 = createExclusiveJob(JOB_ID_1, PROCESS_INSTANCE_ID_1);
    JobEntity job2 = createExclusiveJob(JOB_ID_2, PROCESS_INSTANCE_ID_1);
    // 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 one batch
    AcquiredJobs acquiredJobs = acquireJobsCmd.execute(commandContext);
    List<List<String>> jobIdBatches = acquiredJobs.getJobIdBatches();
    assertThat(jobIdBatches.size(), is(1));
    assertThat(jobIdBatches.get(0).size(), is(2));
    assertThat(jobIdBatches.get(0), hasItems(JOB_ID_1, JOB_ID_2));
}
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) List(java.util.List) Test(org.junit.Test)

Example 5 with AcquiredJobs

use of org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs in project camunda-bpm-platform by camunda.

the class DeploymentAwareJobExecutorTest method testJobsWithoutDeploymentIdAreAlwaysProcessed.

public void testJobsWithoutDeploymentIdAreAlwaysProcessed() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    String messageId = commandExecutor.execute(new Command<String>() {

        public String execute(CommandContext commandContext) {
            MessageEntity message = new MessageEntity();
            commandContext.getJobManager().send(message);
            return message.getId();
        }
    });
    AcquiredJobs acquiredJobs = getExecutableJobs(processEngineConfiguration.getJobExecutor());
    Assert.assertEquals(1, acquiredJobs.size());
    Assert.assertTrue(acquiredJobs.contains(messageId));
    commandExecutor.execute(new DeleteJobsCmd(messageId, true));
}
Also used : MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) AcquiredJobs(org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs) DeleteJobsCmd(org.camunda.bpm.engine.impl.cmd.DeleteJobsCmd)

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