use of org.camunda.bpm.engine.runtime.EventSubscription in project camunda-bpm-platform by camunda.
the class MessageBoundaryEventTest method testBoundaryMessageEventConcurrent.
/**
* Triggering one boundary event should not remove the event subscription
* of a boundary event for a concurrent task
*/
@Deployment
public void testBoundaryMessageEventConcurrent() {
runtimeService.startProcessInstanceByKey("boundaryEvent");
EventSubscription eventSubscriptionTask1 = runtimeService.createEventSubscriptionQuery().activityId("messageBoundary1").singleResult();
assertNotNull(eventSubscriptionTask1);
EventSubscription eventSubscriptionTask2 = runtimeService.createEventSubscriptionQuery().activityId("messageBoundary2").singleResult();
assertNotNull(eventSubscriptionTask2);
// when I trigger the boundary event for task1
runtimeService.correlateMessage("task1Message");
// then the event subscription for task2 still exists
assertEquals(1, runtimeService.createEventSubscriptionQuery().count());
assertNotNull(runtimeService.createEventSubscriptionQuery().activityId("messageBoundary2").singleResult());
}
use of org.camunda.bpm.engine.runtime.EventSubscription in project camunda-bpm-platform by camunda.
the class MessageIntermediateEventTest method testSetSerializedVariableValues.
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/message/MessageIntermediateEventTest.testSingleIntermediateMessageEvent.bpmn20.xml")
@Test
public void testSetSerializedVariableValues() throws IOException, ClassNotFoundException {
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
EventSubscription messageEventSubscription = runtimeService.createEventSubscriptionQuery().singleResult();
// when
FailingJavaSerializable javaSerializable = new FailingJavaSerializable("foo");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(javaSerializable);
String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine());
// then it is not possible to deserialize the object
try {
new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
} catch (RuntimeException e) {
testRule.assertTextPresent("Exception while deserializing object.", e.getMessage());
}
// but it can be set as a variable when delivering a message:
runtimeService.messageEventReceived("newInvoiceMessage", messageEventSubscription.getExecutionId(), Variables.createVariables().putValueTyped("var", Variables.serializedObjectValue(serializedObject).objectTypeName(FailingJavaSerializable.class.getName()).serializationDataFormat(SerializationDataFormats.JAVA).create()));
// then
ObjectValue variableTyped = runtimeService.getVariableTyped(processInstance.getId(), "var", false);
assertNotNull(variableTyped);
assertFalse(variableTyped.isDeserialized());
assertEquals(serializedObject, variableTyped.getValueSerialized());
assertEquals(FailingJavaSerializable.class.getName(), variableTyped.getObjectTypeName());
assertEquals(SerializationDataFormats.JAVA.getName(), variableTyped.getSerializationDataFormat());
}
use of org.camunda.bpm.engine.runtime.EventSubscription in project camunda-bpm-platform by camunda.
the class ReceiveTaskTest method testSupportsCorrelateMessageByBusinessKeyOnSingleReceiveTask.
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.singleReceiveTask.bpmn20.xml")
public void testSupportsCorrelateMessageByBusinessKeyOnSingleReceiveTask() {
// given: a process instance with business key 23 waiting in the receive task
ProcessInstance processInstance23 = runtimeService.startProcessInstanceByKey("testProcess", "23");
// given: a 2nd process instance with business key 42 waiting in the receive task
ProcessInstance processInstance42 = runtimeService.startProcessInstanceByKey("testProcess", "42");
// expect: there is two message event subscriptions for the tasks
List<EventSubscription> subscriptionList = getEventSubscriptionList();
assertEquals(2, subscriptionList.size());
// then: we can correlate the event subscription to one of the process instances
runtimeService.correlateMessage("newInvoiceMessage", "23");
// expect: one subscription is removed
assertEquals(1, getEventSubscriptionList().size());
// expect: this ends the process instance with business key 23
assertProcessEnded(processInstance23.getId());
// expect: other process instance is still running
assertEquals(1, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance42.getId()).count());
// then: we can correlate the event subscription to the other process instance
runtimeService.correlateMessage("newInvoiceMessage", "42");
// expect: subscription is removed
assertEquals(0, getEventSubscriptionList().size());
// expect: this ends the process instance
assertProcessEnded(processInstance42.getId());
}
use of org.camunda.bpm.engine.runtime.EventSubscription in project camunda-bpm-platform by camunda.
the class ReceiveTaskTest method testSupportsMessageEventReceivedOnParallelMultiReceiveTaskWithCompensation.
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.multiParallelReceiveTaskCompensate.bpmn20.xml")
public void testSupportsMessageEventReceivedOnParallelMultiReceiveTaskWithCompensation() {
// 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 the first event subscription
runtimeService.messageEventReceived(subscriptions.get(0).getEventName(), subscriptions.get(0).getExecutionId());
// expect: after completing the first receive task there is one event subscription for compensation
assertEquals(1, runtimeService.createEventSubscriptionQuery().eventType(EventType.COMPENSATE.name()).count());
// then: we can trigger the second event subscription
runtimeService.messageEventReceived(subscriptions.get(1).getEventName(), subscriptions.get(1).getExecutionId());
// expect: there are three event subscriptions for compensation (two subscriptions for tasks and one for miBody)
assertEquals(3, runtimeService.createEventSubscriptionQuery().eventType(EventType.COMPENSATE.name()).count());
// 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 testSupportsCorrelateMessageOnSingleReceiveTask.
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/receivetask/ReceiveTaskTest.singleReceiveTask.bpmn20.xml")
public void testSupportsCorrelateMessageOnSingleReceiveTask() {
// given: a process instance waiting in the receive task
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
// expect: there is a message event subscription for the task
List<EventSubscription> subscriptionList = getEventSubscriptionList();
assertEquals(1, subscriptionList.size());
EventSubscription subscription = subscriptionList.get(0);
// then: we can correlate the event subscription
runtimeService.correlateMessage(subscription.getEventName());
// expect: subscription is removed
assertEquals(0, getEventSubscriptionList().size());
// expect: this ends the process instance
assertProcessEnded(processInstance.getId());
}
Aggregations