Search in sources :

Example 81 with Job

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

the class AsyncAfterTest method testAsyncAfterServiceTask.

@Deployment
public void testAsyncAfterServiceTask() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess");
    // listeners should be fired by now
    assertListenerStartInvoked(pi);
    assertListenerEndInvoked(pi);
    // the process should wait *after* the catch event
    Job job = managementService.createJobQuery().singleResult();
    assertNotNull(job);
    // if the waiting job is executed, the process instance should end
    managementService.executeJob(job.getId());
    assertProcessEnded(pi.getId());
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Job(org.camunda.bpm.engine.runtime.Job) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 82 with Job

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

the class AsyncAfterTest method testAsyncAfterIntermediateCatchEvent.

@Deployment
public void testAsyncAfterIntermediateCatchEvent() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("testIntermediateCatchEvent");
    // the intermediate catch event is waiting for its message
    runtimeService.correlateMessage("testMessage1");
    // listeners should be fired by now
    assertListenerStartInvoked(pi);
    assertListenerEndInvoked(pi);
    // the process should wait *after* the catch event
    Job job = managementService.createJobQuery().singleResult();
    assertNotNull(job);
    // if the waiting job is executed, the process instance should end
    managementService.executeJob(job.getId());
    assertProcessEnded(pi.getId());
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Job(org.camunda.bpm.engine.runtime.Job) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 83 with Job

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

the class AsyncTaskTest method testAsyncBeforeAndAfterParallelMultiInstanceWithAsyncBeforeAndAfterServiceWrappedInMultiInstance.

@Deployment
public void testAsyncBeforeAndAfterParallelMultiInstanceWithAsyncBeforeAndAfterServiceWrappedInMultiInstance() {
    NUM_INVOCATIONS = 0;
    // start process
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncService");
    // the service was not invoked:
    assertEquals(0, NUM_INVOCATIONS);
    // now there should be one job for the multi-instance body:
    assertEquals(1, managementService.createJobQuery().count());
    assertTransitionInstances(processInstance.getId(), "service" + BpmnParse.MULTI_INSTANCE_BODY_ID_SUFFIX, 1);
    // when the mi body before job is executed
    Job job = managementService.createJobQuery().singleResult();
    managementService.executeJob(job.getId());
    // then there are five inner async before jobs
    List<Job> innerBeforeJobs = managementService.createJobQuery().list();
    assertEquals(5, innerBeforeJobs.size());
    assertTransitionInstances(processInstance.getId(), "service", 5);
    assertEquals(0, NUM_INVOCATIONS);
    // when executing all inner jobs
    for (Job innerBeforeJob : innerBeforeJobs) {
        managementService.executeJob(innerBeforeJob.getId());
    }
    assertEquals(5, NUM_INVOCATIONS);
    // then there are five async after jobs
    List<Job> innerAfterJobs = managementService.createJobQuery().list();
    assertEquals(5, innerAfterJobs.size());
    assertTransitionInstances(processInstance.getId(), "service", 5);
    // when executing all inner jobs
    for (Job innerAfterJob : innerAfterJobs) {
        managementService.executeJob(innerAfterJob.getId());
    }
    // then there is one mi body after job
    job = managementService.createJobQuery().singleResult();
    assertNotNull(job);
    assertTransitionInstances(processInstance.getId(), "service" + BpmnParse.MULTI_INSTANCE_BODY_ID_SUFFIX, 1);
    // when executing this job, the process ends
    managementService.executeJob(job.getId());
    assertProcessEnded(processInstance.getId());
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Job(org.camunda.bpm.engine.runtime.Job) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 84 with Job

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

the class AsyncTaskTest method testFailingAsyncServiceTimer.

@Deployment
public void testFailingAsyncServiceTimer() {
    // start process
    runtimeService.startProcessInstanceByKey("asyncService");
    // now there should be one job in the database, and it is a message
    assertEquals(1, managementService.createJobQuery().count());
    Job job = managementService.createJobQuery().singleResult();
    if (!(job instanceof MessageEntity)) {
        fail("the job must be a message");
    }
    executeAvailableJobs();
    // the service failed: the execution is still sitting in the service task:
    Execution execution = runtimeService.createExecutionQuery().singleResult();
    assertNotNull(execution);
    assertEquals("service", runtimeService.getActiveActivityIds(execution.getId()).get(0));
    // there is still a single job because the timer was created in the same transaction as the
    // service was executed (which rolled back)
    assertEquals(1, managementService.createJobQuery().count());
    runtimeService.deleteProcessInstance(execution.getId(), "dead");
}
Also used : MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity) Execution(org.camunda.bpm.engine.runtime.Execution) Job(org.camunda.bpm.engine.runtime.Job) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 85 with Job

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

the class FoxJobRetryCmdEventsTest method assertJobRetries.

protected void assertJobRetries(ProcessInstance pi) {
    assertThat(pi, is(notNullValue()));
    Job job = fetchJob(pi.getProcessInstanceId());
    try {
        engineRule.getManagementService().executeJob(job.getId());
    } catch (Exception e) {
    }
    // update job
    job = fetchJob(pi.getProcessInstanceId());
    assertThat(job.getRetries(), is(4));
}
Also used : Job(org.camunda.bpm.engine.runtime.Job) ExpectedException(org.junit.rules.ExpectedException)

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