ProcessInstance asyncAfterInstance = runtimeService.startProcessInstanceByKey("twoJobsProcess");
// with an async after job
String jobId = managementService.createJobQuery().singleResult().getId();
managementService.executeJob(jobId);
Job asyncAfterJob = managementService.createJobQuery().singleResult();
// and a process instance with an before after job
ProcessInstance asyncBeforeInstance = runtimeService.startProcessInstanceByKey("twoJobsProcess");
Job asyncBeforeJob = managementService.createJobQuery()
.processInstanceId(asyncBeforeInstance.getId()).singleResult();
// and a second deployment of the process
org.camunda.bpm.engine.repository.Deployment deployment = repositoryService
.createDeployment()
.addClasspathResource(TEST_PROCESS_TWO_JOBS)
.deploy();
ProcessDefinition newDefinition =
repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
assertNotNull(newDefinition);
JobDefinition asnycBeforeJobDefinition =
managementService.createJobDefinitionQuery()
.jobConfiguration(MessageJobDeclaration.ASYNC_BEFORE)
.processDefinitionId(newDefinition.getId())
.singleResult();
JobDefinition asnycAfterJobDefinition =
managementService.createJobDefinitionQuery()
.jobConfiguration(MessageJobDeclaration.ASYNC_AFTER)
.processDefinitionId(newDefinition.getId())
.singleResult();
assertNotNull(asnycBeforeJobDefinition);
assertNotNull(asnycAfterJobDefinition);
// when the process instances are migrated
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new SetProcessDefinitionVersionCmd(asyncBeforeInstance.getId(), 2));
commandExecutor.execute(new SetProcessDefinitionVersionCmd(asyncAfterInstance.getId(), 2));
// then the the job's definition reference should also be migrated
Job migratedAsyncBeforeJob = managementService.createJobQuery()
.processInstanceId(asyncBeforeInstance.getId()).singleResult();
assertEquals(asyncBeforeJob.getId(), migratedAsyncBeforeJob.getId());
assertNotNull(migratedAsyncBeforeJob);
assertEquals(asnycBeforeJobDefinition.getId(), migratedAsyncBeforeJob.getJobDefinitionId());
Job migratedAsyncAfterJob = managementService.createJobQuery()
.processInstanceId(asyncAfterInstance.getId()).singleResult();
assertEquals(asyncAfterJob.getId(), migratedAsyncAfterJob.getId());
assertNotNull(migratedAsyncAfterJob);
assertEquals(asnycAfterJobDefinition.getId(), migratedAsyncAfterJob.getJobDefinitionId());
repositoryService.deleteDeployment(deployment.getId(), true);
}