use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutor 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());
}
use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutor in project camunda-bpm-platform by camunda.
the class BoundaryTimerNonInterruptingEventTest method moveByHours.
// we cannot use waitForExecutor... method since there will always be one job left
private void moveByHours(int hours) throws Exception {
ClockUtil.setCurrentTime(new Date(ClockUtil.getCurrentTime().getTime() + ((hours * 60 * 1000 * 60) + 5000)));
JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
jobExecutor.start();
Thread.sleep(1000);
jobExecutor.shutdown();
}
use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutor in project camunda-bpm-platform by camunda.
the class ProcessEngineTestRule method waitForJobExecutorToProcessAllJobs.
public void waitForJobExecutorToProcessAllJobs(long maxMillisToWait) {
ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
JobExecutor jobExecutor = processEngineConfiguration.getJobExecutor();
jobExecutor.start();
long intervalMillis = 1000;
int jobExecutorWaitTime = jobExecutor.getWaitTimeInMillis() * 2;
if (maxMillisToWait < jobExecutorWaitTime) {
maxMillisToWait = jobExecutorWaitTime;
}
try {
Timer timer = new Timer();
InterruptTask task = new InterruptTask(Thread.currentThread());
timer.schedule(task, maxMillisToWait);
boolean areJobsAvailable = true;
try {
while (areJobsAvailable && !task.isTimeLimitExceeded()) {
Thread.sleep(intervalMillis);
try {
areJobsAvailable = areJobsAvailable();
} catch (Throwable t) {
// Ignore, possible that exception occurs due to locking/updating of table on MSSQL when
// isolation level doesn't allow READ of the table
}
}
} catch (InterruptedException e) {
} finally {
timer.cancel();
}
if (areJobsAvailable) {
throw new AssertionError("time limit of " + maxMillisToWait + " was exceeded");
}
} finally {
jobExecutor.shutdown();
}
}
use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutor 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);
}
use of org.camunda.bpm.engine.impl.jobexecutor.JobExecutor in project camunda-bpm-platform by camunda.
the class IndependentJobExecutionTest method testDeploymentUnawareJobAcquisition.
@OperateOnDeployment("pa1")
@Test
public void testDeploymentUnawareJobAcquisition() {
JobExecutor defaultJobExecutor = processEngineConfiguration.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 unaware configuration should return both jobs
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
processEngineConfiguration.setJobExecutorDeploymentAware(false);
try {
AcquiredJobs acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(defaultJobExecutor));
Assert.assertEquals(2, acquiredJobs.size());
Assert.assertTrue(acquiredJobs.contains(job1.getId()));
Assert.assertTrue(acquiredJobs.contains(job2.getId()));
} finally {
processEngineConfiguration.setJobExecutorDeploymentAware(true);
}
}
Aggregations