public List<Record<WorkflowInstanceRecordValue>> receiveElementInstancesInState( Intent intent, int expectedNumber) { return receiveWorkflowInstances() .withIntent(intent) .limit(expectedNumber) .collect(Collectors.toList()); }
public List<Record<WorkflowInstanceRecordValue>> receiveElementInstancesInState( Intent intent, int expectedNumber) { return receiveWorkflowInstances() .withIntent(intent) .limit(expectedNumber) .collect(Collectors.toList()); }
public List<Record<WorkflowInstanceRecordValue>> receiveElementInstancesInState( Intent intent, BpmnElementType elementType, int expectedNumber) { return receiveWorkflowInstances() .withIntent(intent) .withElementType(elementType) .limit(expectedNumber) .collect(Collectors.toList()); }
@Test public void shouldActivateTasksOnParallelBranches() { // given testClient.deploy(FORK_PROCESS); // when testClient.createWorkflowInstance(PROCESS_ID); // then final List<Record<WorkflowInstanceRecordValue>> taskEvents = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .filter(e -> isServiceTaskInProcess(e.getValue().getElementId(), FORK_PROCESS)) .limit(2) .collect(Collectors.toList()); assertThat(taskEvents).hasSize(2); assertThat(taskEvents) .extracting(e -> e.getValue().getElementId()) .containsExactlyInAnyOrder("task1", "task2"); assertThat(taskEvents.get(0).getKey()).isNotEqualTo(taskEvents.get(1).getKey()); }
@Test public void shouldActivateTasksOnParallelBranches() { // given testClient.deploy(FORK_PROCESS); // when testClient.createWorkflowInstance(PROCESS_ID); // then final List<Record<WorkflowInstanceRecordValue>> taskEvents = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .filter(e -> isServiceTaskInProcess(e.getValue().getElementId(), FORK_PROCESS)) .limit(2) .collect(Collectors.toList()); assertThat(taskEvents).hasSize(2); assertThat(taskEvents) .extracting(e -> e.getValue().getElementId()) .containsExactlyInAnyOrder("task1", "task2"); assertThat(taskEvents.get(0).getKey()).isNotEqualTo(taskEvents.get(1).getKey()); }
@Test public void testIntermediateMessageEventLifeCycle() { // given testClient.deploy(SINGLE_MESSAGE_WORKFLOW); testClient.publishMessage("message", "order-123"); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); final List<Record<WorkflowInstanceRecordValue>> events = testClient .receiveWorkflowInstances() .limitToWorkflowInstanceCompleted() .collect(Collectors.toList()); assertThat(events) .filteredOn(r -> r.getValue().getElementId().equals("receive-message")) .extracting(Record::getMetadata) .extracting(RecordMetadata::getIntent) .containsExactly( WorkflowInstanceIntent.EVENT_ACTIVATING, WorkflowInstanceIntent.EVENT_ACTIVATED, WorkflowInstanceIntent.EVENT_OCCURRED, WorkflowInstanceIntent.EVENT_TRIGGERING, WorkflowInstanceIntent.EVENT_TRIGGERED); }
@Test public void testReceiveTaskLifeCycle() { // given testClient.deploy(RECEIVE_TASK_WORKFLOW); testClient.publishMessage("message", "order-123"); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); final List<Record<WorkflowInstanceRecordValue>> events = testClient .receiveWorkflowInstances() .limitToWorkflowInstanceCompleted() .collect(Collectors.toList()); assertThat(events) .filteredOn(r -> r.getValue().getElementId().equals("receive-message")) .extracting(Record::getMetadata) .extracting(RecordMetadata::getIntent) .containsExactly( WorkflowInstanceIntent.ELEMENT_READY, WorkflowInstanceIntent.ELEMENT_ACTIVATED, WorkflowInstanceIntent.EVENT_OCCURRED, WorkflowInstanceIntent.ELEMENT_COMPLETING, WorkflowInstanceIntent.ELEMENT_COMPLETED); }
@Test public void testIntermediateMessageEventLifeCycle() { // given testClient.deploy(SINGLE_MESSAGE_WORKFLOW); testClient.publishMessage("message", "order-123"); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); final List<Record<WorkflowInstanceRecordValue>> events = testClient .receiveWorkflowInstances() .limitToWorkflowInstanceCompleted() .collect(Collectors.toList()); assertThat(events) .filteredOn(r -> r.getValue().getElementId().equals("receive-message")) .extracting(Record::getMetadata) .extracting(RecordMetadata::getIntent) .containsExactly( WorkflowInstanceIntent.ELEMENT_ACTIVATING, WorkflowInstanceIntent.ELEMENT_ACTIVATED, WorkflowInstanceIntent.EVENT_OCCURRED, WorkflowInstanceIntent.ELEMENT_COMPLETING, WorkflowInstanceIntent.ELEMENT_COMPLETED); }
@Test public void testReceiveTaskLifeCycle() { // given testClient.deploy(RECEIVE_TASK_WORKFLOW); testClient.publishMessage("message", "order-123"); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); final List<Record<WorkflowInstanceRecordValue>> events = testClient .receiveWorkflowInstances() .limitToWorkflowInstanceCompleted() .collect(Collectors.toList()); assertThat(events) .filteredOn(r -> r.getValue().getElementId().equals("receive-message")) .extracting(Record::getMetadata) .extracting(RecordMetadata::getIntent) .containsExactly( WorkflowInstanceIntent.ELEMENT_ACTIVATING, WorkflowInstanceIntent.ELEMENT_ACTIVATED, WorkflowInstanceIntent.EVENT_OCCURRED, WorkflowInstanceIntent.ELEMENT_COMPLETING, WorkflowInstanceIntent.ELEMENT_COMPLETED); }
@Test public void shouldPropagatePayloadOnSplit() { // given testClient.deploy(FORK_PROCESS); final byte[] payload = BufferUtil.bufferAsArray(MsgPackUtil.asMsgPack("key", "val")); // when testClient.createWorkflowInstance(PROCESS_ID, payload); // then final List<Record<WorkflowInstanceRecordValue>> taskEvents = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .filter(e -> isServiceTaskInProcess(e.getValue().getElementId(), FORK_PROCESS)) .limit(2) .collect(Collectors.toList()); assertThat(taskEvents) .extracting(e -> MsgPackUtil.asMsgPackReturnArray(e.getValue().getPayload())) .allSatisfy(p -> p.equals(payload)); }
@Test public void shouldPropagatePayloadOnSplit() { // given testClient.deploy(FORK_PROCESS); final byte[] payload = BufferUtil.bufferAsArray(MsgPackUtil.asMsgPack("key", "val")); // when testClient.createWorkflowInstance(PROCESS_ID, payload); // then final List<Record<WorkflowInstanceRecordValue>> taskEvents = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .filter(e -> isServiceTaskInProcess(e.getValue().getElementId(), FORK_PROCESS)) .limit(2) .collect(Collectors.toList()); assertThat(taskEvents) .extracting(e -> MsgPackUtil.asMsgPackReturnArray(e.getValue().getPayload())) .allSatisfy(p -> p.equals(payload)); }
@Test public void shouldEndScopeIfGatewayHasNoOutgoingFlows() { final BpmnModelInstance workflowDefinition = Bpmn.createExecutableProcess("workflow").startEvent().exclusiveGateway("xor").done(); testClient.deploy(workflowDefinition); // when testClient.createWorkflowInstance("workflow", MsgPackUtil.asMsgPack("foo", 10)); // then final List<Record<WorkflowInstanceRecordValue>> completedEvents = RecordingExporter.workflowInstanceRecords() .onlyEvents() .skipUntil(r -> r.getValue().getElementId().equals("xor")) .limitToWorkflowInstanceCompleted() .collect(Collectors.toList()); assertThat(completedEvents) .extracting(r -> r.getMetadata().getIntent()) .containsExactly( WorkflowInstanceIntent.GATEWAY_ACTIVATED, WorkflowInstanceIntent.ELEMENT_COMPLETING, WorkflowInstanceIntent.ELEMENT_COMPLETED); } }
@Test public void shouldCreateMultipleWorkflowInstancesForDifferentBpmnProcessIds() { // given testClient.deploy(Bpmn.createExecutableProcess("foo").startEvent().endEvent().done()); testClient.deploy(Bpmn.createExecutableProcess("bar").startEvent().endEvent().done()); // when final long workflowInstanceKeyFoo = testClient.createWorkflowInstance("foo"); final long workflowInstanceKeyBar = testClient.createWorkflowInstance("bar"); // then final List<Record<WorkflowInstanceRecordValue>> workflowInstanceEvents = testClient .receiveWorkflowInstances() .filterRootScope() .withIntent(WorkflowInstanceIntent.ELEMENT_READY) .limit(2) .collect(Collectors.toList()); assertWorkflowInstanceRecord( "foo", 1, workflowInstanceKeyFoo, "foo", workflowInstanceEvents.get(0)); assertWorkflowInstanceRecord( "bar", 1, workflowInstanceKeyBar, "bar", workflowInstanceEvents.get(1)); }
@Test public void shouldCorrelateMessageToAllSubscriptions() { // given testClient.deploy(SINGLE_MESSAGE_WORKFLOW); final long workflowInstanceKey1 = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); final long workflowInstanceKey2 = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); // when testClient.publishMessage("message", "order-123"); // then final List<Record<WorkflowInstanceRecordValue>> events = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.EVENT_TRIGGERED) .withElementId("receive-message") .limit(2) .collect(Collectors.toList()); assertThat(events) .extracting(r -> r.getValue().getWorkflowInstanceKey()) .contains(workflowInstanceKey1, workflowInstanceKey2); }
@Test public void shouldCreateMultipleWorkflowInstancesForDifferentBpmnProcessIds() { // given testClient.deploy(Bpmn.createExecutableProcess("foo").startEvent().endEvent().done()); testClient.deploy(Bpmn.createExecutableProcess("bar").startEvent().endEvent().done()); // when final long workflowInstanceKeyFoo = testClient.createWorkflowInstance("foo"); final long workflowInstanceKeyBar = testClient.createWorkflowInstance("bar"); // then final List<Record<WorkflowInstanceRecordValue>> workflowInstanceEvents = testClient .receiveWorkflowInstances() .filterRootScope() .withIntent(WorkflowInstanceIntent.ELEMENT_ACTIVATING) .limit(2) .collect(Collectors.toList()); assertWorkflowInstanceRecord( "foo", 1, workflowInstanceKeyFoo, "foo", workflowInstanceEvents.get(0)); assertWorkflowInstanceRecord( "bar", 1, workflowInstanceKeyBar, "bar", workflowInstanceEvents.get(1)); }
@Test public void shouldCorrelateMessageToAllSubscriptions() { // given testClient.deploy(SINGLE_MESSAGE_WORKFLOW); final long workflowInstanceKey1 = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); final long workflowInstanceKey2 = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); // when testClient.publishMessage("message", "order-123"); // then final List<Record<WorkflowInstanceRecordValue>> events = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId("receive-message") .limit(2) .collect(Collectors.toList()); assertThat(events) .extracting(r -> r.getValue().getWorkflowInstanceKey()) .contains(workflowInstanceKey1, workflowInstanceKey2); }
@Test public void shouldMergeParallelBranches() { // given testClient.deploy(FORK_JOIN_PROCESS); // when testClient.createWorkflowInstance(PROCESS_ID); // then final List<Record<WorkflowInstanceRecordValue>> events = testClient .receiveWorkflowInstances() .limitToWorkflowInstanceCompleted() .collect(Collectors.toList()); assertThat(events) .extracting(e -> e.getValue().getElementId(), e -> e.getMetadata().getIntent()) .containsSubsequence( tuple("flow1", WorkflowInstanceIntent.SEQUENCE_FLOW_TAKEN), tuple("join", WorkflowInstanceIntent.ELEMENT_ACTIVATING)) .containsSubsequence( tuple("flow2", WorkflowInstanceIntent.SEQUENCE_FLOW_TAKEN), tuple("join", WorkflowInstanceIntent.ELEMENT_ACTIVATING)) .containsOnlyOnce(tuple("join", WorkflowInstanceIntent.ELEMENT_ACTIVATING)); }
@Test public void shouldSplitIfDefaultFlowIsDeclaredFirst() { final BpmnModelInstance workflowDefinition = Bpmn.createExecutableProcess("workflow") .startEvent() .exclusiveGateway() .defaultFlow() .endEvent("a") .moveToLastExclusiveGateway() .condition("$.foo < 5") .endEvent("b") .done(); testClient.deploy(workflowDefinition); // when testClient.createWorkflowInstance("workflow", MsgPackUtil.asMsgPack("foo", 10)); // then final List<Record<WorkflowInstanceRecordValue>> completedEvents = RecordingExporter.workflowInstanceRecords() .limitToWorkflowInstanceCompleted() .withIntent(WorkflowInstanceIntent.EVENT_ACTIVATED) .collect(Collectors.toList()); assertThat(completedEvents).extracting(r -> r.getValue().getElementId()).containsExactly("a"); }
@Test public void testBoundaryMessageEventLifecycle() { // given testClient.deploy(BOUNDARY_EVENTS_WORKFLOW); testClient.publishMessage("msg1", "order-123"); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); final List<Record<WorkflowInstanceRecordValue>> events = testClient .receiveWorkflowInstances() .limitToWorkflowInstanceCompleted() .collect(Collectors.toList()); assertThat(events) .extracting(r -> tuple(r.getValue().getElementId(), r.getMetadata().getIntent())) .containsSequence( tuple("task", WorkflowInstanceIntent.ELEMENT_READY), tuple("task", WorkflowInstanceIntent.ELEMENT_ACTIVATED), tuple("msg1", WorkflowInstanceIntent.EVENT_OCCURRED), tuple("task", WorkflowInstanceIntent.ELEMENT_TERMINATING), tuple("task", WorkflowInstanceIntent.ELEMENT_TERMINATED), tuple("msg1", WorkflowInstanceIntent.EVENT_TRIGGERING), tuple("msg1", WorkflowInstanceIntent.EVENT_TRIGGERED)); }
@Test public void shouldMergeParallelBranches() { // given testClient.deploy(FORK_JOIN_PROCESS); // when final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); // then final List<Record<WorkflowInstanceRecordValue>> events = testClient .receiveWorkflowInstances() .limit( r -> r.getKey() == workflowInstanceKey && WorkflowInstanceIntent.ELEMENT_COMPLETED == r.getMetadata().getIntent()) .collect(Collectors.toList()); assertThat(events) .extracting(e -> e.getValue().getElementId(), e -> e.getMetadata().getIntent()) .containsSubsequence( tuple("flow1", WorkflowInstanceIntent.SEQUENCE_FLOW_TAKEN), tuple("join", WorkflowInstanceIntent.GATEWAY_ACTIVATED)) .containsSubsequence( tuple("flow2", WorkflowInstanceIntent.SEQUENCE_FLOW_TAKEN), tuple("join", WorkflowInstanceIntent.GATEWAY_ACTIVATED)) .containsOnlyOnce(tuple("join", WorkflowInstanceIntent.GATEWAY_ACTIVATED)); }