use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.
the class ExecutionCachedEntityStateTest method testProcessInstanceIncident.
@Deployment
public void testProcessInstanceIncident() {
runtimeService.startProcessInstanceByKey("testProcess");
ExecutionEntity processInstance = (ExecutionEntity) runtimeService.createProcessInstanceQuery().singleResult();
assertEquals(0, processInstance.getCachedEntityStateRaw());
final ExecutionEntity execution = (ExecutionEntity) runtimeService.createExecutionQuery().activityId("task").singleResult();
assertEquals(0, execution.getCachedEntityStateRaw());
processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
IncidentContext incidentContext = new IncidentContext();
incidentContext.setExecutionId(execution.getId());
IncidentEntity.createAndInsertIncident("foo", incidentContext, null);
return null;
}
});
ExecutionEntity execution2 = (ExecutionEntity) runtimeService.createExecutionQuery().activityId("task").singleResult();
assertEquals(BitMaskUtil.getMaskForBit(ExecutionEntity.INCIDENT_STATE_BIT), execution2.getCachedEntityStateRaw());
}
use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.
the class CommandContextInterceptorTest method testCommandContextNestedFailingCommandsNotExceptions.
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void testCommandContextNestedFailingCommandsNotExceptions() {
final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("processThrowingThrowable").startEvent().serviceTask().camundaClass(ThrowErrorJavaDelegate.class).endEvent().done();
deployment(modelInstance);
boolean errorThrown = false;
try {
processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Object>() {
public Object execute(CommandContext commandContext) {
runtimeService.startProcessInstanceByKey("processThrowingThrowable");
return null;
}
});
fail("Exception expected");
} catch (StackOverflowError t) {
// OK
errorThrown = true;
}
assertTrue(ThrowErrorJavaDelegate.executed);
assertTrue(errorThrown);
// Check data base consistency
assertEquals(0, historyService.createHistoricProcessInstanceQuery().count());
}
use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.
the class XmlSerializationTest method testVariableValueCaching.
@Deployment(resources = ONE_TASK_PROCESS)
public void testVariableValueCaching() {
final ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {
@Override
public Void execute(CommandContext commandContext) {
XmlSerializable bean = new XmlSerializable("a String", 42, true);
runtimeService.setVariable(instance.getId(), "simpleBean", bean);
Object returnedBean = runtimeService.getVariable(instance.getId(), "simpleBean");
assertSame(bean, returnedBean);
return null;
}
});
VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().singleResult();
Object returnedBean = variableInstance.getValue();
Object theSameReturnedBean = variableInstance.getValue();
assertSame(returnedBean, theSameReturnedBean);
}
use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.
the class SpinFunctionMapperTest method executeExpression.
@SuppressWarnings("unchecked")
protected <T> T executeExpression(String expression) {
final TestVariableScope varScope = new TestVariableScope();
final Expression compiledExpression = processEngineConfiguration.getExpressionManager().createExpression(expression);
return (T) processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Object>() {
public Object execute(CommandContext commandContext) {
return compiledExpression.getValue(varScope);
}
});
}
use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.
the class DeleteProcessInstancesJobHandler method createJobs.
@Override
public boolean createJobs(BatchEntity batch) {
DeleteProcessInstanceBatchConfiguration configuration = readConfiguration(batch.getConfigurationBytes());
List<String> ids = configuration.getIds();
final CommandContext commandContext = Context.getCommandContext();
int batchJobsPerSeed = batch.getBatchJobsPerSeed();
int invocationsPerBatchJob = batch.getInvocationsPerBatchJob();
int numberOfItemsToProcess = Math.min(invocationsPerBatchJob * batchJobsPerSeed, ids.size());
// view of process instances to process
final List<String> processIds = ids.subList(0, numberOfItemsToProcess);
List<String> deploymentIds = commandContext.runWithoutAuthorization(new Callable<List<String>>() {
@Override
public List<String> call() throws Exception {
return commandContext.getDeploymentManager().findDeploymentIdsByProcessInstances(processIds);
}
});
for (final String deploymentId : deploymentIds) {
List<String> processIdsPerDeployment = commandContext.runWithoutAuthorization(new Callable<List<String>>() {
@Override
public List<String> call() throws Exception {
final ProcessInstanceQueryImpl processInstanceQueryToBeProcess = new ProcessInstanceQueryImpl();
processInstanceQueryToBeProcess.processInstanceIds(new HashSet<String>(processIds)).deploymentId(deploymentId);
return commandContext.getExecutionManager().findProcessInstancesIdsByQueryCriteria(processInstanceQueryToBeProcess);
}
});
processIds.removeAll(processIdsPerDeployment);
createJobEntities(batch, configuration, deploymentId, processIdsPerDeployment, invocationsPerBatchJob);
}
// when there are non existing process instance ids
if (!processIds.isEmpty()) {
createJobEntities(batch, configuration, null, processIds, invocationsPerBatchJob);
}
return ids.isEmpty();
}
Aggregations