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