public static MessageSubscriptionRecordStream messageSubscriptionRecords( final MessageSubscriptionIntent intent) { return messageSubscriptionRecords().withIntent(intent); }
@Override protected MessageSubscriptionRecordStream supply( final Stream<Record<MessageSubscriptionRecordValue>> wrappedStream) { return new MessageSubscriptionRecordStream(wrappedStream); }
public MessageSubscriptionRecordStream withWorkflowInstanceKey(final long workflowInstanceKey) { return valueFilter(v -> v.getWorkflowInstanceKey() == workflowInstanceKey); }
@Test public void shouldCorrelateMessageSubscription() { // given final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); final Record<WorkflowInstanceRecordValue> catchEventEntered = testClient.receiveElementInState("receive-message", enteredState); // when testClient.publishMessage("order canceled", "order-123", asMsgPack("foo", "bar")); // then final Record<MessageSubscriptionRecordValue> subscription = testClient .receiveMessageSubscriptions() .withIntent(MessageSubscriptionIntent.CORRELATED) .getFirst(); assertThat(subscription.getMetadata().getValueType()).isEqualTo(ValueType.MESSAGE_SUBSCRIPTION); assertThat(subscription.getMetadata().getRecordType()).isEqualTo(RecordType.EVENT); assertMessageSubscription(workflowInstanceKey, catchEventEntered, subscription); }
@Test public void shouldCorrelateMessageWithZeroTTL() { // given testClient.deploy(SINGLE_MESSAGE_WORKFLOW); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); assertThat( RecordingExporter.messageSubscriptionRecords(MessageSubscriptionIntent.OPENED).exists()) .isTrue(); // when testClient.publishMessage("message", "order-123", asMsgPack("foo", "bar"), 0); // then final Record<WorkflowInstanceRecordValue> event = testClient.receiveElementInState("receive-message", WorkflowInstanceIntent.EVENT_TRIGGERED); assertThat(event.getValue().getWorkflowInstanceKey()).isEqualTo(workflowInstanceKey); }
@Test public void shouldOpenMessageSubscription() { final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); final Record<WorkflowInstanceRecordValue> catchEventEntered = testClient.receiveElementInState("receive-message", enteredState); final Record<MessageSubscriptionRecordValue> messageSubscription = RecordingExporter.messageSubscriptionRecords(MessageSubscriptionIntent.OPENED).getFirst(); assertThat(messageSubscription.getMetadata().getValueType()) .isEqualTo(ValueType.MESSAGE_SUBSCRIPTION); assertThat(messageSubscription.getMetadata().getRecordType()).isEqualTo(RecordType.EVENT); assertMessageSubscription( workflowInstanceKey, "order-123", catchEventEntered, messageSubscription); }
public MessageSubscriptionRecordStream receiveMessageSubscriptions() { return RecordingExporter.messageSubscriptionRecords().withPartitionId(partitionId); }
@Test public void shouldOpenMessageSubscriptionsOnDifferentPartitions() { // when IntStream.range(0, 10) .forEach( i -> { testClient.createWorkflowInstance( PROCESS_ID, asMsgPack("key", CORRELATION_KEY_PARTITION_0)); testClient.createWorkflowInstance( PROCESS_ID, asMsgPack("key", CORRELATION_KEY_PARTITION_1)); testClient.createWorkflowInstance( PROCESS_ID, asMsgPack("key", CORRELATION_KEY_PARTITION_2)); }); // then assertThat( RecordingExporter.messageSubscriptionRecords(MessageSubscriptionIntent.OPENED) .limit(30)) .extracting(r -> tuple(r.getMetadata().getPartitionId(), r.getValue().getCorrelationKey())) .containsOnly( tuple(0, CORRELATION_KEY_PARTITION_0), tuple(1, CORRELATION_KEY_PARTITION_1), tuple(2, CORRELATION_KEY_PARTITION_2)); }
@Test public void shouldCorrelateMessageSubscription() { // given final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); final Record<WorkflowInstanceRecordValue> catchEventEntered = testClient.receiveElementInState("receive-message", enteredState); // when testClient.publishMessage("order canceled", "order-123", asMsgPack("foo", "bar")); // then final Record<MessageSubscriptionRecordValue> subscription = testClient .receiveMessageSubscriptions() .withIntent(MessageSubscriptionIntent.CORRELATED) .getFirst(); assertThat(subscription.getMetadata().getValueType()).isEqualTo(ValueType.MESSAGE_SUBSCRIPTION); assertThat(subscription.getMetadata().getRecordType()).isEqualTo(RecordType.EVENT); assertMessageSubscription(workflowInstanceKey, catchEventEntered, subscription); }
@Test public void shouldCorrelateMessageWithZeroTTL() { // given testClient.deploy(SINGLE_MESSAGE_WORKFLOW); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); assertThat( RecordingExporter.messageSubscriptionRecords(MessageSubscriptionIntent.OPENED).exists()) .isTrue(); // when testClient.publishMessage("message", "order-123", asMsgPack("foo", "bar"), 0); // then final Record<WorkflowInstanceRecordValue> event = testClient.receiveElementInState( "receive-message", WorkflowInstanceIntent.ELEMENT_COMPLETED); assertThat(event.getValue().getWorkflowInstanceKey()).isEqualTo(workflowInstanceKey); }
@Test public void shouldOpenMessageSubscription() { final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); final Record<WorkflowInstanceRecordValue> catchEventEntered = testClient.receiveElementInState("receive-message", enteredState); final Record<MessageSubscriptionRecordValue> messageSubscription = RecordingExporter.messageSubscriptionRecords(MessageSubscriptionIntent.OPENED).getFirst(); assertThat(messageSubscription.getMetadata().getValueType()) .isEqualTo(ValueType.MESSAGE_SUBSCRIPTION); assertThat(messageSubscription.getMetadata().getRecordType()).isEqualTo(RecordType.EVENT); assertMessageSubscription( workflowInstanceKey, "order-123", catchEventEntered, messageSubscription); }
public MessageSubscriptionRecordStream receiveMessageSubscriptions() { return RecordingExporter.messageSubscriptionRecords().withPartitionId(partitionId); }
@Test public void shouldOpenMessageSubscriptionsOnDifferentPartitions() { // when IntStream.range(0, 10) .forEach( i -> { testClient.createWorkflowInstance( PROCESS_ID, asMsgPack("key", CORRELATION_KEY_PARTITION_0)); testClient.createWorkflowInstance( PROCESS_ID, asMsgPack("key", CORRELATION_KEY_PARTITION_1)); testClient.createWorkflowInstance( PROCESS_ID, asMsgPack("key", CORRELATION_KEY_PARTITION_2)); }); // then assertThat( RecordingExporter.messageSubscriptionRecords(MessageSubscriptionIntent.OPENED) .limit(30)) .extracting(r -> tuple(r.getMetadata().getPartitionId(), r.getValue().getCorrelationKey())) .containsOnly( tuple(0, CORRELATION_KEY_PARTITION_0), tuple(1, CORRELATION_KEY_PARTITION_1), tuple(2, CORRELATION_KEY_PARTITION_2)); }
public MessageSubscriptionRecordStream withWorkflowInstanceKey(final long workflowInstanceKey) { return valueFilter(v -> v.getWorkflowInstanceKey() == workflowInstanceKey); }
public static MessageSubscriptionRecordStream messageSubscriptionRecords( final MessageSubscriptionIntent intent) { return messageSubscriptionRecords().withIntent(intent); }
@Override protected MessageSubscriptionRecordStream supply( final Stream<Record<MessageSubscriptionRecordValue>> wrappedStream) { return new MessageSubscriptionRecordStream(wrappedStream); }
@Test public void shouldCorrelateMessageIfEnteredBefore() { // given testClient.deploy(SINGLE_MESSAGE_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); assertThat( RecordingExporter.messageSubscriptionRecords(MessageSubscriptionIntent.OPENED).exists()) .isTrue(); // when testClient.publishMessage("message", "order-123", asMsgPack("foo", "bar")); // then final Record<WorkflowInstanceRecordValue> event = testClient.receiveElementInState("receive-message", WorkflowInstanceIntent.EVENT_TRIGGERED); assertWorkflowInstancePayload(event, "{'key':'order-123', 'foo':'bar'}"); }
@Test public void shouldCloseMessageSubscription() { // given final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); final Record<WorkflowInstanceRecordValue> catchEventEntered = testClient.receiveElementInState("receive-message", enteredState); // when testClient.cancelWorkflowInstance(workflowInstanceKey); // then final Record<MessageSubscriptionRecordValue> messageSubscription = RecordingExporter.messageSubscriptionRecords(MessageSubscriptionIntent.CLOSED).getFirst(); assertThat(messageSubscription.getMetadata().getRecordType()).isEqualTo(RecordType.EVENT); Assertions.assertThat(messageSubscription.getValue()) .hasWorkflowInstanceKey(workflowInstanceKey) .hasElementInstanceKey(catchEventEntered.getKey()) .hasMessageName("order canceled") .hasCorrelationKey(""); }
public MessageSubscriptionRecordStream withMessageName(final String messageName) { return valueFilter(v -> messageName.equals(v.getMessageName())); }
public static MessageSubscriptionRecordStream messageSubscriptionRecords() { return new MessageSubscriptionRecordStream( records(ValueType.MESSAGE_SUBSCRIPTION, MessageSubscriptionRecordValue.class)); }