Search in sources :

Example 16 with JobExecutor

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());
}
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 17 with JobExecutor

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();
}
Also used : JobExecutor(org.camunda.bpm.engine.impl.jobexecutor.JobExecutor) Date(java.util.Date)

Example 18 with JobExecutor

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();
    }
}
Also used : Timer(java.util.Timer) JobExecutor(org.camunda.bpm.engine.impl.jobexecutor.JobExecutor) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)

Example 19 with JobExecutor

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

Example 20 with JobExecutor

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

Aggregations

JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)21 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)6 AcquireJobsCmd (org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd)6 Timer (java.util.Timer)5 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)5 AcquiredJobs (org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs)4 Test (org.junit.Test)4 Date (java.util.Date)3 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)3 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 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AbstractProcessApplication (org.camunda.bpm.application.AbstractProcessApplication)2 PlatformServiceContainer (org.camunda.bpm.container.impl.spi.PlatformServiceContainer)2 ProcessEngineConfiguration (org.camunda.bpm.engine.ProcessEngineConfiguration)2 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)2 HashMap (java.util.HashMap)1