@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 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 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 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 shouldCorrelateCorrectBoundaryEvent() { // given testClient.deploy(BOUNDARY_EVENTS_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); // when awaitSubscriptionsOpened(3); testClient.publishMessage("msg1", "123", asMsgPack("foo", 1)); // then assertThat(RecordingExporter.workflowInstanceRecords().limitToWorkflowInstanceCompleted()) .filteredOn(r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.EVENT_ACTIVATED) .extracting(Record::getValue) .extracting(WorkflowInstanceRecordValue::getElementId) .contains("msg1End") .doesNotContain("taskEnd", "msg2End"); }
@Test public void shouldNotTriggerBoundaryEventIfReceiveTaskTriggeredFirst() { // given testClient.deploy(BOUNDARY_EVENTS_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); // when awaitSubscriptionsOpened(3); testClient.publishMessage("taskMsg", "123", asMsgPack("foo", 1)); // then assertThat(RecordingExporter.workflowInstanceRecords().limitToWorkflowInstanceCompleted()) .filteredOn(r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.EVENT_ACTIVATED) .extracting(Record::getValue) .extracting(WorkflowInstanceRecordValue::getElementId) .contains("taskEnd") .doesNotContain("msg1End", "msg2End"); }
@Test public void shouldCorrelateCorrectBoundaryEvent() { // given testClient.deploy(BOUNDARY_EVENTS_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); // when awaitSubscriptionsOpened(3); testClient.publishMessage("msg1", "123", asMsgPack("foo", 1)); // then assertThat(RecordingExporter.workflowInstanceRecords().limitToWorkflowInstanceCompleted()) .filteredOn(r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.ELEMENT_ACTIVATED) .extracting(Record::getValue) .extracting(WorkflowInstanceRecordValue::getElementId) .contains("msg1End") .doesNotContain("taskEnd", "msg2End"); }
@Test public void shouldNotTriggerReceiveTaskIfBoundaryEventTriggeredFirst() { // given testClient.deploy(BOUNDARY_EVENTS_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); // when awaitSubscriptionsOpened(3); // await both subscriptions opened testClient.publishMessage("msg2", "123", asMsgPack("foo", 1)); // then assertThat(RecordingExporter.workflowInstanceRecords().limitToWorkflowInstanceCompleted()) .filteredOn(r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.EVENT_ACTIVATED) .extracting(Record::getValue) .extracting(WorkflowInstanceRecordValue::getElementId) .contains("msg2End") .doesNotContain("taskEnd", "msg1End"); }
@Test public void shouldNotTriggerBoundaryEventIfReceiveTaskTriggeredFirst() { // given testClient.deploy(BOUNDARY_EVENTS_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); // when awaitSubscriptionsOpened(3); testClient.publishMessage("taskMsg", "123", asMsgPack("foo", 1)); // then assertThat(RecordingExporter.workflowInstanceRecords().limitToWorkflowInstanceCompleted()) .filteredOn(r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.ELEMENT_ACTIVATED) .extracting(Record::getValue) .extracting(WorkflowInstanceRecordValue::getElementId) .contains("taskEnd") .doesNotContain("msg1End", "msg2End"); }
@Test public void shouldNotTriggerReceiveTaskIfBoundaryEventTriggeredFirst() { // given testClient.deploy(BOUNDARY_EVENTS_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); // when awaitSubscriptionsOpened(3); // await both subscriptions opened testClient.publishMessage("msg2", "123", asMsgPack("foo", 1)); // then assertThat(RecordingExporter.workflowInstanceRecords().limitToWorkflowInstanceCompleted()) .filteredOn(r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.ELEMENT_ACTIVATED) .extracting(Record::getValue) .extracting(WorkflowInstanceRecordValue::getElementId) .contains("msg2End") .doesNotContain("taskEnd", "msg1End"); }
@Test public void shouldOccurEndEvent() { // given testClient.deploy(Bpmn.createExecutableProcess(PROCESS_ID).startEvent().endEvent("foo").done()); // when final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); // then assertThat( RecordingExporter.workflowInstanceRecords() .limitToWorkflowInstanceCompleted() .withElementId("foo")) .extracting(r -> r.getMetadata().getIntent()) .containsExactly( WorkflowInstanceIntent.EVENT_ACTIVATING, WorkflowInstanceIntent.EVENT_ACTIVATED); assertWorkflowInstanceRecord( workflowInstanceKey, "foo", testClient.receiveFirstWorkflowInstanceEvent(WorkflowInstanceIntent.EVENT_ACTIVATED)); }
@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 test() { // given testClient.deploy(scenario.modelInstance()); // when scenario.executeInstance(); // then final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords() .withBpmnProcessId(scenario.processId()) .limitToWorkflowInstanceCompleted() .withElementId(scenario.elementId()) .asList(); assertThat(records) .extracting(r -> r.getValue().getBpmnElementType()) .isNotEmpty() .containsOnly(scenario.elementType()); }
@Test public void test() { // given testClient.deploy(scenario.modelInstance()); // when scenario.executeInstance(); // then final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords() .withBpmnProcessId(scenario.processId()) .limitToWorkflowInstanceCompleted() .withElementId(scenario.elementId()) .asList(); assertThat(records) .extracting(r -> r.getValue().getBpmnElementType()) .isNotEmpty() .containsOnly(scenario.elementType()); }
@Test public void shouldOccurEndEvent() { // given testClient.deploy(Bpmn.createExecutableProcess(PROCESS_ID).startEvent().endEvent("foo").done()); // when final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); // then assertThat( RecordingExporter.workflowInstanceRecords() .limitToWorkflowInstanceCompleted() .withElementId("foo")) .extracting(r -> r.getMetadata().getIntent()) .containsExactly( WorkflowInstanceIntent.ELEMENT_ACTIVATING, WorkflowInstanceIntent.ELEMENT_ACTIVATED, WorkflowInstanceIntent.ELEMENT_COMPLETING, WorkflowInstanceIntent.ELEMENT_COMPLETED); assertWorkflowInstanceRecord( workflowInstanceKey, "foo", testClient.receiveFirstWorkflowInstanceEvent( WorkflowInstanceIntent.ELEMENT_COMPLETED, BpmnElementType.END_EVENT)); }
@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 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.ELEMENT_COMPLETED) .withElementType(BpmnElementType.END_EVENT) .collect(Collectors.toList()); assertThat(completedEvents).extracting(r -> r.getValue().getElementId()).containsExactly("a"); }
@Test public void testLifecycle() { // given testClient.deploy(WORKFLOW_WITH_TIMERS); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).exists()); // when brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then assertThat( RecordingExporter.workflowInstanceRecords() .skipUntil( r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.GATEWAY_ACTIVATED) .limitToWorkflowInstanceCompleted()) .extracting(r -> tuple(r.getValue().getElementId(), r.getMetadata().getIntent())) .containsExactly( tuple("gateway", WorkflowInstanceIntent.GATEWAY_ACTIVATED), tuple("timer-1", WorkflowInstanceIntent.EVENT_OCCURRED), tuple("timer-1", WorkflowInstanceIntent.EVENT_TRIGGERING), tuple("timer-1", WorkflowInstanceIntent.EVENT_TRIGGERED), tuple("to-end1", WorkflowInstanceIntent.SEQUENCE_FLOW_TAKEN), tuple("end1", WorkflowInstanceIntent.EVENT_ACTIVATING), tuple("end1", WorkflowInstanceIntent.EVENT_ACTIVATED), tuple(PROCESS_ID, WorkflowInstanceIntent.ELEMENT_COMPLETING), tuple(PROCESS_ID, WorkflowInstanceIntent.ELEMENT_COMPLETED)); }