Search in sources :

Example 36 with Execution

use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.

the class MessageCorrelationTest method testCorrelationByProcessInstanceId.

@Deployment(resources = "org/camunda/bpm/engine/test/api/runtime/MessageCorrelationTest.testCatchingMessageEventCorrelation.bpmn20.xml")
@Test
public void testCorrelationByProcessInstanceId() {
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("process");
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("process");
    // correlation with only the name is ambiguous:
    try {
        runtimeService.createMessageCorrelation("aMessageName").correlate();
        fail("Expect an Exception");
    } catch (MismatchingMessageCorrelationException e) {
        testRule.assertTextPresent("Cannot correlate message", e.getMessage());
    }
    // use process instance id as well
    runtimeService.createMessageCorrelation("newInvoiceMessage").processInstanceId(processInstance1.getId()).correlate();
    Execution correlatedExecution = runtimeService.createExecutionQuery().activityId("task").processInstanceId(processInstance1.getId()).singleResult();
    assertNotNull(correlatedExecution);
    Execution uncorrelatedExecution = runtimeService.createExecutionQuery().activityId("task").processInstanceId(processInstance2.getId()).singleResult();
    assertNull(uncorrelatedExecution);
    runtimeService.deleteProcessInstance(processInstance1.getId(), null);
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) MismatchingMessageCorrelationException(org.camunda.bpm.engine.MismatchingMessageCorrelationException) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 37 with Execution

use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.

the class MessageCorrelationByLocalVariablesTest method testReceiveTaskMessageCorrelation.

@Test
public void testReceiveTaskMessageCorrelation() {
    // given
    BpmnModelInstance model = Bpmn.createExecutableProcess("Process_1").startEvent().subProcess("SubProcess_1").embeddedSubProcess().startEvent().receiveTask("MessageReceiver_1").message(TEST_MESSAGE_NAME).camundaInputParameter("localVar", "${loopVar}").camundaInputParameter("constVar", // to test array of parameters
    "someValue").userTask("UserTask_1").endEvent().subProcessDone().multiInstance().camundaCollection("${vars}").camundaElementVariable("loopVar").multiInstanceDone().endEvent().done();
    testHelper.deploy(model);
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("vars", Arrays.asList(1, 2, 3));
    ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("Process_1", variables);
    // when correlated by local variables
    String messageName = TEST_MESSAGE_NAME;
    Map<String, Object> correlationKeys = new HashMap<String, Object>();
    int correlationKey = 1;
    correlationKeys.put("localVar", correlationKey);
    correlationKeys.put("constVar", "someValue");
    MessageCorrelationResult messageCorrelationResult = engineRule.getRuntimeService().createMessageCorrelation(messageName).localVariablesEqual(correlationKeys).setVariables(Variables.createVariables().putValue("newVar", "newValue")).correlateWithResult();
    // then one message is correlated, two other continue waiting
    checkExecutionMessageCorrelationResult(messageCorrelationResult, processInstance, "MessageReceiver_1");
    // uncorrelated executions
    List<Execution> uncorrelatedExecutions = engineRule.getRuntimeService().createExecutionQuery().activityId("MessageReceiver_1").list();
    assertEquals(2, uncorrelatedExecutions.size());
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) MessageCorrelationResult(org.camunda.bpm.engine.runtime.MessageCorrelationResult) Test(org.junit.Test)

Example 38 with Execution

use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.

the class MessageCorrelationByLocalVariablesTest method testBothInstanceAndLocalVariableMessageCorrelation.

@Test
public void testBothInstanceAndLocalVariableMessageCorrelation() {
    // given
    BpmnModelInstance model = Bpmn.createExecutableProcess("Process_1").startEvent().subProcess("SubProcess_1").embeddedSubProcess().startEvent().receiveTask("MessageReceiver_1").message(TEST_MESSAGE_NAME).userTask("UserTask_1").endEvent().subProcessDone().multiInstance().camundaCollection("${vars}").camundaElementVariable("loopVar").multiInstanceDone().endEvent().done();
    model = modify(model).activityBuilder("MessageReceiver_1").camundaInputParameter("localVar", "${loopVar}").camundaInputParameter("constVar", // to test array of parameters
    "someValue").done();
    testHelper.deploy(model);
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("vars", Arrays.asList(1, 2, 3));
    variables.put("processInstanceVar", "processInstanceVarValue");
    ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("Process_1", variables);
    // second process instance with another process instance variable value
    variables = new HashMap<String, Object>();
    variables.put("vars", Arrays.asList(1, 2, 3));
    variables.put("processInstanceVar", "anotherProcessInstanceVarValue");
    engineRule.getRuntimeService().startProcessInstanceByKey("Process_1", variables);
    // when correlated by local variables
    String messageName = TEST_MESSAGE_NAME;
    Map<String, Object> correlationKeys = new HashMap<String, Object>();
    int correlationKey = 1;
    correlationKeys.put("localVar", correlationKey);
    correlationKeys.put("constVar", "someValue");
    Map<String, Object> processInstanceKeys = new HashMap<String, Object>();
    String processInstanceVarValue = "processInstanceVarValue";
    processInstanceKeys.put("processInstanceVar", processInstanceVarValue);
    Map<String, Object> messagePayload = new HashMap<String, Object>();
    messagePayload.put("newVar", "newValue");
    MessageCorrelationResult messageCorrelationResult = engineRule.getRuntimeService().createMessageCorrelation(messageName).processInstanceVariablesEqual(processInstanceKeys).localVariablesEqual(correlationKeys).setVariables(messagePayload).correlateWithResult();
    // then exactly one message is correlated = one receive task is passed by, two + three others continue waiting
    checkExecutionMessageCorrelationResult(messageCorrelationResult, processInstance, "MessageReceiver_1");
    // uncorrelated executions
    List<Execution> uncorrelatedExecutions = engineRule.getRuntimeService().createExecutionQuery().activityId("MessageReceiver_1").list();
    assertEquals(5, uncorrelatedExecutions.size());
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) MessageCorrelationResult(org.camunda.bpm.engine.runtime.MessageCorrelationResult) Test(org.junit.Test)

Example 39 with Execution

use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.

the class ModificationExecutionAsyncTest method testCancelWithFlagForManyInstances.

@Test
public void testCancelWithFlagForManyInstances() {
    // given
    this.instance = Bpmn.createExecutableProcess("process1").startEvent("start").serviceTask("ser").camundaExpression("${true}").userTask("user").endEvent("end").done();
    ProcessDefinition processDefinition = testRule.deployAndGetDefinition(instance);
    List<String> processInstanceIds = helper.startInstances("process1", 10);
    // when
    Batch batch = runtimeService.createModification(processDefinition.getId()).startBeforeActivity("ser").cancelAllForActivity("user", true).processInstanceIds(processInstanceIds).executeAsync();
    helper.executeSeedJob(batch);
    helper.executeJobs(batch);
    // then
    for (String processInstanceId : processInstanceIds) {
        Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstanceId).singleResult();
        assertNotNull(execution);
        assertEquals("user", ((ExecutionEntity) execution).getActivityId());
    }
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) Batch(org.camunda.bpm.engine.batch.Batch) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 40 with Execution

use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.

the class ProcessInstanceModificationAsyncTest method testStartAfterAsync.

/**
 * starting after a task should not respect that tasks asyncAfter setting
 */
@Deployment
public void testStartAfterAsync() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway");
    String processInstanceId = processInstance.getId();
    runtimeService.createProcessInstanceModification(processInstance.getId()).startAfterActivity("task2").execute();
    // there is now a job for the end event after task2
    Job job = managementService.createJobQuery().singleResult();
    assertNotNull(job);
    Execution jobExecution = runtimeService.createExecutionQuery().activityId("end2").executionId(job.getExecutionId()).singleResult();
    assertNotNull(jobExecution);
    // end process
    completeTasksInOrder("task1");
    managementService.executeJob(job.getId());
    assertProcessEnded(processInstanceId);
}
Also used : Execution(org.camunda.bpm.engine.runtime.Execution) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Job(org.camunda.bpm.engine.runtime.Job) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

Execution (org.camunda.bpm.engine.runtime.Execution)279 Deployment (org.camunda.bpm.engine.test.Deployment)188 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)143 Task (org.camunda.bpm.engine.task.Task)99 Test (org.junit.Test)95 HashMap (java.util.HashMap)45 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)33 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)23 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)22 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)20 ThrowErrorDelegate.leaveExecution (org.camunda.bpm.engine.test.bpmn.event.error.ThrowErrorDelegate.leaveExecution)18 ExecutionQuery (org.camunda.bpm.engine.runtime.ExecutionQuery)17 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)15 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)14 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)14 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)14 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)14 DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)13 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)12 ArrayList (java.util.ArrayList)11