public WorkflowInstanceRecordStream withWorkflowInstanceKey(final long workflowInstanceKey) { return valueFilter(v -> v.getWorkflowInstanceKey() == workflowInstanceKey); }
public WorkflowInstanceRecordStream withWorkflowInstanceKey(final long workflowInstanceKey) { return valueFilter(v -> v.getWorkflowInstanceKey() == workflowInstanceKey); }
/** * Verifies that the actual WorkflowInstanceRecordValue's workflowInstanceKey is equal to the given one. * @param workflowInstanceKey the given workflowInstanceKey to compare the actual WorkflowInstanceRecordValue's workflowInstanceKey to. * @return this assertion object. * @throws AssertionError - if the actual WorkflowInstanceRecordValue's workflowInstanceKey is not equal to the given one. */ public S hasWorkflowInstanceKey(long workflowInstanceKey) { // check that actual WorkflowInstanceRecordValue we want to make assertions on is not null. isNotNull(); // overrides the default error message with a more explicit one String assertjErrorMessage = "\nExpecting workflowInstanceKey of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; // check long actualWorkflowInstanceKey = actual.getWorkflowInstanceKey(); if (actualWorkflowInstanceKey != workflowInstanceKey) { failWithMessage(assertjErrorMessage, actual, workflowInstanceKey, actualWorkflowInstanceKey); } // return the current assertion for method chaining return myself; }
/** * @return stream with only records for the workflow instance (i.e. root scope of the instance) */ public WorkflowInstanceRecordStream filterRootScope() { return filter(r -> r.getKey() == r.getValue().getWorkflowInstanceKey()); } }
/** * @return stream with only records for the workflow instance (i.e. root scope of the instance) */ public WorkflowInstanceRecordStream filterRootScope() { return filter(r -> r.getKey() == r.getValue().getWorkflowInstanceKey()); } }
public WorkflowInstanceRecordStream limitToWorkflowInstanceCompleted() { return limit( r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.ELEMENT_COMPLETED && r.getKey() == r.getValue().getWorkflowInstanceKey()); }
public WorkflowInstanceRecordStream limitToWorkflowInstanceCompleted() { return limit( r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.ELEMENT_COMPLETED && r.getKey() == r.getValue().getWorkflowInstanceKey()); }
@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 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 shouldUpdatePayload() { // given testClient.deploy(WORKFLOW); final long workflowInstanceKey = testClient.createWorkflowInstance("process"); final Record<WorkflowInstanceRecordValue> activityInstanceEvent = waitForActivityActivatedEvent(); // when final ExecuteCommandResponse response = updatePayload( activityInstanceEvent.getKey(), MsgPackUtil.asMsgPackReturnArray("{'foo':'bar'}")); // then assertThat(response.getIntent()).isEqualTo(WorkflowInstanceIntent.PAYLOAD_UPDATED); final Record<WorkflowInstanceRecordValue> updateCommand = testClient.receiveFirstWorkflowInstanceCommand(WorkflowInstanceIntent.UPDATE_PAYLOAD); final Record<WorkflowInstanceRecordValue> updatedEvent = testClient.receiveFirstWorkflowInstanceEvent(WorkflowInstanceIntent.PAYLOAD_UPDATED); assertThat(updatedEvent.getSourceRecordPosition()).isEqualTo(updateCommand.getPosition()); assertThat(updatedEvent.getKey()).isEqualTo(activityInstanceEvent.getKey()); assertThat(updatedEvent.getValue().getWorkflowInstanceKey()).isEqualTo(workflowInstanceKey); assertWorkflowInstancePayload(updatedEvent, "{'foo':'bar'}"); }
@Test public void shouldUpdatePayload() { // given testClient.deploy(WORKFLOW); final long workflowInstanceKey = testClient.createWorkflowInstance("process"); final Record<WorkflowInstanceRecordValue> activityInstanceEvent = waitForActivityActivatedEvent(); // when final ExecuteCommandResponse response = updatePayload( activityInstanceEvent.getKey(), MsgPackUtil.asMsgPackReturnArray("{'foo':'bar'}")); // then assertThat(response.getIntent()).isEqualTo(WorkflowInstanceIntent.PAYLOAD_UPDATED); final Record<WorkflowInstanceRecordValue> updateCommand = testClient.receiveFirstWorkflowInstanceCommand(WorkflowInstanceIntent.UPDATE_PAYLOAD); final Record<WorkflowInstanceRecordValue> updatedEvent = testClient.receiveFirstWorkflowInstanceEvent(WorkflowInstanceIntent.PAYLOAD_UPDATED); assertThat(updatedEvent.getSourceRecordPosition()).isEqualTo(updateCommand.getPosition()); assertThat(updatedEvent.getKey()).isEqualTo(activityInstanceEvent.getKey()); assertThat(updatedEvent.getValue().getWorkflowInstanceKey()).isEqualTo(workflowInstanceKey); assertWorkflowInstancePayload(updatedEvent, "{'foo':'bar'}"); }
@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 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_ACTIVATING) .withElementType(BpmnElementType.PROCESS) .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()); }
.getFirst() .getValue() .getWorkflowInstanceKey(); assertThat( RecordingExporter.workflowInstanceRecords(EVENT_ACTIVATED) .getFirst() .getValue() .getWorkflowInstanceKey(); assertThat( RecordingExporter.workflowInstanceRecords(EVENT_ACTIVATED)
@Test public void shouldActivateJobsFromWorkflow() { // given final int jobAmount = 10; deployWorkflow("foo", "bar", "baz"); final List<Long> workflowInstanceKeys = createWorkflowInstances(jobAmount); // when activating and completing all jobs waitUntil( () -> jobRecords(JobIntent.CREATED).withType("foo").limit(jobAmount).count() == jobAmount); activateJobs("foo", jobAmount).forEach(this::completeJob); waitUntil( () -> jobRecords(JobIntent.CREATED).withType("bar").limit(jobAmount).count() == jobAmount); activateJobs("bar", jobAmount).forEach(this::completeJob); waitUntil( () -> jobRecords(JobIntent.CREATED).withType("baz").limit(jobAmount).count() == jobAmount); activateJobs("baz", jobAmount).forEach(this::completeJob); // then all workflow instances are completed final List<Record<WorkflowInstanceRecordValue>> records = workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .filter(r -> r.getKey() == r.getValue().getWorkflowInstanceKey()) .limit(jobAmount) .collect(Collectors.toList()); assertThat(records) .extracting(r -> r.getValue().getWorkflowInstanceKey()) .containsOnlyElementsOf(workflowInstanceKeys); }
@Test public void shouldActivateJobsFromWorkflow() { // given final int jobAmount = 10; deployWorkflow("foo", "bar", "baz"); final List<Long> workflowInstanceKeys = createWorkflowInstances(jobAmount); // when activating and completing all jobs waitUntil( () -> jobRecords(JobIntent.CREATED).withType("foo").limit(jobAmount).count() == jobAmount); activateJobs("foo", jobAmount).forEach(this::completeJob); waitUntil( () -> jobRecords(JobIntent.CREATED).withType("bar").limit(jobAmount).count() == jobAmount); activateJobs("bar", jobAmount).forEach(this::completeJob); waitUntil( () -> jobRecords(JobIntent.CREATED).withType("baz").limit(jobAmount).count() == jobAmount); activateJobs("baz", jobAmount).forEach(this::completeJob); // then all workflow instances are completed final List<Record<WorkflowInstanceRecordValue>> records = workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .filter(r -> r.getKey() == r.getValue().getWorkflowInstanceKey()) .limit(jobAmount) .collect(Collectors.toList()); assertThat(records) .extracting(r -> r.getValue().getWorkflowInstanceKey()) .containsOnlyElementsOf(workflowInstanceKeys); }
@Test public void shouldCorrelateMessageToAllSubscriptions() { // given testClient.deploy(SINGLE_MESSAGE_WORKFLOW); final long workflowInstanceKey1 = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); final long workflowInstanceKey2 = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); // when testClient.publishMessage("message", "order-123"); // then final List<Record<WorkflowInstanceRecordValue>> events = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.EVENT_TRIGGERED) .withElementId("receive-message") .limit(2) .collect(Collectors.toList()); assertThat(events) .extracting(r -> r.getValue().getWorkflowInstanceKey()) .contains(workflowInstanceKey1, workflowInstanceKey2); }
@Test public void shouldCorrelateMessageToAllSubscriptions() { // given testClient.deploy(SINGLE_MESSAGE_WORKFLOW); final long workflowInstanceKey1 = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); final long workflowInstanceKey2 = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); // when testClient.publishMessage("message", "order-123"); // then final List<Record<WorkflowInstanceRecordValue>> events = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId("receive-message") .limit(2) .collect(Collectors.toList()); assertThat(events) .extracting(r -> r.getValue().getWorkflowInstanceKey()) .contains(workflowInstanceKey1, workflowInstanceKey2); }
.limit(3)) .extracting(Record::getValue) .extracting(v -> tuple(v.getWorkflowInstanceKey(), v.getElementId())) .contains( tuple(workflowInstance1, "a"),
.limit(3)) .extracting(Record::getValue) .extracting(v -> tuple(v.getWorkflowInstanceKey(), v.getElementId())) .contains( tuple(workflowInstance1, "a"),