use of org.camunda.bpm.engine.runtime.EventSubscription in project camunda-bpm-platform by camunda.
the class TransactionSubProcessTest method testMultiInstanceTxSuccessful.
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/subprocess/transaction/TransactionSubProcessTest.testMultiInstanceTx.bpmn20.xml" })
public void testMultiInstanceTxSuccessful() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("transactionProcess");
// there are now 5 instances of the transaction:
List<EventSubscription> eventSubscriptions = runtimeService.createEventSubscriptionQuery().eventType("compensate").list();
// there are 10 compensation event subscriptions
assertEquals(10, eventSubscriptions.size());
// first complete the inner user-tasks
List<Task> tasks = taskService.createTaskQuery().list();
for (Task task : tasks) {
taskService.setVariable(task.getId(), "confirmed", true);
taskService.complete(task.getId());
}
// now complete the inner receive tasks
List<Execution> executions = runtimeService.createExecutionQuery().activityId("receive").list();
for (Execution execution : executions) {
runtimeService.signal(execution.getId());
}
runtimeService.signal(runtimeService.createExecutionQuery().activityId("afterSuccess").singleResult().getId());
assertEquals(0, runtimeService.createEventSubscriptionQuery().count());
assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.runtime.EventSubscription in project camunda-bpm-platform by camunda.
the class TransactionSubProcessTest method testMultiInstanceTx.
/*
* The cancel end event cancels all instances, compensation is performed for all instances
*
* see spec page 470:
* "If the cancelActivity attribute is set, the Activity the Event is attached to is then
* cancelled (in case of a multi-instance, all its instances are cancelled);"
*/
@Deployment
public void testMultiInstanceTx() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("transactionProcess");
// there are now 5 instances of the transaction:
List<EventSubscription> eventSubscriptions = runtimeService.createEventSubscriptionQuery().eventType("compensate").list();
// there are 10 compensation event subscriptions
assertEquals(10, eventSubscriptions.size());
Task task = taskService.createTaskQuery().listPage(0, 1).get(0);
// canceling one instance triggers compensation for all other instances:
taskService.setVariable(task.getId(), "confirmed", false);
taskService.complete(task.getId());
assertEquals(0, runtimeService.createEventSubscriptionQuery().count());
assertEquals(1, runtimeService.getVariable(processInstance.getId(), "undoBookHotel"));
assertEquals(1, runtimeService.getVariable(processInstance.getId(), "undoBookFlight"));
runtimeService.signal(runtimeService.createExecutionQuery().activityId("afterCancellation").singleResult().getId());
assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.runtime.EventSubscription in project camunda-bpm-platform by camunda.
the class ReceiveTaskTest method testSupportsCorrelateMessageOnSequentialMultiReceiveTask.
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.multiSequentialReceiveTask.bpmn20.xml")
public void testSupportsCorrelateMessageOnSequentialMultiReceiveTask() {
// given: a process instance waiting in the first receive tasks
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
// expect: there is a message event subscription for the first task
List<EventSubscription> subscriptionList = getEventSubscriptionList();
assertEquals(1, subscriptionList.size());
EventSubscription subscription = subscriptionList.get(0);
String firstSubscriptionId = subscription.getId();
// then: we can trigger the event subscription
runtimeService.correlateMessage(subscription.getEventName());
// expect: there is a new subscription created for the second receive task instance
subscriptionList = getEventSubscriptionList();
assertEquals(1, subscriptionList.size());
subscription = subscriptionList.get(0);
assertFalse(firstSubscriptionId.equals(subscription.getId()));
// then: we can trigger the second event subscription
runtimeService.correlateMessage(subscription.getEventName());
// expect: no event subscription left
assertEquals(0, getEventSubscriptionList().size());
// expect: one user task is created
Task task = taskService.createTaskQuery().singleResult();
taskService.complete(task.getId());
// expect: this ends the process instance
assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.runtime.EventSubscription in project camunda-bpm-platform by camunda.
the class ReceiveTaskTest method testSupportsMessageEventReceivedOnReceiveTaskBehindParallelGateway.
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.parallelGatewayReceiveTask.bpmn20.xml")
public void testSupportsMessageEventReceivedOnReceiveTaskBehindParallelGateway() {
// given: a process instance waiting in two receive tasks
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
// expect: there are two message event subscriptions
List<EventSubscription> subscriptions = getEventSubscriptionList();
assertEquals(2, subscriptions.size());
// then: we can trigger both receive task event subscriptions
runtimeService.messageEventReceived(subscriptions.get(0).getEventName(), subscriptions.get(0).getExecutionId());
runtimeService.messageEventReceived(subscriptions.get(1).getEventName(), subscriptions.get(1).getExecutionId());
// expect: subscriptions are removed
assertEquals(0, getEventSubscriptionList().size());
// expect: this ends the process instance
assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.runtime.EventSubscription in project camunda-bpm-platform by camunda.
the class ReceiveTaskTest method testSupportsCorrelateMessageOnReceiveTaskBehindParallelGateway.
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.parallelGatewayReceiveTask.bpmn20.xml")
public void testSupportsCorrelateMessageOnReceiveTaskBehindParallelGateway() {
// given: a process instance waiting in two receive tasks
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
// expect: there are two message event subscriptions
List<EventSubscription> subscriptions = getEventSubscriptionList();
assertEquals(2, subscriptions.size());
// then: we can trigger both receive task event subscriptions
runtimeService.correlateMessage(subscriptions.get(0).getEventName());
runtimeService.correlateMessage(subscriptions.get(1).getEventName());
// expect: subscriptions are removed
assertEquals(0, getEventSubscriptionList().size());
// expect: this ends the process instance
assertProcessEnded(processInstance.getId());
}
Aggregations