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()); }
public WorkflowInstanceRecordStream limitToWorkflowInstanceCompleted() { return limit( r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.ELEMENT_COMPLETED && r.getKey() == r.getValue().getWorkflowInstanceKey()); }
public WorkflowInstanceRecordStream limitToWorkflowInstanceCompleted() { return limit( r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.ELEMENT_COMPLETED && r.getKey() == r.getValue().getWorkflowInstanceKey()); }
@Test public void shouldCreateMultipleWorkflowInstancesWithRepeatingTimer() { // when testClient.deployWithResponse(THREE_SEC_MODEL); // then assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).exists()).isTrue(); brokerRule.getClock().addTime(Duration.ofSeconds(3)); assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).exists()).isTrue(); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATING) .withElementId("process_3") .exists()) .isTrue(); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).count()).isEqualTo(2); brokerRule.getClock().addTime(Duration.ofSeconds(3)); assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).limit(2).count()).isEqualTo(2); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATING) .withElementId("process_3") .limit(2) .count()) .isEqualTo(2); }
@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 shouldTakeAllOutgoingSequenceFlowsIfTriggered() { // given testClient.deploy(MULTIPLE_SEQUENCE_FLOWS); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.receiveTimerRecord("timer", TimerIntent.CREATED); brokerRule.getClock().addTime(Duration.ofMinutes(1)); awaitProcessCompleted(); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_ACTIVATED) .limit(2)) .extracting(Record::getValue) .extracting(WorkflowInstanceRecordValue::getElementId) .contains("end1", "end2"); }
@Test public void shouldTakeAllOutgoingSequenceFlowsIfTriggered() { // given testClient.deploy(MULTIPLE_SEQUENCE_FLOWS); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.receiveTimerRecord("timer", TimerIntent.CREATED); brokerRule.getClock().addTime(Duration.ofMinutes(1)); awaitProcessCompleted(); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementType(BpmnElementType.END_EVENT) .limit(2)) .extracting(Record::getValue) .extracting(WorkflowInstanceRecordValue::getElementId) .contains("end1", "end2"); }
@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 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 shouldCorrelateOnlyOneMessagePerCatchElement() { // given testClient.deploy(TWO_MESSAGES_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .exists()) .isTrue(); // when testClient.publishMessage("ping", "123", asMsgPack("nr", 1)); testClient.publishMessage("ping", "123", asMsgPack("nr", 2)); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .filter(r -> r.getValue().getElementId().startsWith("message")) .limit(2) .asList()) .extracting( r -> tuple(r.getValue().getElementId(), r.getValue().getPayloadAsMap().get("nr"))) .contains(tuple("message1", 1), tuple("message2", 2)); }
@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 shouldCorrelateMessageOnlyOnceIfPublishedBefore() { // given testClient.deploy(TWO_MESSAGES_WORKFLOW); testClient.publishMessage("ping", "123", asMsgPack("nr", 1)); testClient.publishMessage("ping", "123", asMsgPack("nr", 2)); // when testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_TRIGGERED) .filter(r -> r.getValue().getElementId().startsWith("message")) .limit(2) .asList()) .extracting( r -> tuple(r.getValue().getElementId(), r.getValue().getPayloadAsMap().get("nr"))) .contains(tuple("message1", 1), tuple("message2", 2)); }
@Test public void shouldCorrelateMessageOnlyOnceIfPublishedBefore() { // given testClient.deploy(TWO_MESSAGES_WORKFLOW); testClient.publishMessage("ping", "123", asMsgPack("nr", 1)); testClient.publishMessage("ping", "123", asMsgPack("nr", 2)); // when testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .filter(r -> r.getValue().getElementId().startsWith("message")) .limit(2) .asList()) .extracting( r -> tuple(r.getValue().getElementId(), r.getValue().getPayloadAsMap().get("nr"))) .contains(tuple("message1", 1), tuple("message2", 2)); }
@Test public void shouldCompleteScopeOnParallelGateway() { // given final BpmnModelInstance process = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent("start") .sequenceFlowId("flow1") .parallelGateway("fork") .done(); testClient.deploy(process); // when testClient.createWorkflowInstance(PROCESS_ID); // then final Record<WorkflowInstanceRecordValue> completedEvent = testClient.receiveElementInState(PROCESS_ID, WorkflowInstanceIntent.ELEMENT_COMPLETED); final List<Record<WorkflowInstanceRecordValue>> workflowInstanceEvents = testClient .receiveWorkflowInstances() .limit(r -> r.getPosition() == completedEvent.getPosition()) .collect(Collectors.toList()); assertThat(workflowInstanceEvents) .extracting(e -> e.getValue().getElementId(), e -> e.getMetadata().getIntent()) .containsSequence( tuple("fork", WorkflowInstanceIntent.GATEWAY_ACTIVATED), tuple(PROCESS_ID, WorkflowInstanceIntent.ELEMENT_COMPLETING)); }
@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)); }