private List<Record<WorkflowInstanceSubscriptionRecordValue>> awaitSubscriptionsOpened( int subscriptionsCount) { return testClient .receiveWorkflowInstanceSubscriptions() .withIntent(WorkflowInstanceSubscriptionIntent.OPENED) .limit(subscriptionsCount) .asList(); } }
@Override protected WorkflowInstanceSubscriptionRecordStream supply( final Stream<Record<WorkflowInstanceSubscriptionRecordValue>> wrappedStream) { return new WorkflowInstanceSubscriptionRecordStream(wrappedStream); }
public WorkflowInstanceSubscriptionRecordStream withWorkflowInstanceKey( final long workflowInstanceKey) { return valueFilter(v -> v.getWorkflowInstanceKey() == workflowInstanceKey); }
RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.CORRELATE) .limit(2) .map(r -> r.getValue().getMessageName()) .collect(Collectors.toList()); RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.CORRELATED) .withMessageName(messageNames.get(0)) .exists()) .isTrue(); RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.CORRELATE) .withMessageName(messageNames.get(1)) .onlyCommandRejections() .getFirst() .getMetadata()) .hasRecordType(RecordType.COMMAND_REJECTION)
@Test public void shouldCorrelateMessageAndContinue() { // given testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); // when assertThat( testClient .receiveWorkflowInstanceSubscriptions() .withMessageName("order canceled") .withIntent(WorkflowInstanceSubscriptionIntent.OPENED) .limit(1) .getFirst()) .isNotNull(); testClient.publishMessage("order canceled", "order-123"); // then assertThat( RecordingExporter.workflowInstanceRecords(continueState) .withElementId(continuedElementId) .exists()) .isTrue(); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.SEQUENCE_FLOW_TAKEN) .withElementId("to-end") .exists()) .isTrue(); } }
@Test public void shouldOpenWorkflowInstanceSubscription() { final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); final Record<WorkflowInstanceRecordValue> catchEventEntered = testClient.receiveElementInState("receive-message", enteredState); final Record<WorkflowInstanceSubscriptionRecordValue> workflowInstanceSubscription = testClient .receiveWorkflowInstanceSubscriptions() .withIntent(WorkflowInstanceSubscriptionIntent.OPENED) .getFirst(); assertThat(workflowInstanceSubscription.getMetadata().getValueType()) .isEqualTo(ValueType.WORKFLOW_INSTANCE_SUBSCRIPTION); assertThat(workflowInstanceSubscription.getMetadata().getRecordType()) .isEqualTo(RecordType.EVENT); assertWorkflowSubscription( workflowInstanceKey, catchEventEntered, workflowInstanceSubscription); }
testClient .receiveWorkflowInstanceSubscriptions() .withMessageName("message") .withIntent(WorkflowInstanceSubscriptionIntent.OPENED) .exists()) .isTrue(); testClient.publishMessage("message", "123", asMsgPack("foo", 3));
testClient .receiveWorkflowInstanceSubscriptions() .withIntent(WorkflowInstanceSubscriptionIntent.OPENED) .limit(1) .exists())
@Test public void shouldCorrelateMessageOnlyOnceIfEnteredBefore() { // given testClient.deploy(TWO_MESSAGES_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); // when assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .exists()) .isTrue(); testClient.publishMessage("ping", "123", asMsgPack("nr", 1)); assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .limit(2) .count()) .isEqualTo(2); testClient.publishMessage("ping", "123", asMsgPack("nr", 2)); // 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 shouldCloseWorkflowInstanceSubscription() { // given testClient.deploy(WORKFLOW_WITH_MESSAGES); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .limit(2) .exists()) .isTrue(); // when testClient.publishMessage("msg-1", "123"); // then assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.CLOSED) .limit(1)) .extracting(r -> r.getValue().getMessageName()) .hasSize(1) .contains("msg-2"); }
public static WorkflowInstanceSubscriptionRecordStream workflowInstanceSubscriptionRecords( final WorkflowInstanceSubscriptionIntent intent) { return workflowInstanceSubscriptionRecords().withIntent(intent); }
@Test public void shouldCloseWorkflowInstanceSubscription() { final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); final Record<WorkflowInstanceRecordValue> catchEventEntered = testClient.receiveElementInState("receive-message", enteredState); testClient.cancelWorkflowInstance(workflowInstanceKey); final Record<WorkflowInstanceSubscriptionRecordValue> subscription = RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.CLOSED) .getFirst(); assertThat(subscription.getMetadata().getRecordType()).isEqualTo(RecordType.EVENT); Assertions.assertThat(subscription.getValue()) .hasWorkflowInstanceKey(workflowInstanceKey) .hasElementInstanceKey(catchEventEntered.getKey()) .hasMessageName("order canceled"); }
@Test public void shouldResolveIncidentIfCorrelationKeyNotFound() { // given final long workflowInstance = testClient.createWorkflowInstance(PROCESS_ID); final Record<IncidentRecordValue> incidentCreatedRecord = RecordingExporter.incidentRecords(IncidentIntent.CREATED).getFirst(); testClient.updatePayload( incidentCreatedRecord.getValue().getElementInstanceKey(), "{\"orderId\":\"order123\"}"); // when testClient.resolveIncident(incidentCreatedRecord.getKey()); // then assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .exists()) .isTrue(); final Record<IncidentRecordValue> incidentResolvedEvent = testClient.receiveFirstIncidentEvent(workflowInstance, RESOLVED); assertThat(incidentResolvedEvent.getKey()).isEqualTo(incidentCreatedRecord.getKey()); } }
@Test public void shouldOpenSubscriptionsWhenIncidentIsResolved() { // given testClient.createWorkflowInstance(PROCESS_ID, MsgPackUtil.asMsgPack("key-1", "k1")); final Record<IncidentRecordValue> incidentCreatedRecord = RecordingExporter.incidentRecords(IncidentIntent.CREATED).getFirst(); // when testClient.updatePayload( incidentCreatedRecord.getValue().getElementInstanceKey(), "{'key-1':'k1', 'key-2':'k2'}"); testClient.resolveIncident(incidentCreatedRecord.getKey()); // then assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .limit(2)) .extracting(Record::getValue) .extracting(WorkflowInstanceSubscriptionRecordValue::getMessageName) .containsExactlyInAnyOrder("msg-1", "msg-2"); // and testClient.publishMessage("msg-2", "k2"); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId(PROCESS_ID) .exists()) .isTrue(); }
RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.CORRELATE) .limit(2) .map(r -> r.getValue().getMessageName()) .collect(Collectors.toList()); RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.CORRELATED) .withMessageName(messageNames.get(0)) .exists()) .isTrue(); RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.CORRELATE) .withMessageName(messageNames.get(1)) .onlyCommandRejections() .getFirst() .getMetadata()) .hasRecordType(RecordType.COMMAND_REJECTION)
@Test public void shouldCorrelateMessageAndContinue() { // given testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); // when assertThat( testClient .receiveWorkflowInstanceSubscriptions() .withMessageName("order canceled") .withIntent(WorkflowInstanceSubscriptionIntent.OPENED) .limit(1) .getFirst()) .isNotNull(); testClient.publishMessage("order canceled", "order-123"); // then assertThat( RecordingExporter.workflowInstanceRecords(continueState) .withElementId(continuedElementId) .exists()) .isTrue(); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.SEQUENCE_FLOW_TAKEN) .withElementId("to-end") .exists()) .isTrue(); } }
@Test public void shouldOpenWorkflowInstanceSubscription() { final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); final Record<WorkflowInstanceRecordValue> catchEventEntered = testClient.receiveElementInState("receive-message", enteredState); final Record<WorkflowInstanceSubscriptionRecordValue> workflowInstanceSubscription = testClient .receiveWorkflowInstanceSubscriptions() .withIntent(WorkflowInstanceSubscriptionIntent.OPENED) .getFirst(); assertThat(workflowInstanceSubscription.getMetadata().getValueType()) .isEqualTo(ValueType.WORKFLOW_INSTANCE_SUBSCRIPTION); assertThat(workflowInstanceSubscription.getMetadata().getRecordType()) .isEqualTo(RecordType.EVENT); assertWorkflowSubscription( workflowInstanceKey, catchEventEntered, workflowInstanceSubscription); }
testClient .receiveWorkflowInstanceSubscriptions() .withMessageName("message") .withIntent(WorkflowInstanceSubscriptionIntent.OPENED) .exists()) .isTrue(); testClient.publishMessage("message", "123", asMsgPack("foo", 3));