Search in sources :

Example 66 with Job

use of org.camunda.bpm.engine.runtime.Job in project camunda-bpm-platform by camunda.

the class MigrationTransitionInstancesTest method testCannotMigrateUnmappedTransitionInstanceWithIncident.

@Test
public void testCannotMigrateUnmappedTransitionInstanceWithIncident() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(AsyncProcessModels.ASYNC_BEFORE_USER_TASK_PROCESS);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(AsyncProcessModels.ASYNC_BEFORE_USER_TASK_PROCESS);
    // the user task is not mapped in the migration plan, i.e. there is no instruction to migrate the job
    // and the incident
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).build();
    ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(migrationPlan.getSourceProcessDefinitionId());
    Job job = rule.getManagementService().createJobQuery().singleResult();
    rule.getManagementService().setJobRetries(job.getId(), 0);
    // when
    try {
        testHelper.migrateProcessInstance(migrationPlan, processInstance);
        Assert.fail("should fail");
    } catch (MigratingProcessInstanceValidationException e) {
        // then
        assertThat(e.getValidationReport()).hasTransitionInstanceFailures("userTask", "There is no migration instruction for this instance's activity");
    }
}
Also used : MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) MigratingProcessInstanceValidationException(org.camunda.bpm.engine.migration.MigratingProcessInstanceValidationException) Job(org.camunda.bpm.engine.runtime.Job) Test(org.junit.Test)

Example 67 with Job

use of org.camunda.bpm.engine.runtime.Job in project camunda-bpm-platform by camunda.

the class MigrationTransitionInstancesTest method testMigrateAsyncBeforeTransitionInstanceAddIncomingFlow.

@Test
public void testMigrateAsyncBeforeTransitionInstanceAddIncomingFlow() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(modify(AsyncProcessModels.ASYNC_BEFORE_USER_TASK_PROCESS).removeFlowNode("startEvent"));
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(AsyncProcessModels.ASYNC_BEFORE_USER_TASK_PROCESS);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities("userTask", "userTask").build();
    // when
    ProcessInstance processInstance = rule.getRuntimeService().createProcessInstanceById(sourceProcessDefinition.getId()).startBeforeActivity("userTask").execute();
    testHelper.migrateProcessInstance(migrationPlan, processInstance);
    // then
    testHelper.assertJobMigrated("userTask", "userTask", AsyncContinuationJobHandler.TYPE);
    // and it is possible to successfully execute the migrated job
    Job job = testHelper.snapshotAfterMigration.getJobs().get(0);
    rule.getManagementService().executeJob(job.getId());
    // and complete the task and process instance
    testHelper.completeTask("userTask");
    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) Job(org.camunda.bpm.engine.runtime.Job) Test(org.junit.Test)

Example 68 with Job

use of org.camunda.bpm.engine.runtime.Job in project camunda-bpm-platform by camunda.

the class MigrationTransitionInstancesTest method testMigrateAsyncAfterTransitionInstanceAddOutgoingFlowCase1.

@Test
public void testMigrateAsyncAfterTransitionInstanceAddOutgoingFlowCase1() {
    // given
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(modify(AsyncProcessModels.ASYNC_AFTER_USER_TASK_PROCESS).removeFlowNode("endEvent").removeFlowNode("userTask2"));
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(AsyncProcessModels.ASYNC_AFTER_USER_TASK_PROCESS);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapEqualActivities().build();
    ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
    testHelper.completeTask("userTask1");
    // when
    testHelper.migrateProcessInstance(migrationPlan, processInstance);
    // then
    testHelper.assertJobMigrated("userTask1", "userTask1", AsyncContinuationJobHandler.TYPE);
    // and it is possible to successfully execute the migrated job
    Job job = testHelper.snapshotAfterMigration.getJobs().get(0);
    rule.getManagementService().executeJob(job.getId());
    // and complete the process instance
    testHelper.completeTask("userTask2");
    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) Job(org.camunda.bpm.engine.runtime.Job) Test(org.junit.Test)

Example 69 with Job

use of org.camunda.bpm.engine.runtime.Job in project camunda-bpm-platform by camunda.

the class SetProcessDefinitionVersionCmdTest method testSetProcessDefinitionVersionMigrateJob.

@Deployment(resources = TEST_PROCESS_ONE_JOB)
public void testSetProcessDefinitionVersionMigrateJob() {
    // given a process instance
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneJobProcess");
    // with a job
    Job job = managementService.createJobQuery().singleResult();
    assertNotNull(job);
    // 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 job should also be migrated
    Job migratedJob = managementService.createJobQuery().singleResult();
    assertNotNull(migratedJob);
    assertEquals(job.getId(), migratedJob.getId());
    assertEquals(newDefinition.getId(), migratedJob.getProcessDefinitionId());
    assertEquals(deployment.getId(), migratedJob.getDeploymentId());
    JobDefinition newJobDefinition = managementService.createJobDefinitionQuery().processDefinitionId(newDefinition.getId()).singleResult();
    assertNotNull(newJobDefinition);
    assertEquals(newJobDefinition.getId(), migratedJob.getJobDefinitionId());
    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) Job(org.camunda.bpm.engine.runtime.Job) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 70 with Job

use of org.camunda.bpm.engine.runtime.Job in project camunda-bpm-platform by camunda.

the class MigrationBoundaryEventsTest method testUpdateEventTimer.

@Test
public void testUpdateEventTimer() {
    // given
    ClockTestUtil.setClockToDateWithoutMilliseconds();
    BpmnModelInstance sourceProcess = modify(ProcessModels.ONE_TASK_PROCESS).activityBuilder(USER_TASK_ID).boundaryEvent(BOUNDARY_ID).timerWithDate(TIMER_DATE).userTask(AFTER_BOUNDARY_TASK).endEvent().done();
    BpmnModelInstance targetProcess = modify(ProcessModels.ONE_TASK_PROCESS).activityBuilder(USER_TASK_ID).boundaryEvent(BOUNDARY_ID).timerWithDuration("PT50M").userTask(AFTER_BOUNDARY_TASK).endEvent().done();
    ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(sourceProcess);
    ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(targetProcess);
    MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities(USER_TASK_ID, USER_TASK_ID).mapActivities(BOUNDARY_ID, BOUNDARY_ID).updateEventTrigger().build();
    // when
    testHelper.createProcessInstanceAndMigrate(migrationPlan);
    // then
    Date newDueDate = new DateTime(ClockUtil.getCurrentTime()).plusMinutes(50).toDate();
    testHelper.assertJobMigrated(testHelper.snapshotBeforeMigration.getJobs().get(0), BOUNDARY_ID, newDueDate);
    // and it is possible to successfully complete the migrated instance
    Job jobAfterMigration = testHelper.snapshotAfterMigration.getJobs().get(0);
    rule.getManagementService().executeJob(jobAfterMigration.getId());
    testHelper.completeTask(AFTER_BOUNDARY_TASK);
    testHelper.assertProcessEnded(testHelper.snapshotBeforeMigration.getProcessInstanceId());
}
Also used : MigrationPlan(org.camunda.bpm.engine.migration.MigrationPlan) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Job(org.camunda.bpm.engine.runtime.Job) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

Job (org.camunda.bpm.engine.runtime.Job)696 Deployment (org.camunda.bpm.engine.test.Deployment)310 Test (org.junit.Test)232 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)189 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)148 JobDefinition (org.camunda.bpm.engine.management.JobDefinition)135 JobQuery (org.camunda.bpm.engine.runtime.JobQuery)116 HashMap (java.util.HashMap)98 Batch (org.camunda.bpm.engine.batch.Batch)78 JobDefinitionQuery (org.camunda.bpm.engine.management.JobDefinitionQuery)78 Task (org.camunda.bpm.engine.task.Task)71 Date (java.util.Date)67 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)48 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)24 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)23 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)21 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)20 Incident (org.camunda.bpm.engine.runtime.Incident)17 HistoricJobLog (org.camunda.bpm.engine.history.HistoricJobLog)15 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)15