/** * An entry point for TimerRecordValueAssert to follow AssertJ standard <code>assertThat()</code> statements.<br> * With a static import, one can write directly: <code>assertThat(myTimerRecordValue)</code> and get specific assertion with code completion. * @param actual the TimerRecordValue we want to make assertions on. * @return a new <code>{@link TimerRecordValueAssert}</code> */ @org.assertj.core.util.CheckReturnValue public static TimerRecordValueAssert assertThat(TimerRecordValue actual) { return new TimerRecordValueAssert(actual); } }
@Test public void shouldCreateTimer() { // when testClient.deploy(SIMPLE_MODEL); // then assertThat(RecordingExporter.deploymentRecords(DeploymentIntent.CREATED).exists()).isTrue(); final TimerRecordValue timerRecord = RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst().getValue(); Assertions.assertThat(timerRecord) .hasDueDate(brokerRule.getClock().getCurrentTimeInMillis() + 1000) .hasHandlerFlowNodeId("start_1") .hasElementInstanceKey(NO_ELEMENT_INSTANCE); }
@Test public void shouldContinueWhenTimerIsTriggered() { // given testClient.deploy(WORKFLOW_WITH_TIMERS); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); final Record<WorkflowInstanceRecordValue> gatewayEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementType(BpmnElementType.EVENT_BASED_GATEWAY) .getFirst(); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).exists()).isTrue(); // when brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then final Record<TimerRecordValue> triggeredEvent = RecordingExporter.timerRecords(TimerIntent.TRIGGERED).getFirst(); Assertions.assertThat(triggeredEvent.getValue()) .hasElementInstanceKey(gatewayEvent.getKey()) .hasHandlerFlowNodeId("timer-1"); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.SEQUENCE_FLOW_TAKEN) .withElementId("to-end1") .exists()) .isTrue(); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId(PROCESS_ID) .exists()) .isTrue(); }
@Test public void shouldCreateTimer() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("PT10S")) .endEvent() .done(); testClient.deploy(workflow); testClient.createWorkflowInstance(PROCESS_ID); // when final Record<WorkflowInstanceRecordValue> activatedEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_ACTIVATED) .withElementId("timer") .getFirst(); // then final Record<TimerRecordValue> createdEvent = RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); Assertions.assertThat(createdEvent.getValue()).hasElementInstanceKey(activatedEvent.getKey()); assertThat(createdEvent.getValue().getDueDate()) .isGreaterThan(brokerRule.getClock().getCurrentTimeInMillis()); }
@Test public void shouldUpdateTimerPeriod() { // when long beginTime = brokerRule.getClock().getCurrentTimeInMillis(); testClient.deploy(THREE_SEC_MODEL); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).exists()).isTrue(); brokerRule.getClock().addTime(Duration.ofSeconds(3)); // then TimerRecordValue timerRecord = RecordingExporter.timerRecords(TimerIntent.TRIGGERED).getFirst().getValue(); Assertions.assertThat(timerRecord).hasDueDate(beginTime + 3000); // when beginTime = brokerRule.getClock().getCurrentTimeInMillis(); final BpmnModelInstance slowerModel = Bpmn.createExecutableProcess("process_3") .startEvent("start_4") .timerWithCycle("R2/PT4S") .endEvent("end_4") .done(); testClient.deploy(slowerModel); // then assertThat(RecordingExporter.timerRecords(TimerIntent.CANCELED).getFirst()).isNotNull(); timerRecord = RecordingExporter.timerRecords(TimerIntent.CREATED).skip(2).getFirst().getValue(); Assertions.assertThat(timerRecord).hasDueDate(beginTime + 4000); brokerRule.getClock().addTime(Duration.ofSeconds(3)); assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).limit(1).count()).isEqualTo(1); brokerRule.getClock().addTime(Duration.ofSeconds(1)); assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).limit(2).count()).isEqualTo(2); }
@Test public void shouldContinueWhenTimerIsTriggered() { // given testClient.deploy(WORKFLOW_WITH_TIMERS); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); final Record<WorkflowInstanceRecordValue> gatewayEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.GATEWAY_ACTIVATED) .getFirst(); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).exists()); // when brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then final Record<TimerRecordValue> triggeredEvent = RecordingExporter.timerRecords(TimerIntent.TRIGGERED).getFirst(); Assertions.assertThat(triggeredEvent.getValue()) .hasElementInstanceKey(gatewayEvent.getKey()) .hasHandlerFlowNodeId("timer-1"); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.SEQUENCE_FLOW_TAKEN) .withElementId("to-end1") .exists()) .isTrue(); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId(PROCESS_ID) .exists()); }
@Test public void shouldCreateTimer() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("PT10S")) .endEvent() .done(); testClient.deploy(workflow); testClient.createWorkflowInstance(PROCESS_ID); // when final Record<WorkflowInstanceRecordValue> activatedEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId("timer") .getFirst(); // then final Record<TimerRecordValue> createdEvent = RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); Assertions.assertThat(createdEvent.getValue()).hasElementInstanceKey(activatedEvent.getKey()); assertThat(createdEvent.getValue().getDueDate()) .isGreaterThan(brokerRule.getClock().getCurrentTimeInMillis()); }
@Test public void shouldUpdateTimerPeriod() { // when long beginTime = brokerRule.getClock().getCurrentTimeInMillis(); testClient.deploy(THREE_SEC_MODEL); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).exists()).isTrue(); brokerRule.getClock().addTime(Duration.ofSeconds(3)); // then TimerRecordValue timerRecord = RecordingExporter.timerRecords(TimerIntent.TRIGGERED).getFirst().getValue(); Assertions.assertThat(timerRecord).hasDueDate(beginTime + 3000); // when beginTime = brokerRule.getClock().getCurrentTimeInMillis(); final BpmnModelInstance slowerModel = Bpmn.createExecutableProcess("process_3") .startEvent("start_4") .timerWithCycle("R2/PT4S") .endEvent("end_4") .done(); testClient.deploy(slowerModel); // then assertThat(RecordingExporter.timerRecords(TimerIntent.CANCELED).getFirst()).isNotNull(); timerRecord = RecordingExporter.timerRecords(TimerIntent.CREATED).skip(2).getFirst().getValue(); Assertions.assertThat(timerRecord).hasDueDate(beginTime + 4000); brokerRule.getClock().addTime(Duration.ofSeconds(3)); assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).limit(1).count()).isEqualTo(1); brokerRule.getClock().addTime(Duration.ofSeconds(1)); assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).limit(2).count()).isEqualTo(2); }
@Test public void shouldCreateTimer() { // when testClient.deploy(SIMPLE_MODEL); // then assertThat(RecordingExporter.deploymentRecords(DeploymentIntent.CREATED).exists()).isTrue(); final TimerRecordValue timerRecord = RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst().getValue(); Assertions.assertThat(timerRecord) .hasDueDate(brokerRule.getClock().getCurrentTimeInMillis() + 1000) .hasHandlerFlowNodeId("start_1") .hasElementInstanceKey(NO_ELEMENT_INSTANCE); }
/** * Creates a new instance of <code>{@link io.zeebe.exporter.record.value.TimerRecordValueAssert}</code>. * * @param actual the actual value. * @return the created assertion object. */ @org.assertj.core.util.CheckReturnValue public static io.zeebe.exporter.record.value.TimerRecordValueAssert assertThat(io.zeebe.exporter.record.value.TimerRecordValue actual) { return new io.zeebe.exporter.record.value.TimerRecordValueAssert(actual); }
@Test public void shouldTriggerIfTimeDatePassedOnDeployment() { // given final Instant triggerTime = brokerRule.getClock().getCurrentTime().minusMillis(2000); final BpmnModelInstance model = Bpmn.createExecutableProcess("process") .startEvent("start_2") .timerWithDate(triggerTime.toString()) .endEvent("end_2") .done(); testClient.deploy(model); // then final TimerRecordValue timerRecord = RecordingExporter.timerRecords(TimerIntent.TRIGGERED).getFirst().getValue(); Assertions.assertThat(timerRecord) .hasDueDate(triggerTime.toEpochMilli()) .hasHandlerFlowNodeId("start_2") .hasElementInstanceKey(NO_ELEMENT_INSTANCE); }
@Test public void shouldTriggerIfTimeDatePassedOnDeployment() { // given final Instant triggerTime = brokerRule.getClock().getCurrentTime().minusMillis(2000); final BpmnModelInstance model = Bpmn.createExecutableProcess("process") .startEvent("start_2") .timerWithDate(triggerTime.toString()) .endEvent("end_2") .done(); testClient.deploy(model); // then final TimerRecordValue timerRecord = RecordingExporter.timerRecords(TimerIntent.TRIGGERED).getFirst().getValue(); Assertions.assertThat(timerRecord) .hasDueDate(triggerTime.toEpochMilli()) .hasHandlerFlowNodeId("start_2") .hasElementInstanceKey(NO_ELEMENT_INSTANCE); }
@Test public void shouldTriggerAtSpecifiedTimeDate() { // given final Instant triggerTime = brokerRule.getClock().getCurrentTime().plusMillis(2000); final BpmnModelInstance model = Bpmn.createExecutableProcess("process") .startEvent("start_2") .timerWithDate(triggerTime.toString()) .endEvent("end_2") .done(); testClient.deploy(model); // when brokerRule.getClock().addTime(Duration.ofSeconds(2)); // then final TimerRecordValue timerRecord = RecordingExporter.timerRecords(TimerIntent.TRIGGERED).getFirst().getValue(); Assertions.assertThat(timerRecord) .hasDueDate(triggerTime.toEpochMilli()) .hasHandlerFlowNodeId("start_2") .hasElementInstanceKey(NO_ELEMENT_INSTANCE); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId("end_2") .exists()) .isTrue(); }
@Test public void shouldTriggerAtSpecifiedTimeDate() { // given final Instant triggerTime = brokerRule.getClock().getCurrentTime().plusMillis(2000); final BpmnModelInstance model = Bpmn.createExecutableProcess("process") .startEvent("start_2") .timerWithDate(triggerTime.toString()) .endEvent("end_2") .done(); testClient.deploy(model); // when brokerRule.getClock().addTime(Duration.ofSeconds(2)); // then final TimerRecordValue timerRecord = RecordingExporter.timerRecords(TimerIntent.TRIGGERED).getFirst().getValue(); Assertions.assertThat(timerRecord) .hasDueDate(triggerTime.toEpochMilli()) .hasHandlerFlowNodeId("start_2") .hasElementInstanceKey(NO_ELEMENT_INSTANCE); assertThat( RecordingExporter.workflowInstanceRecords(EVENT_ACTIVATED) .withElementId("end_2") .exists()) .isTrue(); }