@Test public void shouldCreateMultipleWorkflowInstancesWithRepeatingTimer() { // when testClient.deployWithResponse(THREE_SEC_MODEL); // then assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).exists()).isTrue(); brokerRule.getClock().addTime(Duration.ofSeconds(3)); assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).exists()).isTrue(); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_READY) .withElementId("process_3") .exists()) .isTrue(); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).count()).isEqualTo(2); brokerRule.getClock().addTime(Duration.ofSeconds(3)); assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).limit(2).count()).isEqualTo(2); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_READY) .withElementId("process_3") .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 shouldCreateMultipleWorkflowInstancesWithRepeatingTimer() { // when testClient.deployWithResponse(THREE_SEC_MODEL); // then assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).exists()).isTrue(); brokerRule.getClock().addTime(Duration.ofSeconds(3)); assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).exists()).isTrue(); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATING) .withElementId("process_3") .exists()) .isTrue(); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).count()).isEqualTo(2); brokerRule.getClock().addTime(Duration.ofSeconds(3)); assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).limit(2).count()).isEqualTo(2); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATING) .withElementId("process_3") .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 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 shouldCreateMultipleInstanceAtTheCorrectTimes() { // when testClient.deploy(MULTI_TIMER_START_MODEL); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).count()).isEqualTo(2); brokerRule.getClock().addTime(Duration.ofSeconds(2)); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_TRIGGERED) .withElementId("start_4") .exists()) .isTrue(); assertThat( RecordingExporter.workflowInstanceRecords(EVENT_ACTIVATED) .withElementId("end_4") .exists()) .isTrue(); brokerRule.getClock().addTime(Duration.ofSeconds(1)); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_TRIGGERED) .withElementId("start_5") .exists()) .isTrue(); assertThat( RecordingExporter.workflowInstanceRecords(EVENT_ACTIVATED) .withElementId("end_5") .exists()) .isTrue(); }
@Test public void shouldCreateMultipleInstanceAtTheCorrectTimes() { // when testClient.deploy(MULTI_TIMER_START_MODEL); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).count()).isEqualTo(2); brokerRule.getClock().addTime(Duration.ofSeconds(2)); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId("start_4") .exists()) .isTrue(); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId("end_4") .exists()) .isTrue(); brokerRule.getClock().addTime(Duration.ofSeconds(1)); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId("start_5") .exists()) .isTrue(); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId("end_5") .exists()) .isTrue(); }
@Test public void shouldUpdateWorkflow() { // when testClient.deploy(SIMPLE_MODEL); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).exists()).isTrue(); brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then assertThat( RecordingExporter.workflowInstanceRecords(EVENT_ACTIVATED) .withElementId("end_1") .withBpmnProcessId("process") .withVersion(1) .exists()) .isTrue(); // when testClient.deploy(REPEATING_MODEL); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).count()).isEqualTo(2); brokerRule.getClock().addTime(Duration.ofSeconds(2)); assertThat( RecordingExporter.workflowInstanceRecords(EVENT_ACTIVATED) .withElementId("end_2") .withBpmnProcessId("process") .withVersion(2) .exists()) .isTrue(); }
@Test public void shouldUpdateWorkflow() { // when testClient.deploy(SIMPLE_MODEL); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).exists()).isTrue(); brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId("end_1") .withBpmnProcessId("process") .withVersion(1) .exists()) .isTrue(); // when testClient.deploy(REPEATING_MODEL); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).count()).isEqualTo(2); brokerRule.getClock().addTime(Duration.ofSeconds(2)); assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId("end_2") .withBpmnProcessId("process") .withVersion(2) .exists()) .isTrue(); }
assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).count()).isEqualTo(2); brokerRule.getClock().addTime(Duration.ofSeconds(1));
assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).count()).isEqualTo(2); brokerRule.getClock().addTime(Duration.ofSeconds(2));
assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).count()).isEqualTo(2); brokerRule.getClock().addTime(Duration.ofSeconds(2));
assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).count()).isEqualTo(2); brokerRule.getClock().addTime(Duration.ofSeconds(1));
@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); }