public static WorkflowInstanceSubscriptionRecordStream workflowInstanceSubscriptionRecords( final WorkflowInstanceSubscriptionIntent intent) { return workflowInstanceSubscriptionRecords().withIntent(intent); }
public static WorkflowInstanceSubscriptionRecordStream workflowInstanceSubscriptionRecords( final WorkflowInstanceSubscriptionIntent intent) { return workflowInstanceSubscriptionRecords().withIntent(intent); }
public WorkflowInstanceSubscriptionRecordStream receiveWorkflowInstanceSubscriptions() { return RecordingExporter.workflowInstanceSubscriptionRecords().withPartitionId(partitionId); }
public WorkflowInstanceSubscriptionRecordStream receiveWorkflowInstanceSubscriptions() { return RecordingExporter.workflowInstanceSubscriptionRecords().withPartitionId(partitionId); }
private List<Record<WorkflowInstanceSubscriptionRecordValue>> awaitMessagesCorrelated( int messagesCount) { return RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.CORRELATED) .limit(messagesCount) .asList(); }
private List<Record<WorkflowInstanceSubscriptionRecordValue>> awaitMessagesCorrelated( int messagesCount) { return RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.CORRELATED) .limit(messagesCount) .asList(); }
@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"); }
@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()); // when testClient.publishMessage("msg-1", "123"); // then assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.CLOSED) .limit(1)) .extracting(r -> r.getValue().getMessageName()) .hasSize(1) .contains("msg-2"); }
@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 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()); final Record<IncidentRecordValue> incidentResolvedEvent = testClient.receiveFirstIncidentEvent(workflowInstance, RESOLVED); assertThat(incidentResolvedEvent.getKey()).isEqualTo(incidentCreatedRecord.getKey()); } }
@Test public void shouldCancelSubscriptionsWhenScopeIsTerminated() { // given testClient.deploy(WORKFLOW_WITH_TIMER_AND_MESSAGE); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(1).exists()); assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .limit(1) .exists()); // when testClient.cancelWorkflowInstance(workflowInstanceKey); // then assertThat(RecordingExporter.timerRecords(TimerIntent.CANCELED).limit(1)) .extracting(r -> r.getValue().getHandlerFlowNodeId()) .hasSize(1) .contains("timer"); assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.CLOSED) .limit(1)) .extracting(r -> r.getValue().getMessageName()) .hasSize(1) .contains("msg"); }
@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 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 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.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 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 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(); }
@Test public void shouldContinueWhenMessageIsCorrelated() { // given testClient.deploy(WORKFLOW_WITH_MESSAGES); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); final Record<WorkflowInstanceRecordValue> gatewayEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.GATEWAY_ACTIVATED) .getFirst(); // when testClient.publishMessage("msg-1", "123"); // then final Record<WorkflowInstanceSubscriptionRecordValue> triggeredEvent = RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.CORRELATED) .getFirst(); Assertions.assertThat(triggeredEvent.getValue()) .hasElementInstanceKey(gatewayEvent.getKey()) .hasMessageName("msg-1"); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.SEQUENCE_FLOW_TAKEN) .withElementId("to-end1") .exists()) .isTrue(); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId(PROCESS_ID) .exists()); }
@Test public void shouldOpenWorkflowInstanceSubscriptions() { // given testClient.deploy(WORKFLOW_WITH_MESSAGES); // when testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); // then final Record<WorkflowInstanceRecordValue> gatewayEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.GATEWAY_ACTIVATED) .getFirst(); final List<Record<WorkflowInstanceSubscriptionRecordValue>> subscriptionEvents = RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .limit(2) .asList(); assertThat(subscriptionEvents) .hasSize(2) .extracting(r -> tuple(r.getValue().getMessageName(), r.getValue().getElementInstanceKey())) .contains(tuple("msg-1", gatewayEvent.getKey()), tuple("msg-2", gatewayEvent.getKey())); }
@Test public void shouldOpenWorkflowInstanceSubscriptions() { // given testClient.deploy(WORKFLOW_WITH_MESSAGES); // when testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); // then final Record<WorkflowInstanceRecordValue> gatewayEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementType(BpmnElementType.EVENT_BASED_GATEWAY) .getFirst(); final List<Record<WorkflowInstanceSubscriptionRecordValue>> subscriptionEvents = RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .limit(2) .asList(); assertThat(subscriptionEvents) .hasSize(2) .extracting(r -> tuple(r.getValue().getMessageName(), r.getValue().getElementInstanceKey())) .contains(tuple("msg-1", gatewayEvent.getKey()), tuple("msg-2", gatewayEvent.getKey())); }
RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .limit(2)