Search in sources :

Example 31 with CommandExecutor

use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor 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 32 with CommandExecutor

use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.

the class ManagementServiceTest method testSetJobRetriesByDefinitionUnlocksInconsistentJobs.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/ManagementServiceTest.testGetJobExceptionStacktrace.bpmn20.xml" })
public void testSetJobRetriesByDefinitionUnlocksInconsistentJobs() {
    // given a job definition
    final JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();
    // and an inconsistent job that is never again picked up by a job executor
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        @Override
        public Void execute(CommandContext commandContext) {
            JobManager jobManager = commandContext.getJobManager();
            MessageEntity job = new MessageEntity();
            job.setJobDefinitionId(jobDefinition.getId());
            job.setJobHandlerType("any");
            job.setLockOwner("owner");
            job.setLockExpirationTime(ClockUtil.getCurrentTime());
            job.setRetries(0);
            jobManager.send(job);
            return null;
        }
    });
    // when the job retries are reset
    managementService.setJobRetriesByJobDefinitionId(jobDefinition.getId(), 3);
    // then the job can be picked up again
    JobEntity job = (JobEntity) managementService.createJobQuery().singleResult();
    assertNotNull(job);
    assertNull(job.getLockOwner());
    assertNull(job.getLockExpirationTime());
    assertEquals(3, job.getRetries());
    deleteJobAndIncidents(job);
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) 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) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 33 with CommandExecutor

use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.

the class SuspendJobDefinitionTest method tearDown.

@Override
public void tearDown() throws Exception {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerSuspendJobDefinitionHandler.TYPE);
            return null;
        }
    });
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor)

Example 34 with CommandExecutor

use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.

the class ActivateJobDefinitionTest method tearDown.

@Override
public void tearDown() throws Exception {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerActivateJobDefinitionHandler.TYPE);
            return null;
        }
    });
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor)

Example 35 with CommandExecutor

use of org.camunda.bpm.engine.impl.interceptor.CommandExecutor in project camunda-bpm-platform by camunda.

the class SetProcessDefinitionVersionCmdTest method testSetProcessDefinitionVersionNonExistingPD.

@Deployment(resources = { TEST_PROCESS })
public void testSetProcessDefinitionVersionNonExistingPD() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("receiveTask");
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    try {
        commandExecutor.execute(new SetProcessDefinitionVersionCmd(pi.getId(), 23));
        fail("ProcessEngineException expected");
    } catch (ProcessEngineException ae) {
        assertTextPresent("no processes deployed with key = 'receiveTask', version = '23'", ae.getMessage());
    }
}
Also used : CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) SetProcessDefinitionVersionCmd(org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)53 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)31 Deployment (org.camunda.bpm.engine.test.Deployment)17 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)15 SetProcessDefinitionVersionCmd (org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd)13 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)11 Job (org.camunda.bpm.engine.runtime.Job)9 Date (java.util.Date)8 List (java.util.List)7 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)7 Execution (org.camunda.bpm.engine.runtime.Execution)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)5 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)5 AcquireJobsCmd (org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd)5 AcquiredJobs (org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs)5 JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)5 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)5 HistoricIncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity)4 MessageEntity (org.camunda.bpm.engine.impl.persistence.entity.MessageEntity)4