Search in sources :

Example 96 with Job

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

the class AsyncAfterTest method testAsyncAfterErrorEvent.

public void testAsyncAfterErrorEvent() {
    // given
    BpmnModelInstance instance = Bpmn.createExecutableProcess("process").startEvent().serviceTask("servTask").camundaClass(ThrowBpmnErrorDelegate.class).boundaryEvent().camundaAsyncAfter(true).camundaFailedJobRetryTimeCycle("R10/PT10S").errorEventDefinition().errorEventDefinitionDone().serviceTask().camundaClass("foo").endEvent().moveToActivity("servTask").endEvent().done();
    deployment(instance);
    runtimeService.startProcessInstanceByKey("process");
    Job job = managementService.createJobQuery().singleResult();
    // when job fails
    try {
        managementService.executeJob(job.getId());
    } catch (Exception e) {
    // ignore
    }
    // then
    job = managementService.createJobQuery().singleResult();
    Assert.assertEquals(9, job.getRetries());
}
Also used : ThrowBpmnErrorDelegate(org.camunda.bpm.engine.test.bpmn.event.error.ThrowBpmnErrorDelegate) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Job(org.camunda.bpm.engine.runtime.Job) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 97 with Job

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

the class AsyncCallActivityTest method testCallProcessWithAsyncOnStartEvent.

@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/async/AsyncCallActivityTest.asyncStartEvent.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/async/AsyncCallActivityTest.testCallSubProcess.bpmn20.xml" })
public void testCallProcessWithAsyncOnStartEvent() {
    runtimeService.startProcessInstanceByKey("callAsyncSubProcess");
    Job job = managementService.createJobQuery().singleResult();
    assertNotNull(job);
    managementService.executeJob(job.getId());
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    taskService.complete(task.getId());
}
Also used : Task(org.camunda.bpm.engine.task.Task) Job(org.camunda.bpm.engine.runtime.Job) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 98 with Job

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

the class ProcessDefinitionManager method deleteTimerStartEventsForProcessDefinition.

/**
 * Deletes the timer start events for the given process definition.
 *
 * @param processDefinition the process definition
 */
protected void deleteTimerStartEventsForProcessDefinition(ProcessDefinition processDefinition) {
    List<JobEntity> timerStartJobs = getJobManager().findJobsByConfiguration(TimerStartEventJobHandler.TYPE, processDefinition.getKey(), processDefinition.getTenantId());
    ProcessDefinitionEntity latestVersion = getProcessDefinitionManager().findLatestProcessDefinitionByKeyAndTenantId(processDefinition.getKey(), processDefinition.getTenantId());
    // delete timer start event jobs only if this is the latest version of the process definition.
    if (latestVersion != null && latestVersion.getId().equals(processDefinition.getId())) {
        for (Job job : timerStartJobs) {
            ((JobEntity) job).delete();
        }
    }
}
Also used : Job(org.camunda.bpm.engine.runtime.Job)

Example 99 with Job

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

the class HistoricIncidentAuthorizationTest method testMixedQueryWithReadHistoryPermissionOnAnyProcessDefinition.

public void testMixedQueryWithReadHistoryPermissionOnAnyProcessDefinition() {
    // given
    disableAuthorization();
    repositoryService.suspendProcessDefinitionByKey(ONE_INCIDENT_PROCESS_KEY, true, new Date());
    String firstJobId = null;
    List<Job> jobs = managementService.createJobQuery().withRetriesLeft().list();
    for (Job job : jobs) {
        if (job.getProcessDefinitionKey() == null) {
            firstJobId = job.getId();
            break;
        }
    }
    managementService.setJobRetries(firstJobId, 0);
    repositoryService.suspendProcessDefinitionByKey(ONE_INCIDENT_PROCESS_KEY, true, new Date());
    String secondJobId = null;
    jobs = managementService.createJobQuery().withRetriesLeft().list();
    for (Job job : jobs) {
        if (job.getProcessDefinitionKey() == null) {
            secondJobId = job.getId();
            break;
        }
    }
    managementService.setJobRetries(secondJobId, 0);
    enableAuthorization();
    startProcessAndExecuteJob(ONE_INCIDENT_PROCESS_KEY);
    startProcessAndExecuteJob(ONE_INCIDENT_PROCESS_KEY);
    startProcessAndExecuteJob(ANOTHER_ONE_INCIDENT_PROCESS_KEY);
    startProcessAndExecuteJob(ANOTHER_ONE_INCIDENT_PROCESS_KEY);
    startProcessAndExecuteJob(ANOTHER_ONE_INCIDENT_PROCESS_KEY);
    createGrantAuthorization(PROCESS_DEFINITION, ANY, userId, READ_HISTORY);
    // when
    HistoricIncidentQuery query = historyService.createHistoricIncidentQuery();
    // then
    verifyQueryResults(query, 7);
    disableAuthorization();
    managementService.deleteJob(firstJobId);
    managementService.deleteJob(secondJobId);
    enableAuthorization();
    clearDatabase();
}
Also used : Job(org.camunda.bpm.engine.runtime.Job) HistoricIncidentQuery(org.camunda.bpm.engine.history.HistoricIncidentQuery) Date(java.util.Date)

Example 100 with Job

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

the class HistoricIncidentAuthorizationTest method testMixedQueryWithoutAuthorization.

// historic job log (mixed) //////////////////////////////////////////
public void testMixedQueryWithoutAuthorization() {
    // given
    disableAuthorization();
    repositoryService.suspendProcessDefinitionByKey(ONE_INCIDENT_PROCESS_KEY, true, new Date());
    String firstJobId = null;
    List<Job> jobs = managementService.createJobQuery().withRetriesLeft().list();
    for (Job job : jobs) {
        if (job.getProcessDefinitionKey() == null) {
            firstJobId = job.getId();
            break;
        }
    }
    managementService.setJobRetries(firstJobId, 0);
    repositoryService.suspendProcessDefinitionByKey(ONE_INCIDENT_PROCESS_KEY, true, new Date());
    String secondJobId = null;
    jobs = managementService.createJobQuery().withRetriesLeft().list();
    for (Job job : jobs) {
        if (job.getProcessDefinitionKey() == null) {
            secondJobId = job.getId();
            break;
        }
    }
    managementService.setJobRetries(secondJobId, 0);
    enableAuthorization();
    startProcessAndExecuteJob(ONE_INCIDENT_PROCESS_KEY);
    startProcessAndExecuteJob(ONE_INCIDENT_PROCESS_KEY);
    startProcessAndExecuteJob(ANOTHER_ONE_INCIDENT_PROCESS_KEY);
    startProcessAndExecuteJob(ANOTHER_ONE_INCIDENT_PROCESS_KEY);
    startProcessAndExecuteJob(ANOTHER_ONE_INCIDENT_PROCESS_KEY);
    // when
    HistoricIncidentQuery query = historyService.createHistoricIncidentQuery();
    // then
    verifyQueryResults(query, 2);
    disableAuthorization();
    managementService.deleteJob(firstJobId);
    managementService.deleteJob(secondJobId);
    enableAuthorization();
    clearDatabase();
}
Also used : Job(org.camunda.bpm.engine.runtime.Job) HistoricIncidentQuery(org.camunda.bpm.engine.history.HistoricIncidentQuery) Date(java.util.Date)

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