use of org.camunda.bpm.engine.runtime.Incident in project camunda-bpm-platform by camunda.
the class MigrationExternalTaskTest method testIncident.
@Test
public void testIncident() {
// given
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(ExternalTaskModels.ONE_EXTERNAL_TASK_PROCESS);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(ExternalTaskModels.ONE_EXTERNAL_TASK_PROCESS).changeElementId("externalTask", "newExternalTask"));
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("externalTask", "newExternalTask").build();
ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
ExternalTask externalTask = rule.getExternalTaskService().createExternalTaskQuery().singleResult();
rule.getExternalTaskService().setRetries(externalTask.getId(), 0);
Incident incidentBeforeMigration = rule.getRuntimeService().createIncidentQuery().singleResult();
// when
testHelper.migrateProcessInstance(migrationPlan, processInstance);
// then the incident has migrated
Incident incidentAfterMigration = rule.getRuntimeService().createIncidentQuery().singleResult();
assertNotNull(incidentAfterMigration);
assertEquals(incidentBeforeMigration.getId(), incidentAfterMigration.getId());
assertEquals(Incident.EXTERNAL_TASK_HANDLER_TYPE, incidentAfterMigration.getIncidentType());
assertEquals(externalTask.getId(), incidentAfterMigration.getConfiguration());
assertEquals("newExternalTask", incidentAfterMigration.getActivityId());
assertEquals(targetProcessDefinition.getId(), incidentAfterMigration.getProcessDefinitionId());
assertEquals(externalTask.getExecutionId(), incidentAfterMigration.getExecutionId());
// and it is possible to complete the process
rule.getExternalTaskService().setRetries(externalTask.getId(), 1);
LockedExternalTask task = fetchAndLockSingleTask(ExternalTaskModels.TOPIC);
rule.getExternalTaskService().complete(task.getId(), WORKER_ID);
testHelper.assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.runtime.Incident in project camunda-bpm-platform by camunda.
the class MigrationIncidentTest method testCustomIncidentMigration.
@Test
public void testCustomIncidentMigration() {
// 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(), "foo");
// 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 MigrationTransitionInstancesTest method testMigrateAsyncBeforeTransitionInstanceWithIncident.
@Test
public void testMigrateAsyncBeforeTransitionInstanceWithIncident() {
// given
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(AsyncProcessModels.ASYNC_BEFORE_USER_TASK_PROCESS);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(AsyncProcessModels.ASYNC_BEFORE_USER_TASK_PROCESS).changeElementId("userTask", "newUserTask"));
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask", "newUserTask").build();
ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(migrationPlan.getSourceProcessDefinitionId());
Job job = rule.getManagementService().createJobQuery().singleResult();
rule.getManagementService().setJobRetries(job.getId(), 0);
Incident incidentBeforeMigration = rule.getRuntimeService().createIncidentQuery().singleResult();
// when
testHelper.migrateProcessInstance(migrationPlan, processInstance);
// then
Incident incidentAfterMigration = rule.getRuntimeService().createIncidentQuery().singleResult();
assertNotNull(incidentAfterMigration);
// and it is still the same incident
assertEquals(incidentBeforeMigration.getId(), incidentAfterMigration.getId());
assertEquals(job.getId(), incidentAfterMigration.getConfiguration());
// and the activity and process definition references were updated
assertEquals("newUserTask", incidentAfterMigration.getActivityId());
assertEquals(targetProcessDefinition.getId(), incidentAfterMigration.getProcessDefinitionId());
// and it is possible to successfully execute the migrated job
rule.getManagementService().executeJob(job.getId());
// and complete the task and process instance
testHelper.completeTask("newUserTask");
testHelper.assertProcessEnded(testHelper.snapshotBeforeMigration.getProcessInstanceId());
}
use of org.camunda.bpm.engine.runtime.Incident in project camunda-bpm-platform by camunda.
the class JobEntity method createFailedJobIncident.
protected void createFailedJobIncident() {
final ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
if (processEngineConfiguration.isCreateIncidentOnFailedJobEnabled()) {
String incidentHandlerType = Incident.FAILED_JOB_HANDLER_TYPE;
// make sure job has an ID set:
if (id == null) {
id = processEngineConfiguration.getIdGenerator().getNextId();
} else {
// check whether there exists already an incident
// for this job
List<Incident> failedJobIncidents = Context.getCommandContext().getIncidentManager().findIncidentByConfigurationAndIncidentType(id, incidentHandlerType);
if (!failedJobIncidents.isEmpty()) {
return;
}
}
IncidentContext incidentContext = createIncidentContext();
incidentContext.setActivityId(getActivityId());
processEngineConfiguration.getIncidentHandler(incidentHandlerType).handleIncident(incidentContext, exceptionMessage);
}
}
use of org.camunda.bpm.engine.runtime.Incident in project camunda-bpm-platform by camunda.
the class IncidentTest method testShouldCreateOneIncidentAfterSetRetries.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/IncidentTest.testShouldCreateOneIncident.bpmn" })
public void testShouldCreateOneIncidentAfterSetRetries() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("failingProcess");
executeAvailableJobs();
List<Incident> incidents = runtimeService.createIncidentQuery().processInstanceId(processInstance.getId()).list();
assertFalse(incidents.isEmpty());
assertTrue(incidents.size() == 1);
Job job = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(job);
// set job retries to 1 -> should fail again and a second incident should be created
managementService.setJobRetries(job.getId(), 1);
executeAvailableJobs();
incidents = runtimeService.createIncidentQuery().processInstanceId(processInstance.getId()).list();
// There is still one incident
assertFalse(incidents.isEmpty());
assertTrue(incidents.size() == 1);
}
Aggregations