Search in sources :

Example 16 with Incident

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());
}
Also used : MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Incident(org.camunda.bpm.engine.runtime.Incident) ExternalTask(org.camunda.bpm.engine.externaltask.ExternalTask) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) Test(org.junit.Test)

Example 17 with Incident

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());
}
Also used : RuntimeService(org.camunda.bpm.engine.RuntimeService) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) Incident(org.camunda.bpm.engine.runtime.Incident) Test(org.junit.Test)

Example 18 with Incident

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());
}
Also used : MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Incident(org.camunda.bpm.engine.runtime.Incident) Job(org.camunda.bpm.engine.runtime.Job) Test(org.junit.Test)

Example 19 with Incident

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);
    }
}
Also used : IncidentContext(org.camunda.bpm.engine.impl.incident.IncidentContext) Incident(org.camunda.bpm.engine.runtime.Incident) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)

Example 20 with Incident

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);
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Incident(org.camunda.bpm.engine.runtime.Incident) Job(org.camunda.bpm.engine.runtime.Job) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

Incident (org.camunda.bpm.engine.runtime.Incident)100 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)50 Test (org.junit.Test)50 Deployment (org.camunda.bpm.engine.test.Deployment)40 IncidentQuery (org.camunda.bpm.engine.runtime.IncidentQuery)34 HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)19 Job (org.camunda.bpm.engine.runtime.Job)17 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)14 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)13 Execution (org.camunda.bpm.engine.runtime.Execution)10 LockedExternalTask (org.camunda.bpm.engine.externaltask.LockedExternalTask)9 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)8 ProcessDefinitionQuery (org.camunda.bpm.engine.repository.ProcessDefinitionQuery)4 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)4 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)3 HistoricIncidentQuery (org.camunda.bpm.engine.history.HistoricIncidentQuery)3 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)3 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)2 RuntimeService (org.camunda.bpm.engine.RuntimeService)2 ExternalTask (org.camunda.bpm.engine.externaltask.ExternalTask)2