camunda / zeebe-process-test

Testing project for Camunda Platform 8
40 stars 15 forks source link

Variables from the ThrowError command are ignored #1079

Closed saig0 closed 7 months ago

saig0 commented 7 months ago

Description

Since Zeebe 8.2, I can pass variables with the ThrowError command (ref). When the error is caught in the process, the variables are set as local variables of the BPMN error event.

But, in ZPT these variables are ignored (see the code). As a result, the variables are not available in the error catch event.

Expected behaviour

The variables from the ThrowError command are written to the underlying job command. When the error is caught, the variables are set as local variables of the error catch event.

Reproduction steps

Test code ``` @Test void shouldThrowErrorOnJob() { // given zeebeClient .newDeployCommand() .addProcessModel( Bpmn.createExecutableProcess("simpleProcess") .startEvent() .serviceTask("task", (task) -> task.zeebeJobType("jobType")) .boundaryEvent("error") .error("0xCAFE") .zeebeOutputExpression("error_var", "error_var") .endEvent() .done(), "simpleProcess.bpmn") .send() .join(); zeebeClient .newCreateInstanceCommand() .bpmnProcessId("simpleProcess") .latestVersion() .variables(Map.of("test", 1)) .send() .join(); Awaitility.await() .untilAsserted( () -> { final ActivateJobsResponse activateJobsResponse = zeebeClient .newActivateJobsCommand() .jobType("jobType") .maxJobsToActivate(32) .timeout(Duration.ofMinutes(1)) .workerName("yolo") .fetchVariables(List.of("test")) .send() .join(); final List jobs = activateJobsResponse.getJobs(); assertThat(jobs).isNotEmpty(); final ActivatedJob job = jobs.get(0); // when - then zeebeClient .newThrowErrorCommand(job.getKey()) .errorCode("0xCAFE") .errorMessage("What just happened.") .variable("error_var", "Out of coffee") .send() .join(); Awaitility.await() .untilAsserted( () -> { final Optional> boundaryEvent = StreamSupport.stream( RecordStream.of(zeebeEngine.getRecordStreamSource()) .processInstanceRecords() .spliterator(), false) .filter( r -> r.getIntent() == ProcessInstanceIntent.ELEMENT_COMPLETED) .filter( r -> r.getValue().getBpmnElementType() == BpmnElementType.BOUNDARY_EVENT) .filter(r -> r.getValue().getBpmnEventType() == BpmnEventType.ERROR) .findFirst(); assertThat(boundaryEvent).isNotEmpty(); final var errorVariable = StreamSupport.stream( RecordStream.of(zeebeEngine.getRecordStreamSource()) .variableRecords() .spliterator(), false) .filter(r -> r.getValue().getName().equals("error_var")) .findFirst(); assertThat(errorVariable) .describedAs("Expect that the error variable is set") .isPresent() .hasValueSatisfying( record -> assertThat(record.getValue().getValue()) .isEqualTo("\"Out of coffee\"")); }); }); } ```
Process ![Screenshot from 2024-02-08 06-24-46](https://github.com/camunda/zeebe-process-test/assets/4305769/44362be9-d497-405c-846d-0cf65d119893) ```xml Flow_0qbvp5j Flow_0qbvp5j Flow_1bfv4q9 Flow_0vf49pd Flow_0vf49pd Flow_1bfv4q9 ```

Environment