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