Search in sources :

Example 1 with AcquireJobsCmd

use of org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd 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 2 with AcquireJobsCmd

use of org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd 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 3 with AcquireJobsCmd

use of org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd 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 4 with AcquireJobsCmd

use of org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd in project camunda-bpm-platform by camunda.

the class ManagementServiceTest method testDeleteJobThatWasAlreadyAcquired.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/timerOnTask.bpmn20.xml" })
public void testDeleteJobThatWasAlreadyAcquired() {
    ClockUtil.setCurrentTime(new Date());
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnTask");
    Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
    // We need to move time at least one hour to make the timer executable
    ClockUtil.setCurrentTime(new Date(ClockUtil.getCurrentTime().getTime() + 7200000L));
    // Acquire job by running the acquire command manually
    ProcessEngineImpl processEngineImpl = (ProcessEngineImpl) processEngine;
    JobExecutor jobExecutor = processEngineImpl.getProcessEngineConfiguration().getJobExecutor();
    AcquireJobsCmd acquireJobsCmd = new AcquireJobsCmd(jobExecutor);
    CommandExecutor commandExecutor = processEngineImpl.getProcessEngineConfiguration().getCommandExecutorTxRequired();
    commandExecutor.execute(acquireJobsCmd);
    // Try to delete the job. This should fail.
    try {
        managementService.deleteJob(timerJob.getId());
        fail();
    } catch (ProcessEngineException e) {
    // Exception is expected
    }
    // Clean up
    managementService.executeJob(timerJob.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) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Job(org.camunda.bpm.engine.runtime.Job) Date(java.util.Date) ProcessEngineImpl(org.camunda.bpm.engine.impl.ProcessEngineImpl) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 5 with AcquireJobsCmd

use of org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd in project camunda-bpm-platform by camunda.

the class AcquireJobCmdUnitTest method initCommand.

@Before
public void initCommand() {
    JobExecutor jobExecutor = mock(JobExecutor.class);
    when(jobExecutor.getMaxJobsPerAcquisition()).thenReturn(3);
    when(jobExecutor.getLockOwner()).thenReturn("test");
    when(jobExecutor.getLockTimeInMillis()).thenReturn(5 * 60 * 1000);
    acquireJobsCmd = new AcquireJobsCmd(jobExecutor);
    commandContext = mock(CommandContext.class);
    DbEntityManager dbEntityManager = mock(DbEntityManager.class);
    when(commandContext.getDbEntityManager()).thenReturn(dbEntityManager);
    jobManager = mock(JobManager.class);
    when(commandContext.getJobManager()).thenReturn(jobManager);
}
Also used : AcquireJobsCmd(org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) JobExecutor(org.camunda.bpm.engine.impl.jobexecutor.JobExecutor) DbEntityManager(org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager) Before(org.junit.Before)

Aggregations

AcquireJobsCmd (org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd)6 JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)6 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)5 AcquiredJobs (org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs)4 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)3 Job (org.camunda.bpm.engine.runtime.Job)3 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 List (java.util.List)2 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)2 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)2 Test (org.junit.Test)2 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 ProcessEngineImpl (org.camunda.bpm.engine.impl.ProcessEngineImpl)1 DbEntityManager (org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)1 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)1 MessageEntity (org.camunda.bpm.engine.impl.persistence.entity.MessageEntity)1 TimerEntity (org.camunda.bpm.engine.impl.persistence.entity.TimerEntity)1 Deployment (org.camunda.bpm.engine.test.Deployment)1