private static Predicate<Record<WorkflowInstanceRecordValue>> elementId(List<String> elementIds) { return record -> { final String elementId = record.getValue().getElementId(); return elementIds.contains(elementId); }; } }
public WorkflowInstanceRecordStream withElementType(BpmnElementType elementType) { return valueFilter(v -> v.getBpmnElementType() == elementType); }
public WorkflowInstanceRecordStream withBpmnProcessId(final String bpmnProcessId) { return valueFilter(v -> bpmnProcessId.equals(v.getBpmnProcessId())); }
@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)); }
public WorkflowInstanceRecordStream withWorkflowInstanceKey(final long workflowInstanceKey) { return valueFilter(v -> v.getWorkflowInstanceKey() == workflowInstanceKey); }
r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.ELEMENT_ACTIVATED && r.getValue().getBpmnElementType() == BpmnElementType.SERVICE_TASK) .collect(Collectors.toList()); .extracting(e -> e.getValue().getElementId()) .contains("task1", "task2");
.limit(3)) .extracting(Record::getValue) .extracting(v -> tuple(v.getWorkflowInstanceKey(), v.getElementId())) .contains( tuple(workflowInstance1, "a"),
r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.ELEMENT_ACTIVATED && "subProcessTask".equals(r.getValue().getElementId())) .collect(Collectors.toList()); .extracting(e -> e.getMetadata().getIntent(), e -> e.getValue().getElementId()) .containsExactly( tuple(WorkflowInstanceIntent.CREATE, ""), .withIntent(WorkflowInstanceIntent.ELEMENT_READY) .getFirst(); assertThat(subProcessReady.getValue().getScopeInstanceKey()).isEqualTo(workflowInstanceKey); .withIntent(WorkflowInstanceIntent.ELEMENT_READY) .getFirst(); assertThat(subProcessTaskReady.getValue().getScopeInstanceKey()) .isEqualTo(subProcessReady.getKey());
@Test public void shouldCreateInstancesForMultipleMessagesOfSameName() { // given final ExecuteCommandResponse response = testClient.deployWithResponse(createWorkflowWithOneMessageStartEvent()); final long workflowKey = getFirstDeployedWorkflowKey(response); // wait until subscription is opened assertThat( messageStartEventSubscriptionRecords(MessageStartEventSubscriptionIntent.OPENED) .exists()) .isTrue(); // when testClient.publishMessage(MESSAGE_NAME1, "order-123", asMsgPack("foo", "bar")); testClient.publishMessage(MESSAGE_NAME1, "order-124", asMsgPack("foo", "bar")); // then // check if two instances are created final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_READY) .limit(2) .asList(); assertThat(records).allMatch(r -> r.getValue().getWorkflowKey() == workflowKey); final WorkflowInstanceRecordValue recordValue1 = records.get(0).getValue(); final WorkflowInstanceRecordValue recordValue2 = records.get(1).getValue(); assertThat(recordValue1.getWorkflowInstanceKey()) .isNotEqualTo(recordValue2.getWorkflowInstanceKey()); }
r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.ELEMENT_ACTIVATED && "subProcessTask".equals(r.getValue().getElementId())) .collect(Collectors.toList()); .extracting(e -> e.getMetadata().getIntent(), e -> e.getValue().getElementId()) .containsExactly( tuple(WorkflowInstanceIntent.CREATE, ""), .withIntent(WorkflowInstanceIntent.ELEMENT_ACTIVATING) .getFirst(); assertThat(subProcessReady.getValue().getFlowScopeKey()).isEqualTo(workflowInstanceKey); .withIntent(WorkflowInstanceIntent.ELEMENT_ACTIVATING) .getFirst(); assertThat(subProcessTaskReady.getValue().getFlowScopeKey()) .isEqualTo(subProcessReady.getKey());
public WorkflowInstanceRecordStream withWorkflowKey(final long workflowKey) { return valueFilter(v -> v.getWorkflowKey() == workflowKey); }
@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 shouldCreateInstanceOnMessage() { // given final ExecuteCommandResponse response = testClient.deployWithResponse(createWorkflowWithOneMessageStartEvent()); final long workflowKey = getFirstDeployedWorkflowKey(response); // wait until subscription is opened assertThat( messageStartEventSubscriptionRecords(MessageStartEventSubscriptionIntent.OPENED) .exists()) .isTrue(); // when testClient.publishMessage(MESSAGE_NAME1, "order-123", asMsgPack("foo", "bar")); // then final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords().limit(5).asList(); assertThat(records) .extracting(r -> r.getMetadata().getIntent()) .containsExactly( WorkflowInstanceIntent.EVENT_OCCURRED, // message WorkflowInstanceIntent.ELEMENT_READY, // workflow instance WorkflowInstanceIntent.ELEMENT_ACTIVATED, WorkflowInstanceIntent.EVENT_TRIGGERING, // start event WorkflowInstanceIntent.EVENT_TRIGGERED); assertThat(records).allMatch(r -> r.getValue().getWorkflowKey() == workflowKey); assertThat(records.get(3).getValue()).hasElementId(EVENT_ID1); final WorkflowInstanceRecordValue eventTriggeredRecord = records.get(4).getValue(); assertThat(eventTriggeredRecord.getPayloadAsMap()).containsEntry("foo", "bar"); }
private WorkflowInstanceAssert hasPayload( final Record<WorkflowInstanceRecordValue> record, String key, Object expectedValue) { final Map<String, Object> payload = record.getValue().getPayloadAsMap(); if (payload.containsKey(key)) { final Object value = payload.get(key); if (!expectedValue.equals(value)) { failWithMessage( "Expected payload value of <%s> to be <%s> but was <%s>", key, expectedValue, value); } } else { failWithMessage( "Expected payload <%s> to contain <%s> but could not find entry", payload, key); } return this; }
public WorkflowInstanceRecordStream withScopeInstanceKey(final long scopeInstanceKey) { return valueFilter(v -> v.getScopeInstanceKey() == scopeInstanceKey); }
public WorkflowInstanceRecordStream withVersion(final int version) { return valueFilter(v -> v.getVersion() == version); }
public WorkflowInstanceRecordStream withFlowScopeKey(final long flowScopeKey) { return valueFilter(v -> v.getFlowScopeKey() == flowScopeKey); }
@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)); }
public WorkflowInstanceRecordStream withWorkflowInstanceKey(final long workflowInstanceKey) { return valueFilter(v -> v.getWorkflowInstanceKey() == workflowInstanceKey); }
r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.ELEMENT_ACTIVATED && r.getValue().getBpmnElementType() == BpmnElementType.EVENT_BASED_GATEWAY) .limitToWorkflowInstanceCompleted()) .extracting(r -> tuple(r.getValue().getElementId(), r.getMetadata().getIntent())) .containsExactly( tuple("gateway", WorkflowInstanceIntent.ELEMENT_ACTIVATED),