use of io.camunda.zeebe.protocol.record.value.TimerRecordValue in project zeebe-process-test by camunda.
the class RecordStreamLogger method logTimerRecordValue.
private String logTimerRecordValue(final Record<?> record) {
final TimerRecordValue value = (TimerRecordValue) record.getValue();
final StringJoiner joiner = new StringJoiner(", ", "", "");
joiner.add(String.format("(Element id: %s)", value.getTargetElementId()));
joiner.add(String.format("(Due date: %s)", new Date(value.getDueDate())));
return joiner.toString();
}
use of io.camunda.zeebe.protocol.record.value.TimerRecordValue in project zeebe-exporter-protobuf by camunda-community-hub.
the class RecordTransformTest method shouldTransformTimer.
@Test
public void shouldTransformTimer() {
// given
final TimerRecordValue timerRecordValue = mockTimerRecordValue();
final Record<TimerRecordValue> mockedRecord = mockRecord(timerRecordValue, ValueType.TIMER, TimerIntent.CREATED);
// when
final Schema.TimerRecord timerRecord = (Schema.TimerRecord) RecordTransformer.toProtobufMessage(mockedRecord);
// then
assertMetadata(timerRecord.getMetadata(), "TIMER", "CREATED");
assertThat(timerRecord.getDueDate()).isEqualTo(1000L);
assertThat(timerRecord.getRepetitions()).isEqualTo(1);
assertThat(timerRecord.getElementInstanceKey()).isEqualTo(1L);
assertThat(timerRecord.getTargetElementId()).isEqualTo("timerCatch");
assertThat(timerRecord.getProcessInstanceKey()).isEqualTo(2L);
assertThat(timerRecord.getProcessDefinitionKey()).isEqualTo(3L);
}
use of io.camunda.zeebe.protocol.record.value.TimerRecordValue in project zeebe by camunda.
the class TimerCatchEventTest method shouldCreateTimerFromFeelExpression.
@Test
public void shouldCreateTimerFromFeelExpression() {
// given
final BpmnModelInstance process = Bpmn.createExecutableProcess("shouldCreateTimer").startEvent().intermediateCatchEvent("timer", c -> c.timerWithDurationExpression("\"PT10S\"")).endEvent().done();
ENGINE.deployment().withXmlResource(process).deploy();
final long processInstanceKey = ENGINE.processInstance().ofBpmnProcessId("shouldCreateTimer").create();
// when
final Record<ProcessInstanceRecordValue> activatedEvent = RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_ACTIVATED).withProcessInstanceKey(processInstanceKey).withElementId("timer").getFirst();
// then
final Record<TimerRecordValue> createdEvent = RecordingExporter.timerRecords(TimerIntent.CREATED).withProcessInstanceKey(processInstanceKey).getFirst();
Assertions.assertThat(createdEvent.getValue()).hasElementInstanceKey(activatedEvent.getKey()).hasProcessInstanceKey(processInstanceKey);
assertThat(createdEvent.getValue().getDueDate()).isBetween(ENGINE.getClock().getCurrentTimeInMillis(), createdEvent.getTimestamp() + Duration.ofSeconds(10).toMillis());
}
use of io.camunda.zeebe.protocol.record.value.TimerRecordValue in project zeebe by camunda.
the class TimerCatchEventTest method shouldCreateTimer.
@Test
public void shouldCreateTimer() {
// given
final BpmnModelInstance process = Bpmn.createExecutableProcess("shouldCreateTimer").startEvent().intermediateCatchEvent("timer", c -> c.timerWithDuration("PT10S")).endEvent().done();
ENGINE.deployment().withXmlResource(process).deploy();
final long processInstanceKey = ENGINE.processInstance().ofBpmnProcessId("shouldCreateTimer").create();
// when
final Record<ProcessInstanceRecordValue> activatedEvent = RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_ACTIVATED).withProcessInstanceKey(processInstanceKey).withElementId("timer").getFirst();
// then
final Record<TimerRecordValue> createdEvent = RecordingExporter.timerRecords(TimerIntent.CREATED).withProcessInstanceKey(processInstanceKey).getFirst();
Assertions.assertThat(createdEvent.getValue()).hasElementInstanceKey(activatedEvent.getKey()).hasProcessInstanceKey(processInstanceKey);
assertThat(createdEvent.getValue().getDueDate()).isBetween(ENGINE.getClock().getCurrentTimeInMillis(), createdEvent.getTimestamp() + Duration.ofSeconds(10).toMillis());
}
use of io.camunda.zeebe.protocol.record.value.TimerRecordValue in project zeebe by camunda.
the class TimerStartEventTest method shouldTriggerIfTimeDatePassedOnDeployment.
@Test
public void shouldTriggerIfTimeDatePassedOnDeployment() {
// given
final Instant triggerTime = Instant.now().plusMillis(2000);
final BpmnModelInstance model = Bpmn.createExecutableProcess("process").startEvent("start_2").timerWithDate(triggerTime.toString()).endEvent("end_2").done();
final var deployedProcess = engine.deployment().withXmlResource(model).deploy().getValue().getProcessesMetadata().get(0);
// when
engine.increaseTime(Duration.ofMillis(2000L));
// then
final TimerRecordValue timerRecord = RecordingExporter.timerRecords(TimerIntent.TRIGGERED).withProcessDefinitionKey(deployedProcess.getProcessDefinitionKey()).getFirst().getValue();
Assertions.assertThat(timerRecord).hasDueDate(triggerTime.toEpochMilli()).hasTargetElementId("start_2").hasElementInstanceKey(TimerInstance.NO_ELEMENT_INSTANCE);
}
Aggregations