Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport stable/8.4] fix: Set variables from ThrowError command #1083

Merged
4 commits merged into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void completeJob(

final String variables = request.getVariables();
if (!variables.isEmpty()) {
jobRecord.setVariables(BufferUtil.wrapArray(MsgPackConverter.convertToMsgPack(variables)));
jobRecord.setVariables(convertVariablesToMessagePack(variables));
}

writer.writeCommandWithKey(request.getJobKey(), jobRecord, recordMetadata);
Expand Down Expand Up @@ -371,6 +371,11 @@ public void throwError(
jobRecord.setErrorCode(BufferUtil.wrapString(request.getErrorCode()));
jobRecord.setErrorMessage(request.getErrorMessage());

final String variables = request.getVariables();
if (!variables.isEmpty()) {
jobRecord.setVariables(convertVariablesToMessagePack(variables));
}

writer.writeCommandWithKey(request.getJobKey(), jobRecord, recordMetadata);
}

Expand All @@ -395,8 +400,7 @@ public void publishMessage(
messageRecord.setTimeToLive(request.getTimeToLive());
final String variables = request.getVariables();
if (!variables.isEmpty()) {
messageRecord.setVariables(
BufferUtil.wrapArray(MsgPackConverter.convertToMsgPack(variables)));
messageRecord.setVariables(convertVariablesToMessagePack(variables));
}

writer.writeCommandWithoutKey(messageRecord, recordMetadata);
Expand Down Expand Up @@ -437,8 +441,7 @@ public void setVariables(

final String variables = request.getVariables();
if (!variables.isEmpty()) {
variableDocumentRecord.setVariables(
BufferUtil.wrapArray(MsgPackConverter.convertToMsgPack(variables)));
variableDocumentRecord.setVariables(convertVariablesToMessagePack(variables));
}

variableDocumentRecord.setScopeKey(request.getElementInstanceKey());
Expand Down Expand Up @@ -591,8 +594,7 @@ public void broadcastSignal(
final SignalRecord command = new SignalRecord().setSignalName(request.getSignalName());

if (!request.getVariables().isEmpty()) {
command.setVariables(
BufferUtil.wrapArray(MsgPackConverter.convertToMsgPack(request.getVariables())));
command.setVariables(convertVariablesToMessagePack(request.getVariables()));
}

writer.writeCommandWithoutKey(
Expand Down Expand Up @@ -624,9 +626,7 @@ final var record = new ProcessInstanceModificationRecord();
instruction.addVariableInstruction(
new ProcessInstanceModificationVariableInstruction()
.setElementId(variable.getScopeId())
.setVariables(
BufferUtil.wrapArray(
MsgPackConverter.convertToMsgPack(variable.getVariables()))));
.setVariables(convertVariablesToMessagePack(variable.getVariables())));
}

record.addActivateInstruction(instruction);
Expand Down Expand Up @@ -663,8 +663,7 @@ private ProcessInstanceCreationRecord createProcessInstanceCreationRecord(

final String variables = request.getVariables();
if (!variables.isEmpty()) {
processInstanceCreationRecord.setVariables(
BufferUtil.wrapArray(MsgPackConverter.convertToMsgPack(variables)));
processInstanceCreationRecord.setVariables(convertVariablesToMessagePack(variables));
}
return processInstanceCreationRecord;
}
Expand All @@ -681,12 +680,16 @@ private DecisionEvaluationRecord createDecisionEvaluationRecord(

final String variables = request.getVariables();
if (!variables.isEmpty()) {
record.setVariables(BufferUtil.wrapArray(MsgPackConverter.convertToMsgPack(variables)));
record.setVariables(convertVariablesToMessagePack(variables));
}

return record;
}

private static DirectBuffer convertVariablesToMessagePack(final String variables) {
return BufferUtil.wrapArray(MsgPackConverter.convertToMsgPack(variables));
}

public String getAddress() {
return "0.0.0.0:" + port;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ void shouldThrowErrorOnJob() {
.serviceTask("task", (task) -> task.zeebeJobType("jobType"))
.boundaryEvent("error")
.error("0xCAFE")
.zeebeOutputExpression("error_var", "error_var")
.endEvent()
.done(),
"simpleProcess.bpmn")
Expand All @@ -782,10 +783,10 @@ void shouldThrowErrorOnJob() {
.newCreateInstanceCommand()
.bpmnProcessId("simpleProcess")
.latestVersion()
.variables(Map.of("test", 1))
.send()
.join();

// when
Awaitility.await()
.untilAsserted(
() -> {
Expand All @@ -796,42 +797,57 @@ void shouldThrowErrorOnJob() {
.maxJobsToActivate(32)
.timeout(Duration.ofMinutes(1))
.workerName("yolo")
.fetchVariables(List.of("test"))
.send()
.join();

final List<ActivatedJob> 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<Record<ProcessInstanceRecordValue>> 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();
// then
Awaitility.await()
.untilAsserted(
() -> {
final Optional<Record<ProcessInstanceRecordValue>> 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();
});
assertThat(boundaryEvent)
.describedAs("Expect that the error boundary event is completed")
.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\""));
});
}

Expand Down
Loading