Search in sources :

Example 51 with CommandContext

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());
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) IncidentContext(org.camunda.bpm.engine.impl.incident.IncidentContext) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 52 with CommandContext

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());
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) RequiredHistoryLevel(org.camunda.bpm.engine.test.RequiredHistoryLevel)

Example 53 with CommandContext

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);
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) VariableInstance(org.camunda.bpm.engine.runtime.VariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 54 with CommandContext

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);
        }
    });
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) Expression(org.camunda.bpm.engine.delegate.Expression) Command(org.camunda.bpm.engine.impl.interceptor.Command) TestVariableScope(org.camunda.spin.plugin.script.TestVariableScope)

Example 55 with CommandContext

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();
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) List(java.util.List) ProcessInstanceQueryImpl(org.camunda.bpm.engine.impl.ProcessInstanceQueryImpl)

Aggregations

CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)120 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)31 List (java.util.List)17 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)17 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)11 Deployment (org.camunda.bpm.engine.test.Deployment)11 ArrayList (java.util.ArrayList)10 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)10 Date (java.util.Date)9 HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)8 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)8 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)8 Command (org.camunda.bpm.engine.impl.interceptor.Command)6 HistoricIncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity)6 After (org.junit.After)6 ProcessApplicationReference (org.camunda.bpm.application.ProcessApplicationReference)5 RepositoryService (org.camunda.bpm.engine.RepositoryService)5 ProcessEngineImpl (org.camunda.bpm.engine.impl.ProcessEngineImpl)5 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)5 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)4