public static MessageStartEventSubscriptionRecordStream messageStartEventSubscriptionRecords( final MessageStartEventSubscriptionIntent intent) { return messageStartEventSubscriptionRecords().withIntent(intent); }
public static MessageStartEventSubscriptionRecordStream messageStartEventSubscriptionRecords( final MessageStartEventSubscriptionIntent intent) { return messageStartEventSubscriptionRecords().withIntent(intent); }
@Override public void executeInstance() { // wait for message subscription for the start event to be opened RecordingExporter.messageStartEventSubscriptionRecords( MessageStartEventSubscriptionIntent.OPENED) .getFirst(); testClient.publishMessage(messageName(), ""); } },
@Override public void executeInstance() { // wait for message subscription for the start event to be opened RecordingExporter.messageStartEventSubscriptionRecords( MessageStartEventSubscriptionIntent.OPENED) .exists(); testClient.publishMessage(messageName(), ""); } },
@Test public void shouldOpenMessageSubscriptionOnDeployment() { // when testClient.deploy(createWorkflowWithOneMessageStartEvent()); final Record<MessageStartEventSubscriptionRecordValue> subscription = RecordingExporter.messageStartEventSubscriptionRecords( MessageStartEventSubscriptionIntent.OPENED) .getFirst(); // then assertThat(subscription.getValue().getStartEventId()).isEqualTo(EVENT_ID1); assertThat(subscription.getValue().getMessageName()).isEqualTo(MESSAGE_NAME1); }
@Test public void shouldOpenMessageSubscriptionOnDeployment() { // when testClient.deploy(createWorkflowWithOneMessageStartEvent()); final Record<MessageStartEventSubscriptionRecordValue> subscription = RecordingExporter.messageStartEventSubscriptionRecords( MessageStartEventSubscriptionIntent.OPENED) .getFirst(); // then assertThat(subscription.getValue().getStartEventId()).isEqualTo(EVENT_ID1); assertThat(subscription.getValue().getMessageName()).isEqualTo(MESSAGE_NAME1); }
@Test public void shouldCloseSubscriptionForOldVersions() { // given testClient.deploy(createWorkflowWithOneMessageStartEvent()); // when testClient.deploy(createWorkflowWithOneMessageStartEvent()); // then final List<Record<MessageStartEventSubscriptionRecordValue>> subscriptions = RecordingExporter.messageStartEventSubscriptionRecords().limit(6).asList(); final List<Intent> intents = subscriptions.stream().map(s -> s.getMetadata().getIntent()).collect(Collectors.toList()); assertThat(intents) .containsExactly( MessageStartEventSubscriptionIntent.OPEN, MessageStartEventSubscriptionIntent.OPENED, MessageStartEventSubscriptionIntent.CLOSE, // close old version MessageStartEventSubscriptionIntent.OPEN, // open new MessageStartEventSubscriptionIntent.CLOSED, MessageStartEventSubscriptionIntent.OPENED); final long closingWorkflowKey = subscriptions.get(2).getValue().getWorkflowKey(); assertThat(closingWorkflowKey).isEqualTo(subscriptions.get(0).getValue().getWorkflowKey()); }
@Test public void shouldCloseSubscriptionForOldVersions() { // given testClient.deploy(createWorkflowWithOneMessageStartEvent()); // when testClient.deploy(createWorkflowWithOneMessageStartEvent()); // then final List<Record<MessageStartEventSubscriptionRecordValue>> subscriptions = RecordingExporter.messageStartEventSubscriptionRecords().limit(6).asList(); final List<Intent> intents = subscriptions.stream().map(s -> s.getMetadata().getIntent()).collect(Collectors.toList()); assertThat(intents) .containsExactly( MessageStartEventSubscriptionIntent.OPEN, MessageStartEventSubscriptionIntent.OPENED, MessageStartEventSubscriptionIntent.CLOSE, // close old version MessageStartEventSubscriptionIntent.OPEN, // open new MessageStartEventSubscriptionIntent.CLOSED, MessageStartEventSubscriptionIntent.OPENED); final long closingWorkflowKey = subscriptions.get(2).getValue().getWorkflowKey(); assertThat(closingWorkflowKey).isEqualTo(subscriptions.get(0).getValue().getWorkflowKey()); }
@Test public void shouldApplyOutputMappingsOfMessageStartEvent() { // given testClient.deployWithResponse(createWorkflowWithMessageStartEventOutputMapping()); // wait until subscription is opened assertThat( messageStartEventSubscriptionRecords(MessageStartEventSubscriptionIntent.OPENED) .exists()) .isTrue(); // when testClient.publishMessage(MESSAGE_NAME1, "order-123", asMsgPack("foo", "bar")); // then assertThat( RecordingExporter.variableRecords().withName("mappedfoo").withValue("\"bar\"").exists()) .isTrue(); }
@Test public void shouldMergeMessagePayload() { // given testClient.deployWithResponse(createWorkflowWithOneMessageStartEvent()); // wait until subscription is opened assertThat( messageStartEventSubscriptionRecords(MessageStartEventSubscriptionIntent.OPENED) .exists()) .isTrue(); // when testClient.publishMessage(MESSAGE_NAME1, "order-123", asMsgPack("foo", "bar")); // then assertThat(RecordingExporter.variableRecords().withName("foo").withValue("\"bar\"").exists()) .isTrue(); }
@Test public void shouldMergeMessagePayload() { // given testClient.deployWithResponse(createWorkflowWithOneMessageStartEvent()); // wait until subscription is opened assertThat( messageStartEventSubscriptionRecords(MessageStartEventSubscriptionIntent.OPENED) .exists()) .isTrue(); // when testClient.publishMessage(MESSAGE_NAME1, "order-123", asMsgPack("foo", "bar")); // then assertThat(RecordingExporter.variableRecords().withName("foo").withValue("\"bar\"").exists()) .isTrue(); }
@Test public void shouldApplyOutputMappingsOfMessageStartEvent() { // given testClient.deployWithResponse(createWorkflowWithMessageStartEventOutputMapping()); // wait until subscription is opened assertThat( messageStartEventSubscriptionRecords(MessageStartEventSubscriptionIntent.OPENED) .exists()) .isTrue(); // when testClient.publishMessage(MESSAGE_NAME1, "order-123", asMsgPack("foo", "bar")); // then assertThat( RecordingExporter.variableRecords().withName("mappedfoo").withValue("\"bar\"").exists()) .isTrue(); }
@Test public void shouldOpenSubscriptionsForAllMessageStartEvents() { // when testClient.deploy(createWorkflowWithTwoMessageStartEvent()); final List<Record<MessageStartEventSubscriptionRecordValue>> subscriptions = RecordingExporter.messageStartEventSubscriptionRecords( MessageStartEventSubscriptionIntent.OPENED) .limit(2) .asList(); // then assertThat(subscriptions.size()).isEqualTo(2); assertThat(subscriptions) .hasSize(2) .extracting(Record::getValue) .extracting(s -> tuple(s.getMessageName(), s.getStartEventId())) .containsExactlyInAnyOrder( tuple(MESSAGE_NAME1, EVENT_ID1), tuple(MESSAGE_NAME2, EVENT_ID2)); }
@Test public void shouldOpenSubscriptionsForAllMessageStartEvents() { // when testClient.deploy(createWorkflowWithTwoMessageStartEvent()); final List<Record<MessageStartEventSubscriptionRecordValue>> subscriptions = RecordingExporter.messageStartEventSubscriptionRecords( MessageStartEventSubscriptionIntent.OPENED) .limit(2) .asList(); // then assertThat(subscriptions.size()).isEqualTo(2); assertThat(subscriptions) .hasSize(2) .extracting(Record::getValue) .extracting(s -> tuple(s.getMessageName(), s.getStartEventId())) .containsExactlyInAnyOrder( tuple(MESSAGE_NAME1, EVENT_ID1), tuple(MESSAGE_NAME2, EVENT_ID2)); }
@Test public void shouldCreateInstancesForDifferentMessages() { // given final ExecuteCommandResponse response = testClient.deployWithResponse(createWorkflowWithTwoMessageStartEvent()); final long workflowKey = getFirstDeployedWorkflowKey(response); // check if two subscriptions are opened assertThat( messageStartEventSubscriptionRecords(MessageStartEventSubscriptionIntent.OPENED) .limit(2) .count()) .isEqualTo(2); // when testClient.publishMessage(MESSAGE_NAME1, "order-123", asMsgPack("foo", "bar")); testClient.publishMessage(MESSAGE_NAME2, "order-124", asMsgPack("foo", "bar")); // then // check if two instances are created final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_TRIGGERING) .limit(2) .asList(); assertThat(records.size()).isEqualTo(2); assertThat(records).allMatch(r -> r.getValue().getWorkflowKey() == workflowKey); assertThat(records.get(0).getValue()) .hasElementId(EVENT_ID1); // Message 1 triggers start event 1 assertThat(records.get(1).getValue()) .hasElementId(EVENT_ID2); // Message 2 triggers start event 2 }
@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()); }
@Test public void shouldOpenMessageStartEventSubscriptionOnAllPartitions() { testClient.deploy(createWorkflowWithOneMessageStartEvent()); final List<Record<MessageStartEventSubscriptionRecordValue>> subscriptions = RecordingExporter.messageStartEventSubscriptionRecords( MessageStartEventSubscriptionIntent.OPENED) .limit(3) .asList(); assertThat(subscriptions) .hasSize(3) .extracting(Record::getValue) .extracting(v -> tuple(v.getStartEventId(), v.getMessageName())) .containsOnly(tuple(EVENT_ID1, MESSAGE_NAME1)); assertThat(subscriptions) .extracting(r -> r.getMetadata().getPartitionId()) .containsExactlyInAnyOrder(0, 1, 2); }
@Test public void shouldOpenMessageStartEventSubscriptionOnAllPartitions() { testClient.deploy(createWorkflowWithOneMessageStartEvent()); final List<Record<MessageStartEventSubscriptionRecordValue>> subscriptions = RecordingExporter.messageStartEventSubscriptionRecords( MessageStartEventSubscriptionIntent.OPENED) .limit(3) .asList(); assertThat(subscriptions) .hasSize(3) .extracting(Record::getValue) .extracting(v -> tuple(v.getStartEventId(), v.getMessageName())) .containsOnly(tuple(EVENT_ID1, MESSAGE_NAME1)); assertThat(subscriptions) .extracting(r -> r.getMetadata().getPartitionId()) .containsExactlyInAnyOrder(0, 1, 2); }
@Test public void shouldCorrelateMessageToStartEvent() { // 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 Record<WorkflowInstanceRecordValue> record = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_OCCURRED).getFirst(); assertThat(record.getValue()).hasWorkflowKey(workflowKey).hasElementId(EVENT_ID1); }
@Test public void shouldCorrelateMessageToStartEvent() { // 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 Record<WorkflowInstanceRecordValue> record = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_OCCURRED).getFirst(); assertThat(record.getValue()).hasWorkflowKey(workflowKey).hasElementId(EVENT_ID1); }