use of org.camunda.bpm.engine.runtime.Incident in project camunda-bpm-platform by camunda.
the class MigrationIncidentTest method testCustomIncidentMigrationWithoutConfiguration.
@Test
public void testCustomIncidentMigrationWithoutConfiguration() {
// given
RuntimeService runtimeService = engineRule.getRuntimeService();
BpmnModelInstance instance1 = Bpmn.createExecutableProcess("process1").startEvent().userTask("u1").endEvent().done();
BpmnModelInstance instance2 = Bpmn.createExecutableProcess("process2").startEvent().userTask("u2").endEvent().done();
testHelper.deploy(instance1, instance2);
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("process1");
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("process2");
MigrationPlan migrationPlan = runtimeService.createMigrationPlan(processInstance1.getProcessDefinitionId(), processInstance2.getProcessDefinitionId()).mapActivities("u1", "u2").build();
runtimeService.createIncident("custom", processInstance1.getId(), null);
// when
runtimeService.newMigration(migrationPlan).processInstanceIds(processInstance1.getId()).execute();
// then
Incident incident = runtimeService.createIncidentQuery().singleResult();
assertEquals(processInstance2.getProcessDefinitionId(), incident.getProcessDefinitionId());
assertEquals("custom", incident.getIncidentType());
assertEquals(processInstance1.getId(), incident.getExecutionId());
}
use of org.camunda.bpm.engine.runtime.Incident in project camunda-bpm-platform by camunda.
the class SetProcessDefinitionVersionCmdTest method testSetProcessDefinitionVersionMigrateIncident.
@Deployment(resources = TEST_PROCESS_ONE_JOB)
public void testSetProcessDefinitionVersionMigrateIncident() {
// given a process instance
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneJobProcess", Variables.createVariables().putValue("shouldFail", true));
// with a failed job
executeAvailableJobs();
// and an incident
Incident incident = runtimeService.createIncidentQuery().singleResult();
assertNotNull(incident);
// and a second deployment of the process
org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource(TEST_PROCESS_ONE_JOB).deploy();
ProcessDefinition newDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
assertNotNull(newDefinition);
// when the process instance is migrated
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new SetProcessDefinitionVersionCmd(instance.getId(), 2));
// then the the incident should also be migrated
Incident migratedIncident = runtimeService.createIncidentQuery().singleResult();
assertNotNull(migratedIncident);
assertEquals(newDefinition.getId(), migratedIncident.getProcessDefinitionId());
assertEquals(instance.getId(), migratedIncident.getProcessInstanceId());
assertEquals(instance.getId(), migratedIncident.getExecutionId());
repositoryService.deleteDeployment(deployment.getId(), true);
}
use of org.camunda.bpm.engine.runtime.Incident in project camunda-bpm-platform by camunda.
the class MigrationRemoveBoundaryEventsTest method testRemoveIncidentForJob.
@Test
public void testRemoveIncidentForJob() {
// given
BpmnModelInstance sourceProcess = modify(ProcessModels.ONE_TASK_PROCESS).userTaskBuilder("userTask").boundaryEvent("boundary").timerWithDate(TIMER_DATE).serviceTask("failingTask").camundaClass("org.camunda.bpm.engine.test.api.runtime.FailingDelegate").endEvent().done();
BpmnModelInstance targetProcess = modify(sourceProcess).changeElementId("userTask", "newUserTask").changeElementId("boundary", "newBoundary");
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(sourceProcess);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(targetProcess);
ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
// a timer job exists
Job jobBeforeMigration = rule.getManagementService().createJobQuery().singleResult();
assertNotNull(jobBeforeMigration);
// if the timer job is triggered the failing delegate fails and an incident is created
executeJob(jobBeforeMigration);
Incident incidentBeforeMigration = rule.getRuntimeService().createIncidentQuery().singleResult();
assertEquals("boundary", incidentBeforeMigration.getActivityId());
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask", "newUserTask").build();
// when
testHelper.migrateProcessInstance(migrationPlan, processInstance);
// then the incident was removed
Job jobAfterMigration = rule.getManagementService().createJobQuery().jobId(jobBeforeMigration.getId()).singleResult();
assertNull(jobAfterMigration);
assertEquals(0, rule.getRuntimeService().createIncidentQuery().count());
}
use of org.camunda.bpm.engine.runtime.Incident in project camunda-bpm-platform by camunda.
the class MigrationBoundaryEventsTest method testMigrateIncidentForJob.
@Test
public void testMigrateIncidentForJob() {
// given
BpmnModelInstance sourceProcess = modify(ProcessModels.ONE_TASK_PROCESS).userTaskBuilder(USER_TASK_ID).boundaryEvent(BOUNDARY_ID).timerWithDate(TIMER_DATE).serviceTask("failingTask").camundaClass(FailingDelegate.class.getName()).endEvent().done();
BpmnModelInstance targetProcess = modify(sourceProcess).changeElementId(USER_TASK_ID, "newUserTask").changeElementId(BOUNDARY_ID, "newBoundary");
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(sourceProcess);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(targetProcess);
ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
// a timer job exists
Job jobBeforeMigration = rule.getManagementService().createJobQuery().singleResult();
assertNotNull(jobBeforeMigration);
// if the timer job is triggered the failing delegate fails and an incident is created
executeJob(jobBeforeMigration);
Incident incidentBeforeMigration = rule.getRuntimeService().createIncidentQuery().singleResult();
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities(USER_TASK_ID, "newUserTask").mapActivities(BOUNDARY_ID, "newBoundary").build();
// when
testHelper.migrateProcessInstance(migrationPlan, processInstance);
// then the job and incident still exists
Job jobAfterMigration = rule.getManagementService().createJobQuery().jobId(jobBeforeMigration.getId()).singleResult();
assertNotNull(jobAfterMigration);
Incident incidentAfterMigration = rule.getRuntimeService().createIncidentQuery().singleResult();
assertNotNull(incidentAfterMigration);
// and it is still the same incident
assertEquals(incidentBeforeMigration.getId(), incidentAfterMigration.getId());
assertEquals(jobAfterMigration.getId(), incidentAfterMigration.getConfiguration());
// and the activity, process definition and job definition references were updated
assertEquals("newBoundary", incidentAfterMigration.getActivityId());
assertEquals(targetProcessDefinition.getId(), incidentAfterMigration.getProcessDefinitionId());
assertEquals(jobAfterMigration.getJobDefinitionId(), incidentAfterMigration.getJobDefinitionId());
}
use of org.camunda.bpm.engine.runtime.Incident in project camunda-bpm-platform by camunda.
the class MigrationEventSubProcessTest method testMigrateEventSubprocessTimerIncident.
@Test
public void testMigrateEventSubprocessTimerIncident() {
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(EventSubProcessModels.TIMER_EVENT_SUBPROCESS_PROCESS);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(EventSubProcessModels.TIMER_EVENT_SUBPROCESS_PROCESS);
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities(USER_TASK_ID, USER_TASK_ID).mapActivities(EVENT_SUB_PROCESS_START_ID, EVENT_SUB_PROCESS_START_ID).build();
ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
Job timerTriggerJob = rule.getManagementService().createJobQuery().singleResult();
// create an incident
rule.getManagementService().setJobRetries(timerTriggerJob.getId(), 0);
Incident incidentBeforeMigration = rule.getRuntimeService().createIncidentQuery().singleResult();
// when
testHelper.migrateProcessInstance(migrationPlan, processInstance);
// then
Incident incidentAfterMigration = rule.getRuntimeService().createIncidentQuery().singleResult();
assertNotNull(incidentAfterMigration);
assertEquals(incidentBeforeMigration.getId(), incidentAfterMigration.getId());
assertEquals(timerTriggerJob.getId(), incidentAfterMigration.getConfiguration());
assertEquals(EVENT_SUB_PROCESS_START_ID, incidentAfterMigration.getActivityId());
assertEquals(targetProcessDefinition.getId(), incidentAfterMigration.getProcessDefinitionId());
// and it is possible to complete the process
rule.getManagementService().executeJob(timerTriggerJob.getId());
testHelper.completeTask(EVENT_SUB_PROCESS_TASK_ID);
testHelper.assertProcessEnded(processInstance.getId());
}
Aggregations