@Override BpmnModelInstance modelInstance() { return Bpmn.createExecutableProcess(processId()) .startEvent() .parallelGateway(elementId()) .endEvent() .done(); } },
@Override BpmnModelInstance modelInstance() { return Bpmn.createExecutableProcess(processId()) .startEvent() .parallelGateway(elementId()) .endEvent() .done(); } },
@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 shouldCompleteScopeOnParallelGateway() { // given final BpmnModelInstance process = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent("start") .sequenceFlowId("flow1") .parallelGateway("fork") .done(); testClient.deploy(process); // when testClient.createWorkflowInstance(PROCESS_ID); // then final Record<WorkflowInstanceRecordValue> completedEvent = testClient.receiveElementInState(PROCESS_ID, WorkflowInstanceIntent.ELEMENT_COMPLETED); final List<Record<WorkflowInstanceRecordValue>> workflowInstanceEvents = testClient .receiveWorkflowInstances() .limit(r -> r.getPosition() == completedEvent.getPosition()) .collect(Collectors.toList()); assertThat(workflowInstanceEvents) .extracting(e -> e.getValue().getElementId(), e -> e.getMetadata().getIntent()) .containsSequence( tuple("fork", WorkflowInstanceIntent.GATEWAY_ACTIVATED), tuple(PROCESS_ID, WorkflowInstanceIntent.ELEMENT_COMPLETING)); }
@Test public void shouldCompleteInstanceAfterTimerIntermediateCatchEvent() { // given brokerRule.getClock().pinCurrentTime(); testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task", t -> t.zeebeTaskType("task")) .endEvent("end-1") .moveToLastGateway() .intermediateCatchEvent("catch", e -> e.timerWithDuration("PT0.1S")) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("task"); brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.EVENT_ACTIVATED); }
@Test public void shouldMergeAndSplitInOneGateway() { // given final BpmnModelInstance process = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway("fork") .parallelGateway("join-fork") .moveToNode("fork") .connectTo("join-fork") .serviceTask("task1", b -> b.zeebeTaskType("type1")) .moveToLastGateway() .serviceTask("task2", b -> b.zeebeTaskType("type2")) .done(); testClient.deploy(process); // when testClient.createWorkflowInstance(PROCESS_ID); // then final List<Record<WorkflowInstanceRecordValue>> elementInstances = testClient .receiveWorkflowInstances() .filter(r -> r.getMetadata().getIntent() == WorkflowInstanceIntent.ELEMENT_ACTIVATED) .limit(3) .collect(Collectors.toList()); assertThat(elementInstances) .extracting(e -> e.getValue().getElementId()) .contains(PROCESS_ID, "task1", "task2"); }
@Test public void shouldCompleteInstanceAfterTimerIntermediateCatchEvent() { // given brokerRule.getClock().pinCurrentTime(); testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task", t -> t.zeebeTaskType("task")) .endEvent("end-1") .moveToLastGateway() .intermediateCatchEvent("catch", e -> e.timerWithDuration("PT0.1S")) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("task"); brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.ELEMENT_COMPLETED); }
@Test public void shouldCompleteInstanceAfterParallelSplit() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task-1", t -> t.zeebeTaskType("task-1")) .endEvent("end-1") .moveToLastGateway() .serviceTask("task-2", t -> t.zeebeTaskType("task-2")) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("task-1"); testClient.completeJobOfType("task-2"); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.EVENT_ACTIVATED); }
@Test public void shouldCompleteInstanceAfterParallelSplit() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task-1", t -> t.zeebeTaskType("task-1")) .endEvent("end-1") .moveToLastGateway() .serviceTask("task-2", t -> t.zeebeTaskType("task-2")) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("task-1"); testClient.completeJobOfType("task-2"); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.ELEMENT_COMPLETED); }
@Test public void shouldCompleteInstanceAfterParallelJoin() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway("fork") .serviceTask("task-1", t -> t.zeebeTaskType("task-1")) .parallelGateway("join") .endEvent("end") .moveToNode("fork") .serviceTask("task-2", t -> t.zeebeTaskType("task-2")) .connectTo("join") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("task-1"); testClient.completeJobOfType("task-2"); // then assertThatWorkflowInstanceCompletedAfter("end", WorkflowInstanceIntent.EVENT_ACTIVATED); }
@Test public void shouldCompleteInstanceAfterMessageIntermediateCatchEvent() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task", t -> t.zeebeTaskType("task")) .endEvent("end-1") .moveToLastGateway() .intermediateCatchEvent( "catch", e -> e.message(m -> m.name("msg").zeebeCorrelationKey("$.key"))) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID, "{'key':'123'}"); // when testClient.completeJobOfType("task"); testClient.publishMessage("msg", "123"); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.EVENT_ACTIVATED); }
@Test public void shouldCompleteInstanceAfterParallelJoin() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway("fork") .serviceTask("task-1", t -> t.zeebeTaskType("task-1")) .parallelGateway("join") .endEvent("end") .moveToNode("fork") .serviceTask("task-2", t -> t.zeebeTaskType("task-2")) .connectTo("join") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("task-1"); testClient.completeJobOfType("task-2"); // then assertThatWorkflowInstanceCompletedAfter("end", WorkflowInstanceIntent.ELEMENT_COMPLETED); }
@Test public void shouldCompleteInstanceAfterMessageIntermediateCatchEvent() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task", t -> t.zeebeTaskType("task")) .endEvent("end-1") .moveToLastGateway() .intermediateCatchEvent( "catch", e -> e.message(m -> m.name("msg").zeebeCorrelationKey("$.key"))) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID, "{'key':'123'}"); // when testClient.completeJobOfType("task"); testClient.publishMessage("msg", "123"); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.ELEMENT_COMPLETED); }
@Test public void shouldCompleteInstanceAfterSubProcessEnded() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task-1", t -> t.zeebeTaskType("task-1")) .endEvent("end-1") .moveToLastGateway() .subProcess( "sub", s -> s.embeddedSubProcess() .startEvent() .serviceTask("task-2", t -> t.zeebeTaskType("task-2")) .endEvent("end-sub")) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("task-1"); testClient.completeJobOfType("task-2"); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.EVENT_ACTIVATED); }
@Test public void shouldNotCompleteInstanceAfterIncidentIsRaisedOnActivity() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task-1", t -> t.zeebeTaskType("task-1")) .endEvent("end-1") .moveToLastGateway() .serviceTask("task-2", t -> t.zeebeTaskType("task-2").zeebeOutput("$.result", "$.r")) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("task-2"); final Record<IncidentRecordValue> incident = RecordingExporter.incidentRecords(IncidentIntent.CREATED).getFirst(); testClient.completeJobOfType("task-1"); testClient.updatePayload(incident.getValue().getElementInstanceKey(), "{'result':'123'}"); testClient.resolveIncident(incident.getKey()); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.EVENT_ACTIVATED); }
@Test public void shouldCompleteInstanceAfterEventBasedGateway() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task", t -> t.zeebeTaskType("task")) .endEvent("end-1") .moveToLastGateway() .eventBasedGateway("gateway") .intermediateCatchEvent( "catch-1", e -> e.message(m -> m.name("msg-1").zeebeCorrelationKey("$.key"))) .endEvent("end-2") .moveToNode("gateway") .intermediateCatchEvent( "catch-2", e -> e.message(m -> m.name("msg-2").zeebeCorrelationKey("$.key"))) .endEvent("end-3") .done()); testClient.createWorkflowInstance(PROCESS_ID, "{'key':'123'}"); // when testClient.completeJobOfType("task"); testClient.publishMessage("msg-1", "123"); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.EVENT_ACTIVATED); }
@Test public void shouldNotCompleteInstanceAfterIncidentIsRaisedOnActivity() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task-1", t -> t.zeebeTaskType("task-1")) .endEvent("end-1") .moveToLastGateway() .serviceTask("task-2", t -> t.zeebeTaskType("task-2").zeebeOutput("$.result", "$.r")) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("task-2"); final Record<IncidentRecordValue> incident = RecordingExporter.incidentRecords(IncidentIntent.CREATED).getFirst(); testClient.completeJobOfType("task-1"); testClient.updatePayload(incident.getValue().getElementInstanceKey(), "{'result':'123'}"); testClient.resolveIncident(incident.getKey()); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.ELEMENT_COMPLETED); }
@Test public void shouldNotCompleteInstanceAfterIncidentIsRaisedOnEvent() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task", t -> t.zeebeTaskType("task")) .endEvent("end-1") .moveToLastGateway() .intermediateCatchEvent( "catch", e -> e.message(m -> m.name("msg").zeebeCorrelationKey("$.key"))) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when final Record<IncidentRecordValue> incident = RecordingExporter.incidentRecords(IncidentIntent.CREATED).getFirst(); testClient.completeJobOfType("task"); testClient.updatePayload(incident.getValue().getElementInstanceKey(), "{'key':'123'}"); testClient.resolveIncident(incident.getKey()); testClient.publishMessage("msg", "123"); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.EVENT_ACTIVATED); }
@Test public void shouldNotCompleteInstanceAfterIncidentIsRaisedOnExclusiveGateway() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task", t -> t.zeebeTaskType("task")) .endEvent("end-1") .moveToLastGateway() .exclusiveGateway("gateway") .defaultFlow() .endEvent("end-2") .moveToNode("gateway") .sequenceFlowId("to-end-3") .condition("$.x < 21") .endEvent("end-3") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when final Record<IncidentRecordValue> incident = RecordingExporter.incidentRecords(IncidentIntent.CREATED).getFirst(); testClient.completeJobOfType("task"); testClient.updatePayload(incident.getValue().getElementInstanceKey(), "{'x':123}"); testClient.resolveIncident(incident.getKey()); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.ELEMENT_COMPLETED); }