@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 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"); }
WorkflowInstanceSubscriptionIntent.CORRELATED) .withMessageName(messageNames.get(0)) .exists()) .isTrue();
WorkflowInstanceSubscriptionIntent.CORRELATED) .withMessageName(messageNames.get(0)) .exists()) .isTrue();
@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 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 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 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.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 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()).isTrue(); assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .limit(1) .exists()) .isTrue(); // 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 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 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"); }
.withMessageName("message") .withIntent(WorkflowInstanceSubscriptionIntent.OPENED) .exists()) .isTrue(); testClient.publishMessage("message", "123", asMsgPack("foo", 3));
.withMessageName("message") .withIntent(WorkflowInstanceSubscriptionIntent.OPENED) .exists()) .isTrue(); testClient.publishMessage("message", "123", asMsgPack("foo", 3));
.withIntent(WorkflowInstanceSubscriptionIntent.OPENED) .limit(1) .exists())
.withIntent(WorkflowInstanceSubscriptionIntent.OPENED) .limit(1) .exists())