Skip to content

Commit

Permalink
merge: #9520
Browse files Browse the repository at this point in the history
9520: Writer timer triggered event with process instance key r=remcowesterhoud a=saig0

## Description

* minimal change in the timer processor to write the timer `triggered` event with the key of the created process instance 

## Related issues

closes #9519



Co-authored-by: Philipp Ossler <philipp.ossler@gmail.com>
  • Loading branch information
zeebe-bors-camunda[bot] and saig0 committed Jun 9, 2022
2 parents eb56202 + b6e5b35 commit fa7386b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ public void processRecord(
processState.getFlowElement(
processDefinitionKey, timer.getTargetElementIdBuffer(), ExecutableCatchEvent.class);
if (isStartEvent(elementInstanceKey)) {
stateWriter.appendFollowUpEvent(record.getKey(), TimerIntent.TRIGGERED, timer);
final long processInstanceKey = keyGenerator.nextKey();
timer.setProcessInstanceKey(processInstanceKey);
stateWriter.appendFollowUpEvent(record.getKey(), TimerIntent.TRIGGERED, timer);
eventHandle.activateProcessInstanceForStartEvent(
processDefinitionKey, processInstanceKey, timer.getTargetElementIdBuffer(), NO_VARIABLES);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -877,4 +877,47 @@ public void shouldTriggerOnlyTimerStartEvent() {
.extracting(r -> r.getValue().getElementId())
.containsOnly("timer_start");
}

@Test
public void shouldWriteTriggeredEventWithProcessInstanceKey() {
// given
final var deployedProcess =
engine
.deployment()
.withXmlResource(SIMPLE_MODEL)
.deploy()
.getValue()
.getProcessesMetadata()
.get(0);

final long processDefinitionKey = deployedProcess.getProcessDefinitionKey();

assertThat(
RecordingExporter.timerRecords(TimerIntent.CREATED)
.withProcessDefinitionKey(processDefinitionKey)
.exists())
.isTrue();

// when
engine.increaseTime(Duration.ofSeconds(2));

// then
final var processInstanceKey =
RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_ACTIVATED)
.withElementType(BpmnElementType.PROCESS)
.withProcessDefinitionKey(processDefinitionKey)
.getFirst()
.getKey();

final var timerTriggered =
RecordingExporter.timerRecords(TimerIntent.TRIGGERED)
.withProcessDefinitionKey(processDefinitionKey)
.getFirst();

Assertions.assertThat(timerTriggered.getValue())
.hasProcessDefinitionKey(processDefinitionKey)
.hasProcessInstanceKey(processInstanceKey)
.hasElementInstanceKey(-1L)
.hasTargetElementId("start_1");
}
}

0 comments on commit fa7386b

Please sign in to comment.