Skip to content

Commit

Permalink
test(zeebe): add test for migrateProcessInstance
Browse files Browse the repository at this point in the history
fixes #49
  • Loading branch information
jwulf committed Apr 2, 2024
1 parent 3cb4e36 commit f39085e
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 15 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ jobs:

- name: Install dependencies
run: npm install
env:
GH_NPM_TOKEN: ${{ secrets.GH_NPM_TOKEN }}

- name: Lint last commit message
run: npx commitlint --from=${{ github.event.pull_request.base.sha }} --to=${{ github.event.pull_request.head.sha }} --verbose
Expand Down
91 changes: 91 additions & 0 deletions src/__tests__/testdata/MigrateProcess-Version-1.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1cfwunf" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.21.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.4.0">
<bpmn:process id="migrant-work" name="migrant-work" isExecutable="true">
<bpmn:startEvent id="StartEvent_1" name="Start MigrationTest Process">
<bpmn:outgoing>Flow_167nn02</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_167nn02" sourceRef="StartEvent_1" targetRef="Activity_1fbznct" />
<bpmn:endEvent id="Event_0zwmdqk" name="End">
<bpmn:incoming>Flow_1r250pk</bpmn:incoming>
</bpmn:endEvent>
<bpmn:serviceTask id="Activity_1fbznct" name="Migrant Worker Task 1">
<bpmn:extensionElements>
<zeebe:taskDefinition type="migrant-worker-task-1" />
<zeebe:taskHeaders>
<zeebe:header key="ProcessVersion" value="1" />
</zeebe:taskHeaders>
</bpmn:extensionElements>
<bpmn:incoming>Flow_167nn02</bpmn:incoming>
<bpmn:outgoing>Flow_04fsyv6</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_1r250pk" sourceRef="Activity_0wjb7yn" targetRef="Event_0zwmdqk" />
<bpmn:sequenceFlow id="Flow_04fsyv6" sourceRef="Activity_1fbznct" targetRef="Activity_050vmrm" />
<bpmn:serviceTask id="Activity_0wjb7yn" name="Migrant Worker Task 2">
<bpmn:extensionElements>
<zeebe:taskDefinition type="migrant-worker-task-2" />
<zeebe:taskHeaders>
<zeebe:header key="ProcessVersion" value="1" />
</zeebe:taskHeaders>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1igeic8</bpmn:incoming>
<bpmn:outgoing>Flow_1r250pk</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_1igeic8" sourceRef="Activity_050vmrm" targetRef="Activity_0wjb7yn" />
<bpmn:serviceTask id="Activity_050vmrm" name="Migration Checkpoint">
<bpmn:extensionElements>
<zeebe:taskDefinition type="migration-checkpoint" />
</bpmn:extensionElements>
<bpmn:incoming>Flow_04fsyv6</bpmn:incoming>
<bpmn:outgoing>Flow_1igeic8</bpmn:outgoing>
</bpmn:serviceTask>
</bpmn:process>
<bpmn:message id="Message_2h617dg" name="MigrationFinished">
<bpmn:extensionElements>
<zeebe:subscription correlationKey="=messageCorrelationKey" />
</bpmn:extensionElements>
</bpmn:message>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="migrant-work">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="164" y="142" width="66" height="40" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1rj9fgz_di" bpmnElement="Activity_1fbznct">
<dc:Bounds x="330" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0uo9rxu_di" bpmnElement="Activity_0wjb7yn">
<dc:Bounds x="600" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0zwmdqk_di" bpmnElement="Event_0zwmdqk">
<dc:Bounds x="822" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="830" y="142" width="20" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1io10nl_di" bpmnElement="Activity_050vmrm">
<dc:Bounds x="460" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_167nn02_di" bpmnElement="Flow_167nn02">
<di:waypoint x="215" y="117" />
<di:waypoint x="330" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1r250pk_di" bpmnElement="Flow_1r250pk">
<di:waypoint x="700" y="117" />
<di:waypoint x="822" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_04fsyv6_di" bpmnElement="Flow_04fsyv6">
<di:waypoint x="430" y="117" />
<di:waypoint x="460" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1igeic8_di" bpmnElement="Flow_1igeic8">
<di:waypoint x="560" y="117" />
<di:waypoint x="600" y="117" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
91 changes: 91 additions & 0 deletions src/__tests__/testdata/MigrateProcess-Version-2.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1cfwunf" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.21.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.4.0">
<bpmn:process id="migrant-work" name="migrant-work" isExecutable="true">
<bpmn:startEvent id="StartEvent_1" name="Start MigrationTest Process">
<bpmn:outgoing>Flow_167nn02</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_167nn02" sourceRef="StartEvent_1" targetRef="Activity_1fbznct" />
<bpmn:endEvent id="Event_0zwmdqk" name="End">
<bpmn:incoming>Flow_1r250pk</bpmn:incoming>
</bpmn:endEvent>
<bpmn:serviceTask id="Activity_1fbznct" name="Migrant Worker Task 1">
<bpmn:extensionElements>
<zeebe:taskDefinition type="migrant-worker-task-1" />
<zeebe:taskHeaders>
<zeebe:header key="ProcessVersion" value="2" />
</zeebe:taskHeaders>
</bpmn:extensionElements>
<bpmn:incoming>Flow_167nn02</bpmn:incoming>
<bpmn:outgoing>Flow_04fsyv6</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_1r250pk" sourceRef="Activity_0wjb7yn" targetRef="Event_0zwmdqk" />
<bpmn:sequenceFlow id="Flow_04fsyv6" sourceRef="Activity_1fbznct" targetRef="Activity_050vmrm" />
<bpmn:serviceTask id="Activity_0wjb7yn" name="Migrant Worker Task 2">
<bpmn:extensionElements>
<zeebe:taskDefinition type="migrant-worker-task-2" />
<zeebe:taskHeaders>
<zeebe:header key="ProcessVersion" value="2" />
</zeebe:taskHeaders>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1igeic8</bpmn:incoming>
<bpmn:outgoing>Flow_1r250pk</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_1igeic8" sourceRef="Activity_050vmrm" targetRef="Activity_0wjb7yn" />
<bpmn:serviceTask id="Activity_050vmrm" name="Migration Checkpoint">
<bpmn:extensionElements>
<zeebe:taskDefinition type="migration-checkpoint" />
</bpmn:extensionElements>
<bpmn:incoming>Flow_04fsyv6</bpmn:incoming>
<bpmn:outgoing>Flow_1igeic8</bpmn:outgoing>
</bpmn:serviceTask>
</bpmn:process>
<bpmn:message id="Message_2h617dg" name="MigrationFinished">
<bpmn:extensionElements>
<zeebe:subscription correlationKey="=messageCorrelationKey" />
</bpmn:extensionElements>
</bpmn:message>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="migrant-work">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="164" y="142" width="66" height="40" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1rj9fgz_di" bpmnElement="Activity_1fbznct">
<dc:Bounds x="330" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0uo9rxu_di" bpmnElement="Activity_0wjb7yn">
<dc:Bounds x="600" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0zwmdqk_di" bpmnElement="Event_0zwmdqk">
<dc:Bounds x="822" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="830" y="142" width="20" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1io10nl_di" bpmnElement="Activity_050vmrm">
<dc:Bounds x="460" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_167nn02_di" bpmnElement="Flow_167nn02">
<di:waypoint x="215" y="117" />
<di:waypoint x="330" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1r250pk_di" bpmnElement="Flow_1r250pk">
<di:waypoint x="700" y="117" />
<di:waypoint x="822" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_04fsyv6_di" bpmnElement="Flow_04fsyv6">
<di:waypoint x="430" y="117" />
<di:waypoint x="460" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1igeic8_di" bpmnElement="Flow_1igeic8">
<di:waypoint x="560" y="117" />
<di:waypoint x="600" y="117" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Original file line number Diff line number Diff line change
@@ -1,26 +1,112 @@
import { suppressZeebeLogging } from 'lib'
import { restoreZeebeLogging, suppressZeebeLogging } from 'lib'
import { DeployResourceResponse, ProcessDeployment } from 'zeebe/types'

import { ZeebeGrpcClient } from '../../../zeebe/index'
import { cancelProcesses } from '../../../zeebe/lib/cancelProcesses'

suppressZeebeLogging()

let res: DeployResourceResponse<ProcessDeployment> | undefined
let res1: DeployResourceResponse<ProcessDeployment> | undefined

afterAll(async () => {
restoreZeebeLogging()
await cancelProcesses(
res?.deployments[0].process.processDefinitionKey as string
)
await cancelProcesses(
res1?.deployments[0].process.processDefinitionKey as string
)
})

const zbc = new ZeebeGrpcClient()

test('ZeebeGrpcClient can migrate a process instance', async () => {
expect(true).toBe(true)
// Deploy a process model

// const res = await zbc.deployResource({
// processFilename: './src/__tests__/testdata/Client-SkipFirstTask.bpmn',
// })
res = await zbc.deployResource({
processFilename: './src/__tests__/testdata/MigrateProcess-Version-1.bpmn',
})

// Create an instance of the process model

const processInstance = await zbc.createProcessInstance({
bpmnProcessId: 'migrant-work',
variables: {},
})

let instanceKey = ''
let processVersion = 0

await new Promise((res) => {
const w = zbc.createWorker({
taskType: 'migrant-worker-task-1',
taskHandler: async (job) => {
instanceKey = job.processInstanceKey
processVersion = job.customHeaders.ProcessVersion as number
return job.complete().then((outcome) => {
w.close()
res(null)
return outcome
})
},
})
})

expect(instanceKey).toBe(processInstance.processInstanceKey)
expect(processVersion).toBe('1')

// Deploy the updated process model
res1 = await zbc.deployResource({
processFilename: './src/__tests__/testdata/MigrateProcess-Version-2.bpmn',
})

// Migrate the process instance to the updated process model
await zbc.migrateProcessInstance({
processInstanceKey: processInstance.processInstanceKey,
migrationPlan: {
mappingInstructions: [
{
sourceElementId: 'Activity_050vmrm',
targetElementId: 'Activity_050vmrm',
},
],
targetProcessDefinitionKey:
res1?.deployments[0].process.processDefinitionKey,
},
})

// Complete the job in the process instance

// Assert that the job was completed in the new process model
await new Promise((res) => {
const w = zbc.createWorker({
taskType: 'migration-checkpoint',
taskHandler: async (job) => {
return job.complete().then((outcome) => {
w.close()
res(null)
return outcome
})
},
})
})

await new Promise((res) => {
const w = zbc.createWorker({
taskType: 'migrant-worker-task-2',
taskHandler: async (job) => {
instanceKey = job.processInstanceKey
processVersion = job.customHeaders.ProcessVersion as number
return job.complete().then((outcome) => {
w.close()
res(null)
return outcome
})
},
})
})

expect(instanceKey).toBe(processInstance.processInstanceKey)
expect(processVersion).toBe('2')
})
12 changes: 6 additions & 6 deletions src/zeebe/lib/interfaces-grpc-1.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export interface DecisionMetadata {
* the assigned decision key, which acts as a unique identifier for this
* decision
*/
decisionKey: number
decisionKey: string
/**
* the dmn ID of the decision requirements graph that this decision is part
* of, as parsed during deployment
Expand All @@ -329,7 +329,7 @@ export interface DecisionMetadata {
* the assigned key of the decision requirements graph that this decision is
* part of
*/
decisionRequirementsKey: number
decisionRequirementsKey: string
/** the tenant id of the deployed decision */
tenantId: string
}
Expand All @@ -348,7 +348,7 @@ export interface DecisionRequirementsMetadata {
* the assigned decision requirements key, which acts as a unique identifier
* for this decision requirements
*/
decisionRequirementsKey: number
decisionRequirementsKey: string
/**
* the resource name (see: Resource.name) from which this decision
* requirements was parsed
Expand All @@ -367,7 +367,7 @@ export interface FormMetadata {
/** the assigned form version */
readonly version: number
/** the assigned key, which acts as a unique identifier for this form */
readonly formKey: number
readonly formKey: string
/** the resource name */
readonly resourceName: string
/** the tenant id of the deployed form */
Expand Down Expand Up @@ -396,7 +396,7 @@ export type Deployment =

export interface DeployResourceResponse<T> {
/** the unique key identifying the deployment */
readonly key: number
readonly key: string
/** a list of deployed resources, e.g. processes */
readonly deployments: T[]
/** the tenant id of the deployed resources */
Expand Down Expand Up @@ -439,7 +439,7 @@ export interface PublishMessageRequest<Variables = IInputVariables> {

export interface PublishMessageResponse {
/** the unique ID of the message that was published */
key: number
key: string
/** the tenantId of the message */
tenantId: string
}
Expand Down
3 changes: 1 addition & 2 deletions src/zeebe/zb/ZeebeGrpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,7 @@ export class ZeebeGrpcClient extends TypedEmitter<

/**
*
* @param migrateProcessInstanceRequest
* @returns
* @since 8.5.0
*/
public migrateProcessInstance(
migrateProcessInstanceRequest: Grpc.MigrateProcessInstanceRequest
Expand Down

0 comments on commit f39085e

Please sign in to comment.