Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move to sdk (wip) #569

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions timer-testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

<properties>
<java.version>21</java.version>
<spring-boot.version>3.3.0</spring-boot.version>
<camunda-process-test-coverage.version>2.7.0</camunda-process-test-coverage.version>
<spring-zeebe.version>8.5.7</spring-zeebe.version>
<spring-boot.version>3.4.0</spring-boot.version>
<camunda.version>8.6.6</camunda.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
Expand All @@ -30,9 +29,9 @@

<dependencies>
<dependency>
<groupId>io.camunda.spring</groupId>
<artifactId>spring-boot-starter-camunda</artifactId>
<version>${spring-zeebe.version}</version>
<groupId>io.camunda</groupId>
<artifactId>spring-boot-starter-camunda-sdk</artifactId>
<version>${camunda.version}</version>
</dependency>

<dependency>
Expand All @@ -46,15 +45,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.camunda.spring</groupId>
<artifactId>spring-boot-starter-camunda-test</artifactId>
<version>${spring-zeebe.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.camunda.community.process_test_coverage</groupId>
<artifactId>camunda-process-test-coverage-junit5-platform-8</artifactId>
<version>${camunda-process-test-coverage.version}</version>
<groupId>io.camunda</groupId>
<artifactId>camunda-process-test-spring</artifactId>
<version>${camunda.version}</version>
<scope>test</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion timer-testing/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
camunda:
client:
mode: simple
mode: selfmanaged
10 changes: 5 additions & 5 deletions timer-testing/src/main/resources/get-up.bpmn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0nlacrn" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.23.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.5.0">
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0nlacrn" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.30.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.5.0">
<bpmn:process id="GetUpProcess" name="Get Up" isExecutable="true">
<bpmn:startEvent id="KidsNeedToGetUpForSchoolStartEvent" name="Kids need to get up for school">
<bpmn:outgoing>Flow_0lin8i4</bpmn:outgoing>
Expand All @@ -21,7 +21,7 @@
<bpmn:outgoing>Flow_0j8vm25</bpmn:outgoing>
</bpmn:parallelGateway>
<bpmn:sequenceFlow id="Flow_1m7we6c" sourceRef="Gateway_09a2iuf" targetRef="Wait5MinutesEvent1" />
<bpmn:intermediateCatchEvent id="Wait5MinutesEvent1" name="Wait 5 minutes">
<bpmn:intermediateCatchEvent id="Wait5MinutesEvent1" name="Wait another 5 minutes">
<bpmn:incoming>Flow_1m7we6c</bpmn:incoming>
<bpmn:outgoing>Flow_0nxql0b</bpmn:outgoing>
<bpmn:timerEventDefinition id="TimerEventDefinition_0xnag2v">
Expand Down Expand Up @@ -105,7 +105,7 @@
<bpmn:outgoing>Flow_14nugz7</bpmn:outgoing>
<bpmn:outgoing>Flow_0ih5vlk</bpmn:outgoing>
</bpmn:parallelGateway>
<bpmn:intermediateCatchEvent id="Wait15MinutesEvent1" name="Wait 15 minutes">
<bpmn:intermediateCatchEvent id="Wait15MinutesEvent1" name="Wait another 15 minutes">
<bpmn:incoming>Flow_0ih5vlk</bpmn:incoming>
<bpmn:outgoing>Flow_0j2xfnn</bpmn:outgoing>
<bpmn:timerEventDefinition id="TimerEventDefinition_0kkywwd">
Expand Down Expand Up @@ -208,7 +208,7 @@
<bpmndi:BPMNShape id="Event_0tcsm17_di" bpmnElement="Wait5MinutesEvent1">
<dc:Bounds x="1812" y="200" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="1794" y="243" width="73" height="14" />
<dc:Bounds x="1795" y="243" width="72" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1c60h93_di" bpmnElement="DriveKidsToSchoolTask">
Expand Down Expand Up @@ -272,7 +272,7 @@
<bpmndi:BPMNShape id="Event_1fhcsph_di" bpmnElement="Wait15MinutesEvent1">
<dc:Bounds x="1252" y="172" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="1231" y="215" width="79" height="14" />
<dc:Bounds x="1232" y="215" width="78" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_0rp37iu_di" bpmnElement="Gateway_1po0o0g">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
package com.camunda.consulting;

import static com.camunda.consulting.ExampleApplication.*;
import static io.camunda.zeebe.process.test.assertions.BpmnAssert.*;
import static io.camunda.zeebe.spring.test.ZeebeTestThreadSupport.*;
import static io.camunda.process.test.api.CamundaAssert.*;
import static org.assertj.core.api.Assertions.*;

import io.camunda.process.test.api.CamundaProcessTestContext;
import io.camunda.process.test.api.CamundaSpringProcessTest;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.api.response.ActivatedJob;
import io.camunda.zeebe.client.api.response.ProcessInstanceEvent;
import io.camunda.zeebe.process.test.api.ZeebeTestEngine;
import io.camunda.zeebe.process.test.inspections.model.InspectedProcessInstance;
import io.camunda.zeebe.spring.test.ZeebeSpringTest;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import org.camunda.community.process_test_coverage.junit5.platform8.ProcessEngineCoverageExtension;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@ZeebeSpringTest
@CamundaSpringProcessTest
@SpringBootTest
@ExtendWith(ProcessEngineCoverageExtension.class)
public class SpringTimerTest {
private static final Duration DEFAULT = Duration.ofSeconds(30);
@Autowired ZeebeTestEngine zeebeTestEngine;
@Autowired CamundaProcessTestContext camundaProcessTestContext;
@Autowired ZeebeClient zeebeClient;

@BeforeEach
Expand All @@ -41,98 +36,66 @@ void reset() {
progressOverride = null;
}

@RepeatedTest(10)
@Test
void happyPath() throws InterruptedException, TimeoutException {
progressOverride = "ready";
ProcessInstanceEvent processInstance = createInstance("GetUpProcess");
InspectedProcessInstance inspectedProcessInstance =
new InspectedProcessInstance(processInstance.getProcessInstanceKey());
waitForProcessInstanceHasPassedElement(processInstance, "TellKidsToGetUpTask", DEFAULT);
skipTimer(inspectedProcessInstance, "Wait15MinutesEvent", Duration.ofMinutes(15));
waitForProcessInstanceHasPassedElement(processInstance, "CheckCurrentProgressTask", DEFAULT);
skipTimer(inspectedProcessInstance, "Wait15MinutesEvent1", Duration.ofMinutes(15));
skipTimer(inspectedProcessInstance, "Wait5MinutesEvent1", Duration.ofMinutes(5));
waitForProcessInstanceCompleted(processInstance);
assertThat(processInstance).hasActiveElements("Wait 15 minutes");
skipTimer(Duration.ofMinutes(15));
assertThat(processInstance).hasActiveElements("Wait another 15 minutes");
skipTimer(Duration.ofMinutes(15));
assertThat(processInstance).hasActiveElements("Wait another 5 minutes");
skipTimer(Duration.ofMinutes(5));
assertThat(processInstance).isCompleted();
}

@RepeatedTest(10)
@Test
void boundaryEvent() throws InterruptedException, TimeoutException {
progressOverride = "in bed";
ProcessInstanceEvent processInstance = createInstance("GetUpProcess");
InspectedProcessInstance inspectedProcessInstance =
new InspectedProcessInstance(processInstance.getProcessInstanceKey());
waitForProcessInstanceHasPassedElement(processInstance, "TellKidsToGetUpTask", DEFAULT);
skipTimer(inspectedProcessInstance, "Wait15MinutesEvent", Duration.ofMinutes(15));
waitForProcessInstanceHasPassedElement(processInstance, "CheckCurrentProgressTask", DEFAULT);
waitForProcessInstanceHasPassedElement(
inspectedProcessInstance, "TellKidsToGetUpTask", DEFAULT, 2);
skipTimer(inspectedProcessInstance, "Wait15MinutesEvent", Duration.ofMinutes(15), 2);
waitForProcessInstanceHasPassedElement(
inspectedProcessInstance, "CheckCurrentProgressTask", DEFAULT, 2);
assertThat(processInstance).hasActiveElements("Wait 15 minutes");
skipTimer(Duration.ofMinutes(15));
assertThat(processInstance).hasActiveElements("Wait 15 minutes");
skipTimer(Duration.ofMinutes(15));
assertThat(processInstance).hasActiveElements("Wait 15 minutes");
progressOverride = "dressing";
waitForProcessInstanceHasPassedElement(
inspectedProcessInstance, "TellKidsToGetUpTask", DEFAULT, 3);
skipTimer(inspectedProcessInstance, "Wait15MinutesEvent", Duration.ofMinutes(15), 3);
waitForProcessInstanceHasPassedElement(
inspectedProcessInstance, "CheckCurrentProgressTask", DEFAULT, 3);
skipTimer(Duration.ofMinutes(15));
assertThat(processInstance).hasActiveElements("Wait 5 minutes");
progressOverride = "ready";
skipTimer(inspectedProcessInstance, "Wait5MinutesEvent", Duration.ofMinutes(5));
waitForProcessInstanceHasPassedElement(
inspectedProcessInstance, "CheckCurrentProgressTask", DEFAULT, 4);
skipTimer(Duration.ofMinutes(5));
// we start having breakfast (finally)
zeebeTestEngine.increaseTime(Duration.ofMinutes(10));
skipTimer(Duration.ofMinutes(10));
// we are running late at this point (15+15+15+5+10 = 60) so the boundary event gets triggered
// instead
waitForProcessInstanceHasPassedElement(processInstance, "RunningLateBoundaryEvent", DEFAULT);
skipTimer(inspectedProcessInstance, "Wait5MinutesEvent1", Duration.ofMinutes(5));
waitForProcessInstanceCompleted(processInstance);
assertThat(processInstance)
.isCompleted()
.hasPassedElement("MakeThemReadyTask")
.hasNotPassedElement("KidsAreFedEndEvent");
assertThat(processInstance).hasCompletedElements("Running late");
assertThat(processInstance).hasActiveElements("Wait another 5 minutes");
skipTimer(Duration.ofMinutes(5));
assertThat(processInstance).isCompleted().hasCompletedElements("Make them ready");
// missing: has not completed elements
}

private void skipTimer(
InspectedProcessInstance processInstance, String timerElementId, Duration timerDuration)
throws InterruptedException, TimeoutException {
skipTimer(processInstance, timerElementId, timerDuration, 1);
private void skipTimer(Duration timerDuration) throws InterruptedException, TimeoutException {
camundaProcessTestContext.increaseTime(timerDuration);
}

private void skipTimer(
InspectedProcessInstance processInstance,
String timerElementId,
Duration timerDuration,
int times)
throws InterruptedException, TimeoutException {
zeebeTestEngine.waitForIdleState(DEFAULT);
assertThat(processInstance).isWaitingAtElements(timerElementId);
zeebeTestEngine.increaseTime(timerDuration);
waitForProcessInstanceHasPassedElement(processInstance, timerElementId, DEFAULT, times);
zeebeTestEngine.waitForIdleState(DEFAULT);
}

private ProcessInstanceEvent createInstance(String bpmnProcessId)
throws InterruptedException, TimeoutException {
private ProcessInstanceEvent createInstance(String bpmnProcessId) {
ProcessInstanceEvent instance =
zeebeClient
.newCreateInstanceCommand()
.bpmnProcessId(bpmnProcessId)
.latestVersion()
.send()
.join();
zeebeTestEngine.waitForIdleState(DEFAULT);
return instance;
}

private void completeJob(String jobType) throws InterruptedException, TimeoutException {
private void completeJob(String jobType) {
completeJob(jobType, Map.of());
}

private void completeJob(String jobType, Map<String, Object> variables)
throws InterruptedException, TimeoutException {
private void completeJob(String jobType, Map<String, Object> variables) {
ActivatedJob activatedJob = job(jobType);
complete(activatedJob.getKey(), variables);
zeebeTestEngine.waitForIdleState(DEFAULT);
}

private void complete(long jobKey, Map<String, Object> variables) {
Expand Down
Loading
Loading