Search in sources :

Example 1 with TimerRecordValue

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();
}
Also used : TimerRecordValue(io.camunda.zeebe.protocol.record.value.TimerRecordValue) StringJoiner(java.util.StringJoiner) Date(java.util.Date)

Example 2 with TimerRecordValue

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);
}
Also used : TimerRecordValue(io.camunda.zeebe.protocol.record.value.TimerRecordValue) Test(org.junit.Test)

Example 3 with TimerRecordValue

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());
}
Also used : ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) TimerRecordValue(io.camunda.zeebe.protocol.record.value.TimerRecordValue) Test(org.junit.Test)

Example 4 with TimerRecordValue

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());
}
Also used : ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) TimerRecordValue(io.camunda.zeebe.protocol.record.value.TimerRecordValue) Test(org.junit.Test)

Example 5 with TimerRecordValue

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);
}
Also used : Instant(java.time.Instant) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) TimerRecordValue(io.camunda.zeebe.protocol.record.value.TimerRecordValue) Test(org.junit.Test)

Aggregations

TimerRecordValue (io.camunda.zeebe.protocol.record.value.TimerRecordValue)37 Test (org.junit.Test)34 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)24 ProcessInstanceRecordValue (io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue)12 Instant (java.time.Instant)9 EngineRule (io.camunda.zeebe.engine.util.EngineRule)6 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)6 Assertions (io.camunda.zeebe.protocol.record.Assertions)6 Record (io.camunda.zeebe.protocol.record.Record)6 ProcessInstanceIntent (io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent)6 TimerIntent (io.camunda.zeebe.protocol.record.intent.TimerIntent)6 BpmnElementType (io.camunda.zeebe.protocol.record.value.BpmnElementType)6 RecordingExporter (io.camunda.zeebe.test.util.record.RecordingExporter)6 Duration (java.time.Duration)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 Rule (org.junit.Rule)6 TimerInstance (io.camunda.zeebe.engine.state.instance.TimerInstance)3 ProcessBuilder (io.camunda.zeebe.model.bpmn.builder.ProcessBuilder)3 IncidentIntent (io.camunda.zeebe.protocol.record.intent.IncidentIntent)3 RecordingExporterTestWatcher (io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher)3