use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.
the class ExecutionTree method forExecution.
public static ExecutionTree forExecution(final String executionId, ProcessEngine processEngine) {
ProcessEngineConfigurationImpl configuration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
CommandExecutor commandExecutor = configuration.getCommandExecutorTxRequired();
ExecutionTree executionTree = commandExecutor.execute(new Command<ExecutionTree>() {
public ExecutionTree execute(CommandContext commandContext) {
ExecutionEntity execution = commandContext.getExecutionManager().findExecutionById(executionId);
return ExecutionTree.forExecution(execution);
}
});
return executionTree;
}
use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.
the class UserOperationLogQueryTest method testQueryJobDefinitionOperationWithDelayedJobDefinition.
@Deployment(resources = { ONE_TASK_PROCESS })
public void testQueryJobDefinitionOperationWithDelayedJobDefinition() {
// given
// a running process instance
ProcessInstance process = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// with a process definition id
String processDefinitionId = process.getProcessDefinitionId();
// ...which will be suspended with the corresponding jobs
managementService.suspendJobDefinitionByProcessDefinitionId(processDefinitionId, true);
// one week from now
ClockUtil.setCurrentTime(today);
long oneWeekFromStartTime = today.getTime() + (7 * 24 * 60 * 60 * 1000);
// when
// activate the job definition
managementService.activateJobDefinitionByProcessDefinitionId(processDefinitionId, false, new Date(oneWeekFromStartTime));
// then
// there is a user log entry for the activation
Long jobDefinitionEntryCount = query().entityType(JOB_DEFINITION).operationType(UserOperationLogEntry.OPERATION_TYPE_ACTIVATE_JOB_DEFINITION).processDefinitionId(processDefinitionId).count();
assertEquals(1, jobDefinitionEntryCount.longValue());
// there exists a job for the delayed activation execution
JobQuery jobQuery = managementService.createJobQuery();
Job delayedActivationJob = jobQuery.timers().active().singleResult();
assertNotNull(delayedActivationJob);
// execute job
managementService.executeJob(delayedActivationJob.getId());
jobDefinitionEntryCount = query().entityType(JOB_DEFINITION).operationType(UserOperationLogEntry.OPERATION_TYPE_ACTIVATE_JOB_DEFINITION).processDefinitionId(processDefinitionId).count();
assertEquals(1, jobDefinitionEntryCount.longValue());
// Clean up db
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new Command<Object>() {
public Object execute(CommandContext commandContext) {
commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerActivateJobDefinitionHandler.TYPE);
return null;
}
});
}
use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.
the class UserOperationLogQueryTest method testQueryProcessDefinitionOperationWithDelayedProcessDefinition.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/repository/ProcessDefinitionSuspensionTest.testWithOneAsyncServiceTask.bpmn" })
public void testQueryProcessDefinitionOperationWithDelayedProcessDefinition() {
// given
ClockUtil.setCurrentTime(today);
final long hourInMs = 60 * 60 * 1000;
String key = "oneFailingServiceTaskProcess";
// a running process instance with a failed service task
Map<String, Object> params = new HashMap<String, Object>();
params.put("fail", Boolean.TRUE);
runtimeService.startProcessInstanceByKey(key, params);
// when
// the process definition will be suspended
repositoryService.suspendProcessDefinitionByKey(key, false, new Date(today.getTime() + (2 * hourInMs)));
// then
// there exists a timer job to suspend the process definition delayed
Job timerToSuspendProcessDefinition = managementService.createJobQuery().timers().singleResult();
assertNotNull(timerToSuspendProcessDefinition);
// there is a user log entry for the activation
Long processDefinitionEntryCount = query().entityType(PROCESS_DEFINITION).operationType(UserOperationLogEntry.OPERATION_TYPE_SUSPEND_PROCESS_DEFINITION).processDefinitionKey(key).count();
assertEquals(1, processDefinitionEntryCount.longValue());
// when
// execute job
managementService.executeJob(timerToSuspendProcessDefinition.getId());
// then
// there is a user log entry for the activation
processDefinitionEntryCount = query().entityType(PROCESS_DEFINITION).operationType(UserOperationLogEntry.OPERATION_TYPE_SUSPEND_PROCESS_DEFINITION).processDefinitionKey(key).count();
assertEquals(1, processDefinitionEntryCount.longValue());
// clean up op log
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new Command<Object>() {
public Object execute(CommandContext commandContext) {
commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerSuspendProcessDefinitionHandler.TYPE);
return null;
}
});
}
use of org.camunda.bpm.engine.impl.interceptor.CommandContext 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.interceptor.CommandContext 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();
}
Aggregations