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);
}
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());
}
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());
}
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());
}
}
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);
}
Aggregations