public Record<TimerRecordValue> receiveTimerRecord(String handlerNodeId, TimerIntent intent) { return receiveTimerRecords().withIntent(intent).withHandlerNodeId(handlerNodeId).getFirst(); }
public Record<TimerRecordValue> receiveTimerRecord(String handlerNodeId, TimerIntent intent) { return receiveTimerRecords().withIntent(intent).withHandlerNodeId(handlerNodeId).getFirst(); }
@Test public void shouldTriggerTimer() { // given testClient.deploy(SINGLE_TIMER_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID); // when final Record<TimerRecordValue> createdEvent = RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then final Record<TimerRecordValue> triggeredEvent = RecordingExporter.timerRecords(TimerIntent.TRIGGERED).getFirst(); assertThat(triggeredEvent.getKey()).isEqualTo(createdEvent.getKey()); assertThat(triggeredEvent.getValue()).isEqualTo(createdEvent.getValue()); assertThat(Duration.between(createdEvent.getTimestamp(), triggeredEvent.getTimestamp())) .isGreaterThanOrEqualTo(Duration.ofMillis(100)); }
@Test public void shouldTriggerTimer() { // given testClient.deploy(SINGLE_TIMER_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID); // when final Record<TimerRecordValue> createdEvent = RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then final Record<TimerRecordValue> triggeredEvent = RecordingExporter.timerRecords(TimerIntent.TRIGGERED).getFirst(); assertThat(triggeredEvent.getKey()).isEqualTo(createdEvent.getKey()); assertThat(triggeredEvent.getValue()).isEqualTo(createdEvent.getValue()); assertThat(Duration.between(createdEvent.getTimestamp(), triggeredEvent.getTimestamp())) .isGreaterThanOrEqualTo(Duration.ofMillis(100)); }
@Test public void shouldTriggerHandlerNodeWhenAttachedToActivity() { // given testClient.deploy(BOUNDARY_EVENT_WORKFLOW); testClient.createWorkflowInstance("process"); // when RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); brokerRule.getClock().addTime(Duration.ofSeconds(10)); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_TRIGGERING) .withElementId("timer") .getFirst()) .isNotNull(); }
@Test public void shouldTriggerHandlerNodeWhenAttachedToActivity() { // given testClient.deploy(BOUNDARY_EVENT_WORKFLOW); testClient.createWorkflowInstance("process"); // when RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); brokerRule.getClock().addTime(Duration.ofSeconds(10)); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETING) .withElementId("timer") .getFirst()) .isNotNull(); }
@Test public void shouldRecreateATimerForTheSpecifiedAmountOfRepetitions() { // given testClient.deploy(TWO_REPS_CYCLE_WORKFLOW); brokerRule.getClock().pinCurrentTime(); testClient.createWorkflowInstance(PROCESS_ID); // when assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst()).isNotNull(); brokerRule.getClock().addTime(Duration.ofSeconds(5)); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2)).hasSize(2); brokerRule.getClock().addTime(Duration.ofSeconds(5)); testClient.completeJobOfType("type"); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId(PROCESS_ID) .exists()) .isTrue(); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).count()).isEqualTo(2); }
@Test public void shouldRecreateATimerForTheSpecifiedAmountOfRepetitions() { // given testClient.deploy(TWO_REPS_CYCLE_WORKFLOW); brokerRule.getClock().pinCurrentTime(); testClient.createWorkflowInstance(PROCESS_ID); // when assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst()).isNotNull(); brokerRule.getClock().addTime(Duration.ofSeconds(5)); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2)).hasSize(2); brokerRule.getClock().addTime(Duration.ofSeconds(5)); testClient.completeJobOfType("type"); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId(PROCESS_ID) .exists()) .isTrue(); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).count()).isEqualTo(2); }
@Test public void shouldRecreateATimerInfinitely() { // given final int expectedRepetitions = 5; testClient.deploy(INFINITE_CYCLE_WORKFLOW); brokerRule.getClock().pinCurrentTime(); testClient.createWorkflowInstance(PROCESS_ID); // when assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst()).isNotNull(); for (int i = 2; i <= expectedRepetitions; i++) { brokerRule.getClock().addTime(Duration.ofSeconds(5)); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(i).count()).isEqualTo(i); } testClient.completeJobOfType("type"); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId(PROCESS_ID) .exists()) .isTrue(); assertThat( RecordingExporter.timerRecords(TimerIntent.CREATED).limit(expectedRepetitions).count()) .isEqualTo(expectedRepetitions); } }
@Test public void shouldRecreateATimerWithCycle() { // given testClient.deploy(TWO_REPS_CYCLE_WORKFLOW); brokerRule.getClock().pinCurrentTime(); final long nowMs = brokerRule.getClock().getCurrentTimeInMillis(); testClient.createWorkflowInstance(PROCESS_ID); // when final Record<TimerRecordValue> timerCreatedRecord = RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); brokerRule.getClock().addTime(Duration.ofSeconds(5)); final Record<TimerRecordValue> timerRescheduledRecord = RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).getLast(); // then assertThat(timerCreatedRecord).isNotEqualTo(timerRescheduledRecord); assertThat(timerCreatedRecord.getValue().getDueDate()).isEqualTo(nowMs + 1000); assertThat(timerRescheduledRecord.getValue().getDueDate()).isEqualTo(nowMs + 6000); }
@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 shouldRecreateATimerWithCycle() { // given testClient.deploy(TWO_REPS_CYCLE_WORKFLOW); brokerRule.getClock().pinCurrentTime(); final long nowMs = brokerRule.getClock().getCurrentTimeInMillis(); testClient.createWorkflowInstance(PROCESS_ID); // when final Record<TimerRecordValue> timerCreatedRecord = RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); brokerRule.getClock().addTime(Duration.ofSeconds(5)); final Record<TimerRecordValue> timerRescheduledRecord = RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).getLast(); // then assertThat(timerCreatedRecord).isNotEqualTo(timerRescheduledRecord); assertThat(timerCreatedRecord.getValue().getDueDate()).isEqualTo(nowMs + 1000); assertThat(timerRescheduledRecord.getValue().getDueDate()).isEqualTo(nowMs + 6000); }
@Test public void shouldCreateTimerBasedOnBoundaryEvent() { // given testClient.deploy(BOUNDARY_EVENT_WORKFLOW); brokerRule.getClock().pinCurrentTime(); final long nowMs = brokerRule.getClock().getCurrentTimeInMillis(); testClient.createWorkflowInstance("process"); // when final Record<TimerRecordValue> timerCreatedRecord = RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); final Record<WorkflowInstanceRecordValue> activityRecord = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId("task") .getFirst(); // then assertThat(timerCreatedRecord.getValue().getDueDate()).isEqualTo(nowMs + 1000); assertThat(timerCreatedRecord.getValue().getElementInstanceKey()) .isEqualTo(activityRecord.getKey()); assertThat(timerCreatedRecord.getValue().getHandlerFlowNodeId()).isEqualTo("timer"); }
@Test public void shouldCreateTimerBasedOnBoundaryEvent() { // given testClient.deploy(BOUNDARY_EVENT_WORKFLOW); brokerRule.getClock().pinCurrentTime(); final long nowMs = brokerRule.getClock().getCurrentTimeInMillis(); testClient.createWorkflowInstance("process"); // when final Record<TimerRecordValue> timerCreatedRecord = RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); final Record<WorkflowInstanceRecordValue> activityRecord = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId("task") .getFirst(); // then assertThat(timerCreatedRecord.getValue().getDueDate()).isEqualTo(nowMs + 1000); assertThat(timerCreatedRecord.getValue().getElementInstanceKey()) .isEqualTo(activityRecord.getKey()); assertThat(timerCreatedRecord.getValue().getHandlerFlowNodeId()).isEqualTo("timer"); }
@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 shouldCancelTimer() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .intermediateCatchEvent("timer1", c -> c.timerWithDuration("PT10S")) .endEvent() .done(); testClient.deploy(workflow); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); // when final Record<TimerRecordValue> createdEvent = RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); testClient.cancelWorkflowInstance(workflowInstanceKey); // then final Record<TimerRecordValue> canceledEvent = RecordingExporter.timerRecords(TimerIntent.CANCELED).getFirst(); assertThat(canceledEvent.getKey()).isEqualTo(createdEvent.getKey()); assertThat(canceledEvent.getValue()).isEqualTo(createdEvent.getValue()); assertThat(canceledEvent.getValue().getDueDate()) .isGreaterThan(brokerRule.getClock().getCurrentTimeInMillis()); }
@Test public void shouldCancelTimer() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .intermediateCatchEvent("timer1", c -> c.timerWithDuration("PT10S")) .endEvent() .done(); testClient.deploy(workflow); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); // when final Record<TimerRecordValue> createdEvent = RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); testClient.cancelWorkflowInstance(workflowInstanceKey); // then final Record<TimerRecordValue> canceledEvent = RecordingExporter.timerRecords(TimerIntent.CANCELED).getFirst(); assertThat(canceledEvent.getKey()).isEqualTo(createdEvent.getKey()); assertThat(canceledEvent.getValue()).isEqualTo(createdEvent.getValue()); assertThat(canceledEvent.getValue().getDueDate()) .isGreaterThan(brokerRule.getClock().getCurrentTimeInMillis()); }
@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()); }