@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 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 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 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 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(); }
@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); }