public TimerRecordStream receiveTimerRecords() { return RecordingExporter.timerRecords().withPartitionId(partitionId); }
public static TimerRecordStream timerRecords(final TimerIntent intent) { return timerRecords().withIntent(intent); }
public static TimerRecordStream timerRecords(final TimerIntent intent) { return timerRecords().withIntent(intent); }
public TimerRecordStream receiveTimerRecords() { return RecordingExporter.timerRecords().withPartitionId(partitionId); }
@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 shouldCancelTimer() { // given testClient.deploy(WORKFLOW_WITH_TIMERS); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).exists()).isTrue(); // when brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then assertThat(RecordingExporter.timerRecords(TimerIntent.CANCELED).limit(1)) .extracting(r -> r.getValue().getHandlerFlowNodeId()) .hasSize(1) .contains("timer-2"); }
@Test public void shouldCancelTimer() { // given testClient.deploy(WORKFLOW_WITH_TIMERS); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).exists()); // when brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then assertThat(RecordingExporter.timerRecords(TimerIntent.CANCELED).limit(1)) .extracting(r -> r.getValue().getHandlerFlowNodeId()) .hasSize(1) .contains("timer-2"); }
@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 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 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 shouldTriggerTimerWithZeroDuration() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("PT0S")) .endEvent() .done(); testClient.deploy(workflow); testClient.createWorkflowInstance(PROCESS_ID); // then assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).exists()).isTrue(); }
@Test public void shouldTriggerTimerWithNegativeDuration() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("-PT1H")) .endEvent() .done(); testClient.deploy(workflow); testClient.createWorkflowInstance(PROCESS_ID); // then assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).exists()).isTrue(); }
@Test public void shouldTriggerTimerWithZeroDuration() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("PT0S")) .endEvent() .done(); testClient.deploy(workflow); testClient.createWorkflowInstance(PROCESS_ID); // then assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).exists()).isTrue(); }
@Test public void shouldTriggerTimerWithNegativeDuration() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("-PT1H")) .endEvent() .done(); testClient.deploy(workflow); testClient.createWorkflowInstance(PROCESS_ID); // then assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).exists()).isTrue(); }
@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 shouldCreateTimer() { // given testClient.deploy(WORKFLOW_WITH_TIMERS); // when testClient.createWorkflowInstance(PROCESS_ID); // then final Record<WorkflowInstanceRecordValue> gatewayEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.GATEWAY_ACTIVATED) .getFirst(); final List<Record<TimerRecordValue>> timerEvents = RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).asList(); assertThat(timerEvents) .hasSize(2) .extracting( r -> tuple(r.getValue().getHandlerFlowNodeId(), r.getValue().getElementInstanceKey())) .contains(tuple("timer-1", gatewayEvent.getKey()), tuple("timer-2", gatewayEvent.getKey())); }
@Test public void shouldCreateTimer() { // given testClient.deploy(WORKFLOW_WITH_TIMERS); // when testClient.createWorkflowInstance(PROCESS_ID); // then final Record<WorkflowInstanceRecordValue> gatewayEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementType(BpmnElementType.EVENT_BASED_GATEWAY) .getFirst(); final List<Record<TimerRecordValue>> timerEvents = RecordingExporter.timerRecords(TimerIntent.CREATED).limit(2).asList(); assertThat(timerEvents) .hasSize(2) .extracting( r -> tuple(r.getValue().getHandlerFlowNodeId(), r.getValue().getElementInstanceKey())) .contains(tuple("timer-1", gatewayEvent.getKey()), tuple("timer-2", gatewayEvent.getKey())); }