public TimerRecordStream withDueDate(final long dueDate) { return valueFilter(v -> v.getDueDate() == dueDate); }
public TimerRecordStream withElementInstanceKey(final long elementInstanceKey) { return valueFilter(v -> v.getElementInstanceKey() == elementInstanceKey); }
public TimerRecordStream withHandlerNodeId(final String handlerNodeId) { return valueFilter(v -> v.getHandlerFlowNodeId().equals(handlerNodeId)); }
@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() { // 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 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() { // 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())); }
public TimerRecordStream withDueDate(final long dueDate) { return valueFilter(v -> v.getDueDate() == dueDate); }
public TimerRecordStream withHandlerNodeId(final String handlerNodeId) { return valueFilter(v -> v.getHandlerFlowNodeId().equals(handlerNodeId)); }
public TimerRecordStream withElementInstanceKey(final long elementInstanceKey) { return valueFilter(v -> v.getElementInstanceKey() == elementInstanceKey); }
/** * Verifies that the actual TimerRecordValue's dueDate is equal to the given one. * @param dueDate the given dueDate to compare the actual TimerRecordValue's dueDate to. * @return this assertion object. * @throws AssertionError - if the actual TimerRecordValue's dueDate is not equal to the given one. */ public S hasDueDate(long dueDate) { // check that actual TimerRecordValue we want to make assertions on is not null. isNotNull(); // overrides the default error message with a more explicit one String assertjErrorMessage = "\nExpecting dueDate of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; // check long actualDueDate = actual.getDueDate(); if (actualDueDate != dueDate) { failWithMessage(assertjErrorMessage, actual, dueDate, actualDueDate); } // return the current assertion for method chaining return myself; }
/** * Verifies that the actual TimerRecordValue's handlerFlowNodeId is equal to the given one. * @param handlerFlowNodeId the given handlerFlowNodeId to compare the actual TimerRecordValue's handlerFlowNodeId to. * @return this assertion object. * @throws AssertionError - if the actual TimerRecordValue's handlerFlowNodeId is not equal to the given one. */ public S hasHandlerFlowNodeId(String handlerFlowNodeId) { // check that actual TimerRecordValue we want to make assertions on is not null. isNotNull(); // overrides the default error message with a more explicit one String assertjErrorMessage = "\nExpecting handlerFlowNodeId of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; // null safe check String actualHandlerFlowNodeId = actual.getHandlerFlowNodeId(); if (!Objects.areEqual(actualHandlerFlowNodeId, handlerFlowNodeId)) { failWithMessage(assertjErrorMessage, actual, handlerFlowNodeId, actualHandlerFlowNodeId); } // return the current assertion for method chaining return myself; }
/** * Verifies that the actual TimerRecordValue's elementInstanceKey is equal to the given one. * @param elementInstanceKey the given elementInstanceKey to compare the actual TimerRecordValue's elementInstanceKey to. * @return this assertion object. * @throws AssertionError - if the actual TimerRecordValue's elementInstanceKey is not equal to the given one. */ public S hasElementInstanceKey(long elementInstanceKey) { // check that actual TimerRecordValue we want to make assertions on is not null. isNotNull(); // overrides the default error message with a more explicit one String assertjErrorMessage = "\nExpecting elementInstanceKey of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; // check long actualElementInstanceKey = actual.getElementInstanceKey(); if (actualElementInstanceKey != elementInstanceKey) { failWithMessage(assertjErrorMessage, actual, elementInstanceKey, actualElementInstanceKey); } // return the current assertion for method chaining return myself; }
@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 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 shouldSubscribeToBoundaryEventTriggersOnReady() { // given testClient.deploy(WITH_BOUNDARY_EVENTS); testClient.createWorkflowInstance(PROCESS_ID); // when final Record<WorkflowInstanceRecordValue> readyRecord = testClient.receiveElementInState("task", WorkflowInstanceIntent.ELEMENT_READY); final Record<WorkflowInstanceRecordValue> activatedRecord = testClient.receiveElementInState("task", WorkflowInstanceIntent.ELEMENT_ACTIVATED); final List<Record<TimerRecordValue>> subscriptions = Arrays.asList( testClient.receiveTimerRecord("timer1", TimerIntent.CREATE), testClient.receiveTimerRecord("timer2", TimerIntent.CREATE)); // then assertThat(subscriptions).hasSize(2); for (final Record<TimerRecordValue> subscription : subscriptions) { assertThat(subscription.getPosition()) .isBetween(readyRecord.getPosition(), activatedRecord.getPosition()); assertThat(subscription.getValue().getElementInstanceKey()).isEqualTo(readyRecord.getKey()); } }
@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); }
RecordingExporter.timerRecords(TimerIntent.CREATE) .limit(2) .map(r -> r.getValue().getHandlerFlowNodeId()) .collect(Collectors.toList());
@Test public void shouldSubscribeToBoundaryEventTriggersOnReady() { // given testClient.deploy(WITH_BOUNDARY_EVENTS); testClient.createWorkflowInstance(PROCESS_ID); // when final Record<WorkflowInstanceRecordValue> readyRecord = testClient.receiveElementInState("task", WorkflowInstanceIntent.ELEMENT_ACTIVATING); final Record<WorkflowInstanceRecordValue> activatedRecord = testClient.receiveElementInState("task", WorkflowInstanceIntent.ELEMENT_ACTIVATED); final List<Record<TimerRecordValue>> subscriptions = Arrays.asList( testClient.receiveTimerRecord("timer1", TimerIntent.CREATE), testClient.receiveTimerRecord("timer2", TimerIntent.CREATE)); // then assertThat(subscriptions).hasSize(2); for (final Record<TimerRecordValue> subscription : subscriptions) { assertThat(subscription.getPosition()) .isBetween(readyRecord.getPosition(), activatedRecord.getPosition()); assertThat(subscription.getValue().getElementInstanceKey()).isEqualTo(readyRecord.getKey()); } }
@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()); }