Skip to content

Commit

Permalink
merge: #12349
Browse files Browse the repository at this point in the history
12349: [Backport stable/8.2] Support numbers as error/escalation codes r=remcowesterhoud a=backport-action

# Description
Backport of #12327 to `stable/8.2`.

relates to #12326

Co-authored-by: Remco Westerhoud <[email protected]>
  • Loading branch information
zeebe-bors-camunda[bot] and remcowesterhoud authored Apr 11, 2023
2 parents 0c30137 + f560816 commit c1fb4e4
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
*/
package io.camunda.zeebe.engine.processing.deployment.model.transformer;

import io.camunda.zeebe.el.EvaluationResult;
import io.camunda.zeebe.el.Expression;
import io.camunda.zeebe.el.ResultType;
import io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableError;
import io.camunda.zeebe.engine.processing.deployment.model.transformation.ModelElementTransformer;
import io.camunda.zeebe.engine.processing.deployment.model.transformation.TransformContext;
Expand Down Expand Up @@ -38,12 +36,7 @@ public void transform(final Error element, final TransformContext context) {

error.setErrorCodeExpression(errorCodeExpression);
if (errorCodeExpression.isStatic()) {
final EvaluationResult errorCodeResult =
expressionLanguage.evaluateExpression(errorCodeExpression, variable -> null);

if (errorCodeResult.getType() == ResultType.STRING) {
error.setErrorCode(BufferUtil.wrapString(errorCodeResult.getString()));
}
error.setErrorCode(BufferUtil.wrapString(element.getErrorCode()));
}

context.addError(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
*/
package io.camunda.zeebe.engine.processing.deployment.model.transformer;

import io.camunda.zeebe.el.EvaluationResult;
import io.camunda.zeebe.el.Expression;
import io.camunda.zeebe.el.ExpressionLanguage;
import io.camunda.zeebe.el.ResultType;
import io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableEscalation;
import io.camunda.zeebe.engine.processing.deployment.model.transformation.ModelElementTransformer;
import io.camunda.zeebe.engine.processing.deployment.model.transformation.TransformContext;
Expand All @@ -35,13 +33,7 @@ public void transform(final Escalation element, final TransformContext context)

escalation.setEscalationCodeExpression(escalationCodeExpression);
if (escalationCodeExpression.isStatic()) {
final EvaluationResult escalationCodeResult =
expressionLanguage.evaluateExpression(escalationCodeExpression, variable -> null);

if (escalationCodeResult.getType() == ResultType.STRING) {
final String escalationCode = escalationCodeResult.getString();
escalation.setEscalationCode(BufferUtil.wrapString(escalationCode));
}
escalation.setEscalationCode(BufferUtil.wrapString(element.getEscalationCode()));
}
}
context.addEscalation(escalation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public void shouldThrowErrorWithVariables() {
final List<Record<VariableRecordValue>> variableRecords =
RecordingExporter.variableRecords()
.withProcessInstanceKey(processInstanceKey)
.limit(r -> r.getValue().getName().equals("foo"))
.collect(Collectors.toList());

final List<Record<ProcessInstanceRecordValue>> errorEvents =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class ErrorEventTest {
private static final String PROCESS_ID = "wf";
private static final String JOB_TYPE = "test";
private static final String ERROR_CODE = "ERROR";
private static final String ERROR_CODE_NUMBER = "404";

private static final BpmnModelInstance SINGLE_BOUNDARY_EVENT =
process(
Expand Down Expand Up @@ -144,6 +145,52 @@ public void shouldCatchErrorEventsByErrorCode() {
.containsOnly("error-2");
}

@Test
public void shouldCatchErrorEventsByNumericErrorCode() {
// Regression for https://github.com/camunda/zeebe/issues/12326
// given
ENGINE
.deployment()
.withXmlResource(
process(
serviceTask ->
serviceTask.boundaryEvent("error", b -> b.error(ERROR_CODE_NUMBER).endEvent())))
.deploy();

final var processInstanceKey = ENGINE.processInstance().ofBpmnProcessId(PROCESS_ID).create();

// when
ENGINE
.job()
.ofInstance(processInstanceKey)
.withType(JOB_TYPE)
.withErrorCode(ERROR_CODE_NUMBER)
.throwError();

// then
assertThat(
RecordingExporter.processInstanceRecords()
.withProcessInstanceKey(processInstanceKey)
.limitToProcessInstanceCompleted())
.extracting(r -> r.getValue().getBpmnElementType(), Record::getIntent)
.containsSubsequence(
tuple(BpmnElementType.SERVICE_TASK, ProcessInstanceIntent.ELEMENT_TERMINATING),
tuple(BpmnElementType.SERVICE_TASK, ProcessInstanceIntent.ELEMENT_TERMINATED),
tuple(BpmnElementType.BOUNDARY_EVENT, ProcessInstanceIntent.ELEMENT_ACTIVATING),
tuple(BpmnElementType.BOUNDARY_EVENT, ProcessInstanceIntent.ELEMENT_ACTIVATED),
tuple(BpmnElementType.BOUNDARY_EVENT, ProcessInstanceIntent.COMPLETE_ELEMENT),
tuple(BpmnElementType.BOUNDARY_EVENT, ProcessInstanceIntent.ELEMENT_COMPLETING),
tuple(BpmnElementType.BOUNDARY_EVENT, ProcessInstanceIntent.ELEMENT_COMPLETED),
tuple(BpmnElementType.SEQUENCE_FLOW, ProcessInstanceIntent.SEQUENCE_FLOW_TAKEN),
tuple(BpmnElementType.END_EVENT, ProcessInstanceIntent.ELEMENT_ACTIVATING),
tuple(BpmnElementType.END_EVENT, ProcessInstanceIntent.ELEMENT_ACTIVATED),
tuple(BpmnElementType.END_EVENT, ProcessInstanceIntent.ELEMENT_COMPLETING),
tuple(BpmnElementType.END_EVENT, ProcessInstanceIntent.ELEMENT_COMPLETED),
tuple(BpmnElementType.PROCESS, ProcessInstanceIntent.COMPLETE_ELEMENT),
tuple(BpmnElementType.PROCESS, ProcessInstanceIntent.ELEMENT_COMPLETING),
tuple(BpmnElementType.PROCESS, ProcessInstanceIntent.ELEMENT_COMPLETED));
}

@Test
public void shouldCatchErrorEventsOnBoundaryEventWithoutErrorRef() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class EscalationEventTest {
private static final String TASK_ELEMENT_ID = "task";
private static final String PROCESS_ID = "wf";
private static final String ESCALATION_CODE = "ESCALATION";
private static final String ESCALATION_CODE_NUMBER = "404";
private static final String THROW_ELEMENT_ID = "throw";
private static final String CATCH_ELEMENT_ID = "catch";

Expand Down Expand Up @@ -155,6 +156,54 @@ public void shouldCatchEscalationOnBoundaryEventWithoutEscalationCode() {
assertIsEscalated(processInstanceKey, CATCH_ELEMENT_ID, THROW_ELEMENT_ID, ESCALATION_CODE);
}

@Test
public void shouldCatchEscalationOnBoundaryEventWithNumericEscalationCode() {
// Regression for https://github.com/camunda/zeebe/issues/12326
// given
final var process =
Bpmn.createExecutableProcess(PROCESS_ID)
.startEvent()
.subProcess(
"subprocess",
s ->
s.embeddedSubProcess()
.startEvent()
.intermediateThrowEvent(
THROW_ELEMENT_ID, i -> i.escalation(ESCALATION_CODE_NUMBER)))
.boundaryEvent(CATCH_ELEMENT_ID, AbstractBoundaryEventBuilder::escalation)
.manualTask(TASK_ELEMENT_ID)
.endEvent()
.done();
ENGINE.deployment().withXmlResource(process).deploy();

// when
final var processInstanceKey = ENGINE.processInstance().ofBpmnProcessId(PROCESS_ID).create();

// then
assertThat(
RecordingExporter.processInstanceRecords()
.withProcessInstanceKey(processInstanceKey)
.limitToProcessInstanceCompleted())
.extracting(r -> r.getValue().getBpmnElementType(), Record::getIntent)
.containsSubsequence(
tuple(BpmnElementType.SUB_PROCESS, ProcessInstanceIntent.ELEMENT_TERMINATING),
tuple(
BpmnElementType.INTERMEDIATE_THROW_EVENT,
ProcessInstanceIntent.ELEMENT_TERMINATING),
tuple(
BpmnElementType.INTERMEDIATE_THROW_EVENT, ProcessInstanceIntent.ELEMENT_TERMINATED),
tuple(BpmnElementType.SUB_PROCESS, ProcessInstanceIntent.ELEMENT_TERMINATED),
tuple(BpmnElementType.BOUNDARY_EVENT, ProcessInstanceIntent.ELEMENT_COMPLETING),
tuple(BpmnElementType.BOUNDARY_EVENT, ProcessInstanceIntent.ELEMENT_COMPLETED),
tuple(BpmnElementType.MANUAL_TASK, ProcessInstanceIntent.ELEMENT_COMPLETING),
tuple(BpmnElementType.MANUAL_TASK, ProcessInstanceIntent.ELEMENT_COMPLETED),
tuple(BpmnElementType.PROCESS, ProcessInstanceIntent.ELEMENT_COMPLETING),
tuple(BpmnElementType.PROCESS, ProcessInstanceIntent.ELEMENT_COMPLETED));

assertIsEscalated(
processInstanceKey, CATCH_ELEMENT_ID, THROW_ELEMENT_ID, ESCALATION_CODE_NUMBER);
}

@Test
public void shouldCatchEscalationInsideMultiInstanceSubprocess() {
// given
Expand Down

0 comments on commit c1fb4e4

Please sign in to comment.