Search in sources :

Example 11 with HistoricIncident

use of org.camunda.bpm.engine.history.HistoricIncident in project camunda-bpm-platform by camunda.

the class MigrationHistoricIncidentTest method testMigrateHistoricIncidentAddScope.

@Test
public void testMigrateHistoricIncidentAddScope() {
    // given
    ProcessDefinition sourceProcess = testHelper.deployAndGetDefinition(AsyncProcessModels.ASYNC_BEFORE_USER_TASK_PROCESS);
    ProcessDefinition targetProcess = testHelper.deployAndGetDefinition(AsyncProcessModels.ASYNC_BEFORE_SUBPROCESS_USER_TASK_PROCESS);
    MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcess.getId(), targetProcess.getId()).mapActivities("userTask", "userTask").build();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcess.getId());
    Job job = managementService.createJobQuery().singleResult();
    managementService.setJobRetries(job.getId(), 0);
    // when
    runtimeService.newMigration(migrationPlan).processInstanceIds(Arrays.asList(processInstance.getId())).execute();
    // then
    ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstance.getId());
    HistoricIncident historicIncident = historyService.createHistoricIncidentQuery().singleResult();
    Assert.assertNotNull(historicIncident);
    Assert.assertEquals(activityInstance.getTransitionInstances("userTask")[0].getExecutionId(), historicIncident.getExecutionId());
}
Also used : HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Job(org.camunda.bpm.engine.runtime.Job) Test(org.junit.Test)

Example 12 with HistoricIncident

use of org.camunda.bpm.engine.history.HistoricIncident in project camunda-bpm-platform by camunda.

the class MigrationHistoricIncidentTest method testMigrateHistoricIncident.

@Test
public void testMigrateHistoricIncident() {
    // given
    ProcessDefinition sourceProcess = testHelper.deployAndGetDefinition(AsyncProcessModels.ASYNC_BEFORE_USER_TASK_PROCESS);
    ProcessDefinition targetProcess = testHelper.deployAndGetDefinition(modify(AsyncProcessModels.ASYNC_BEFORE_USER_TASK_PROCESS).changeElementId(ProcessModels.PROCESS_KEY, "new" + ProcessModels.PROCESS_KEY).changeElementId("userTask", "newUserTask"));
    JobDefinition targetJobDefinition = managementService.createJobDefinitionQuery().processDefinitionId(targetProcess.getId()).singleResult();
    MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceProcess.getId(), targetProcess.getId()).mapActivities("userTask", "newUserTask").build();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(sourceProcess.getId());
    Job job = managementService.createJobQuery().singleResult();
    managementService.setJobRetries(job.getId(), 0);
    HistoricIncident incidentBeforeMigration = historyService.createHistoricIncidentQuery().singleResult();
    // when
    runtimeService.newMigration(migrationPlan).processInstanceIds(Arrays.asList(processInstance.getId())).execute();
    // then
    HistoricIncident historicIncident = historyService.createHistoricIncidentQuery().singleResult();
    Assert.assertNotNull(historicIncident);
    Assert.assertEquals("newUserTask", historicIncident.getActivityId());
    Assert.assertEquals(targetJobDefinition.getId(), historicIncident.getJobDefinitionId());
    Assert.assertEquals(targetProcess.getId(), historicIncident.getProcessDefinitionId());
    Assert.assertEquals(targetProcess.getKey(), historicIncident.getProcessDefinitionKey());
    Assert.assertEquals(processInstance.getId(), historicIncident.getExecutionId());
    // and other properties have not changed
    Assert.assertEquals(incidentBeforeMigration.getCreateTime(), historicIncident.getCreateTime());
    Assert.assertEquals(incidentBeforeMigration.getProcessInstanceId(), historicIncident.getProcessInstanceId());
}
Also used : HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Job(org.camunda.bpm.engine.runtime.Job) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Test(org.junit.Test)

Example 13 with HistoricIncident

use of org.camunda.bpm.engine.history.HistoricIncident in project camunda-bpm-platform by camunda.

the class HistoricIncidentTest method testDoNotCreateNewIncident.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneFailingServiceProcess.bpmn20.xml" })
public void testDoNotCreateNewIncident() {
    startProcessInstance(PROCESS_DEFINITION_KEY);
    ProcessInstance pi = runtimeService.createProcessInstanceQuery().singleResult();
    HistoricIncidentQuery query = historyService.createHistoricIncidentQuery().processInstanceId(pi.getId());
    HistoricIncident incident = query.singleResult();
    assertNotNull(incident);
    JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();
    // set retries to 1 by job definition id
    managementService.setJobRetriesByJobDefinitionId(jobDefinition.getId(), 1);
    // the incident still exists
    HistoricIncident tmp = query.singleResult();
    assertEquals(incident.getId(), tmp.getId());
    assertNull(tmp.getEndTime());
    assertTrue(tmp.isOpen());
    // execute the available job (should fail again)
    executeAvailableJobs();
    // the incident still exists and there
    // should be not a new incident
    assertEquals(1, query.count());
    tmp = query.singleResult();
    assertEquals(incident.getId(), tmp.getId());
    assertNull(tmp.getEndTime());
    assertTrue(tmp.isOpen());
}
Also used : HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricIncidentQuery(org.camunda.bpm.engine.history.HistoricIncidentQuery) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 14 with HistoricIncident

use of org.camunda.bpm.engine.history.HistoricIncident in project camunda-bpm-platform by camunda.

the class HistoricIncidentTest method testPropertiesOfHistoricIncident.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/oneFailingServiceProcess.bpmn20.xml" })
public void testPropertiesOfHistoricIncident() {
    startProcessInstance(PROCESS_DEFINITION_KEY);
    Incident incident = runtimeService.createIncidentQuery().singleResult();
    assertNotNull(incident);
    HistoricIncident historicIncident = historyService.createHistoricIncidentQuery().singleResult();
    assertNotNull(historicIncident);
    assertEquals(incident.getId(), historicIncident.getId());
    assertEquals(incident.getIncidentTimestamp(), historicIncident.getCreateTime());
    assertNull(historicIncident.getEndTime());
    assertEquals(incident.getIncidentType(), historicIncident.getIncidentType());
    assertEquals(incident.getIncidentMessage(), historicIncident.getIncidentMessage());
    assertEquals(incident.getExecutionId(), historicIncident.getExecutionId());
    assertEquals(incident.getActivityId(), historicIncident.getActivityId());
    assertEquals(incident.getProcessInstanceId(), historicIncident.getProcessInstanceId());
    assertEquals(incident.getProcessDefinitionId(), historicIncident.getProcessDefinitionId());
    assertEquals(PROCESS_DEFINITION_KEY, historicIncident.getProcessDefinitionKey());
    assertEquals(incident.getCauseIncidentId(), historicIncident.getCauseIncidentId());
    assertEquals(incident.getRootCauseIncidentId(), historicIncident.getRootCauseIncidentId());
    assertEquals(incident.getConfiguration(), historicIncident.getConfiguration());
    assertEquals(incident.getJobDefinitionId(), historicIncident.getJobDefinitionId());
    assertTrue(historicIncident.isOpen());
    assertFalse(historicIncident.isDeleted());
    assertFalse(historicIncident.isResolved());
}
Also used : HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) Incident(org.camunda.bpm.engine.runtime.Incident) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 15 with HistoricIncident

use of org.camunda.bpm.engine.history.HistoricIncident in project camunda-bpm-platform by camunda.

the class HistoricIncidentTest method testCreateRecursiveHistoricIncidents.

@Deployment(resources = { "org/camunda/bpm/engine/test/history/HistoricIncidentQueryTest.testQueryByCauseIncidentId.bpmn20.xml", "org/camunda/bpm/engine/test/api/runtime/oneFailingServiceProcess.bpmn20.xml" })
public void testCreateRecursiveHistoricIncidents() {
    startProcessInstance("process");
    ProcessInstance pi1 = runtimeService.createProcessInstanceQuery().processDefinitionKey("process").singleResult();
    assertNotNull(pi1);
    ProcessInstance pi2 = runtimeService.createProcessInstanceQuery().processDefinitionKey(PROCESS_DEFINITION_KEY).singleResult();
    assertNotNull(pi2);
    HistoricIncidentQuery query = historyService.createHistoricIncidentQuery();
    HistoricIncident rootCauseHistoricIncident = query.processInstanceId(pi2.getId()).singleResult();
    assertNotNull(rootCauseHistoricIncident);
    // cause and root cause id is equal to the id of the root incident
    assertEquals(rootCauseHistoricIncident.getId(), rootCauseHistoricIncident.getCauseIncidentId());
    assertEquals(rootCauseHistoricIncident.getId(), rootCauseHistoricIncident.getRootCauseIncidentId());
    HistoricIncident historicIncident = query.processInstanceId(pi1.getId()).singleResult();
    assertNotNull(historicIncident);
    // cause and root cause id is equal to the id of the root incident
    assertEquals(rootCauseHistoricIncident.getId(), historicIncident.getCauseIncidentId());
    assertEquals(rootCauseHistoricIncident.getId(), historicIncident.getRootCauseIncidentId());
}
Also used : HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricIncidentQuery(org.camunda.bpm.engine.history.HistoricIncidentQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)25 Deployment (org.camunda.bpm.engine.test.Deployment)12 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)8 List (java.util.List)7 HistoricIncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity)7 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)7 HistoricIncidentQuery (org.camunda.bpm.engine.history.HistoricIncidentQuery)6 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)5 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)4 ArrayList (java.util.ArrayList)3 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)3 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)3 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)3 JobDefinition (org.camunda.bpm.engine.management.JobDefinition)3 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)3 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)3 Incident (org.camunda.bpm.engine.runtime.Incident)3 Test (org.junit.Test)3 LockedExternalTask (org.camunda.bpm.engine.externaltask.LockedExternalTask)2 Job (org.camunda.bpm.engine.runtime.Job)2