public Record<WorkflowInstanceRecordValue> receiveElementInState( final String elementId, final WorkflowInstanceIntent intent) { return receiveWorkflowInstances().withIntent(intent).withElementId(elementId).getFirst(); }
public Record<WorkflowInstanceRecordValue> receiveElementInState( final String elementId, final WorkflowInstanceIntent intent) { return receiveWorkflowInstances().withIntent(intent).withElementId(elementId).getFirst(); }
public Record<WorkflowInstanceRecordValue> receiveFirstWorkflowInstanceEvent( final long wfInstanceKey, final String elementId, final Intent intent) { return receiveWorkflowInstances() .withIntent(intent) .withWorkflowInstanceKey(wfInstanceKey) .withElementId(elementId) .getFirst(); }
public Record<WorkflowInstanceRecordValue> receiveFirstWorkflowInstanceEvent( final long wfInstanceKey, final String elementId, final Intent intent) { return receiveWorkflowInstances() .withIntent(intent) .withWorkflowInstanceKey(wfInstanceKey) .withElementId(elementId) .getFirst(); }
public WorkflowInstanceAssert hasElementPayload( String elementId, String key, Object expectedValue) { final Optional<Record<WorkflowInstanceRecordValue>> record = RecordingExporter.workflowInstanceRecords() .withWorkflowInstanceKey(workflowInstanceKey) .withElementId(elementId) .filter(r -> ELEMENT_PASSED_INTENTS.contains(r.getMetadata().getIntent())) .findFirst(); if (record.isPresent()) { hasPayload(record.get(), key, expectedValue); } else { failWithMessage("Expected <%s> to contain payload but element was not passed", elementId); } return this; }
public WorkflowInstanceAssert hasElementPayload( String elementId, String key, Object expectedValue) { final Optional<Record<WorkflowInstanceRecordValue>> record = RecordingExporter.workflowInstanceRecords() .withWorkflowInstanceKey(workflowInstanceKey) .withElementId(elementId) .filter(r -> ELEMENT_PASSED_INTENTS.contains(r.getMetadata().getIntent())) .findFirst(); if (record.isPresent()) { hasPayload(record.get(), key, expectedValue); } else { failWithMessage("Expected <%s> to contain payload but element was not passed", elementId); } return this; }
private void assertThatWorkflowInstanceCompletedAfter( String elementId, WorkflowInstanceIntent intent) { final Record<WorkflowInstanceRecordValue> lastEvent = RecordingExporter.workflowInstanceRecords(intent).withElementId(elementId).getFirst(); final Record<WorkflowInstanceRecordValue> completedEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId(PROCESS_ID) .getFirst(); assertThat(completedEvent.getPosition()).isGreaterThan(lastEvent.getPosition()); } }
private void assertThatWorkflowInstanceCompletedAfter( String elementId, WorkflowInstanceIntent intent) { final Record<WorkflowInstanceRecordValue> lastEvent = RecordingExporter.workflowInstanceRecords(intent).withElementId(elementId).getFirst(); final Record<WorkflowInstanceRecordValue> completedEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId(PROCESS_ID) .getFirst(); assertThat(completedEvent.getPosition()).isGreaterThan(lastEvent.getPosition()); } }
@Test public void shouldCompleteTimerEvent() { // given testClient.deploy(SINGLE_TIMER_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID); // when final Record<WorkflowInstanceRecordValue> activatedEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_ACTIVATED) .withElementId("timer") .getFirst(); brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then final Record<WorkflowInstanceRecordValue> completedEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_TRIGGERED) .withElementId("timer") .getFirst(); assertThat(completedEvent.getKey()).isEqualTo(activatedEvent.getKey()); assertThat(completedEvent.getValue()).isEqualTo(activatedEvent.getValue()); }
@Test public void shouldCompleteTimerEvent() { // given testClient.deploy(SINGLE_TIMER_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID); // when final Record<WorkflowInstanceRecordValue> activatedEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId("timer") .getFirst(); brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then final Record<WorkflowInstanceRecordValue> completedEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId("timer") .getFirst(); assertThat(completedEvent.getKey()).isEqualTo(activatedEvent.getKey()); assertThat(completedEvent.getValue()).isEqualTo(activatedEvent.getValue()); }
@Test public void shouldTriggerHandlerNodeWhenAttachedToActivity() { // given testClient.deploy(BOUNDARY_EVENT_WORKFLOW); testClient.createWorkflowInstance("process"); // when RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); brokerRule.getClock().addTime(Duration.ofSeconds(10)); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_TRIGGERING) .withElementId("timer") .getFirst()) .isNotNull(); }
@Test public void shouldTriggerHandlerNodeWhenAttachedToActivity() { // given testClient.deploy(BOUNDARY_EVENT_WORKFLOW); testClient.createWorkflowInstance("process"); // when RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); brokerRule.getClock().addTime(Duration.ofSeconds(10)); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETING) .withElementId("timer") .getFirst()) .isNotNull(); }
@Test public void shouldRecreateATimerForTheSpecifiedAmountOfRepetitions() { // given testClient.deploy(TWO_REPS_CYCLE_WORKFLOW); brokerRule.getClock().pinCurrentTime(); testClient.createWorkflowInstance(PROCESS_ID); // when assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst()).isNotNull(); brokerRule.getClock().addTime(Duration.ofSeconds(5)); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2)).hasSize(2); brokerRule.getClock().addTime(Duration.ofSeconds(5)); testClient.completeJobOfType("type"); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId(PROCESS_ID) .exists()) .isTrue(); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).count()).isEqualTo(2); }
@Test public void shouldCreateTimerBasedOnBoundaryEvent() { // given testClient.deploy(BOUNDARY_EVENT_WORKFLOW); brokerRule.getClock().pinCurrentTime(); final long nowMs = brokerRule.getClock().getCurrentTimeInMillis(); testClient.createWorkflowInstance("process"); // when final Record<TimerRecordValue> timerCreatedRecord = RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); final Record<WorkflowInstanceRecordValue> activityRecord = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId("task") .getFirst(); // then assertThat(timerCreatedRecord.getValue().getDueDate()).isEqualTo(nowMs + 1000); assertThat(timerCreatedRecord.getValue().getElementInstanceKey()) .isEqualTo(activityRecord.getKey()); assertThat(timerCreatedRecord.getValue().getHandlerFlowNodeId()).isEqualTo("timer"); }
@Test public void shouldWriteEntireEventOnCancel() { // given testClient.deploy(WORKFLOW); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); final io.zeebe.exporter.record.Record<WorkflowInstanceRecordValue> activatedEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId(PROCESS_ID) .getFirst(); // when final ExecuteCommandResponse response = cancelWorkflowInstance(workflowInstanceKey); // then MsgPackUtil.assertEqualityExcluding( response.getRawValue(), activatedEvent.getValue().toJson(), "payload"); final io.zeebe.exporter.record.Record<WorkflowInstanceRecordValue> cancelingEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_TERMINATING) .withElementId(PROCESS_ID) .getFirst(); assertThat(cancelingEvent.getValue()).isEqualTo(activatedEvent.getValue()); }
@Test public void test() { // given testClient.deploy(scenario.modelInstance()); // when scenario.executeInstance(); // then final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords() .withBpmnProcessId(scenario.processId()) .limitToWorkflowInstanceCompleted() .withElementId(scenario.elementId()) .asList(); assertThat(records) .extracting(r -> r.getValue().getBpmnElementType()) .isNotEmpty() .containsOnly(scenario.elementType()); }
@Test public void shouldOccurEndEvent() { // given testClient.deploy(Bpmn.createExecutableProcess(PROCESS_ID).startEvent().endEvent("foo").done()); // when final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); // then assertThat( RecordingExporter.workflowInstanceRecords() .limitToWorkflowInstanceCompleted() .withElementId("foo")) .extracting(r -> r.getMetadata().getIntent()) .containsExactly( WorkflowInstanceIntent.EVENT_ACTIVATING, WorkflowInstanceIntent.EVENT_ACTIVATED); assertWorkflowInstanceRecord( workflowInstanceKey, "foo", testClient.receiveFirstWorkflowInstanceEvent(WorkflowInstanceIntent.EVENT_ACTIVATED)); }
@Test public void test() { // given testClient.deploy(scenario.modelInstance()); // when scenario.executeInstance(); // then final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords() .withBpmnProcessId(scenario.processId()) .limitToWorkflowInstanceCompleted() .withElementId(scenario.elementId()) .asList(); assertThat(records) .extracting(r -> r.getValue().getBpmnElementType()) .isNotEmpty() .containsOnly(scenario.elementType()); }
@Test public void shouldCreateIncidentIfCorrelationKeyNotFound() { // when final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); final Record<WorkflowInstanceRecordValue> failureEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_ACTIVATED) .withElementId("catch") .getFirst(); // then final Record<IncidentRecordValue> incidentRecord = RecordingExporter.incidentRecords(IncidentIntent.CREATED).getFirst(); Assertions.assertThat(incidentRecord.getValue()) .hasErrorType(ErrorType.EXTRACT_VALUE_ERROR.name()) .hasErrorMessage("Failed to extract the correlation-key by '$.orderId': no value found") .hasBpmnProcessId(PROCESS_ID) .hasWorkflowInstanceKey(workflowInstanceKey) .hasElementId("catch") .hasElementInstanceKey(failureEvent.getKey()) .hasJobKey(-1L); }
@Test public void shouldCreateIncidentIfMessageCorrelationKeyNotFound() { // when final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, MsgPackUtil.asMsgPack("key-1", "k1")); final Record<WorkflowInstanceRecordValue> failureEvent = RecordingExporter.workflowInstanceRecords(failureEventIntent) .withElementId(elementId) .getFirst(); // then final Record<IncidentRecordValue> incidentRecord = RecordingExporter.incidentRecords(IncidentIntent.CREATED).getFirst(); Assertions.assertThat(incidentRecord.getValue()) .hasErrorType(ErrorType.EXTRACT_VALUE_ERROR.name()) .hasErrorMessage("Failed to extract the correlation-key by '$.key-2': no value found") .hasBpmnProcessId(PROCESS_ID) .hasWorkflowInstanceKey(workflowInstanceKey) .hasElementId(failureEvent.getValue().getElementId()) .hasElementInstanceKey(failureEvent.getKey()) .hasJobKey(-1L); }