Search in sources :

Example 71 with Incident

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());
}
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 72 with Incident

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);
}
Also used : CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) SetProcessDefinitionVersionCmd(org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Incident(org.camunda.bpm.engine.runtime.Incident) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 73 with Incident

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

Example 74 with Incident

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

Example 75 with Incident

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());
}
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)

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