Search in sources :

Example 91 with Job

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

the class FoxJobRetryCmdTest method assertJobRetriesForActivity.

protected void assertJobRetriesForActivity(ProcessInstance pi, String activityId) {
    assertNotNull(pi);
    waitForExecutedJobWithRetriesLeft(4);
    stillOneJobWithExceptionAndRetriesLeft();
    Job job = fetchJob(pi.getProcessInstanceId());
    assertNotNull(job);
    assertEquals(pi.getProcessInstanceId(), job.getProcessInstanceId());
    assertEquals(4, job.getRetries());
    ExecutionEntity execution = fetchExecutionEntity(pi.getProcessInstanceId(), activityId);
    assertNotNull(execution);
    waitForExecutedJobWithRetriesLeft(3);
    job = refreshJob(job.getId());
    assertEquals(3, job.getRetries());
    stillOneJobWithExceptionAndRetriesLeft();
    execution = refreshExecutionEntity(execution.getId());
    assertEquals(activityId, execution.getActivityId());
    waitForExecutedJobWithRetriesLeft(2);
    job = refreshJob(job.getId());
    assertEquals(2, job.getRetries());
    stillOneJobWithExceptionAndRetriesLeft();
    execution = refreshExecutionEntity(execution.getId());
    assertEquals(activityId, execution.getActivityId());
    waitForExecutedJobWithRetriesLeft(1);
    job = refreshJob(job.getId());
    assertEquals(1, job.getRetries());
    stillOneJobWithExceptionAndRetriesLeft();
    execution = refreshExecutionEntity(execution.getId());
    assertEquals(activityId, execution.getActivityId());
    waitForExecutedJobWithRetriesLeft(0);
    job = refreshJob(job.getId());
    assertEquals(0, job.getRetries());
    assertEquals(1, managementService.createJobQuery().withException().count());
    assertEquals(0, managementService.createJobQuery().withRetriesLeft().count());
    assertEquals(1, managementService.createJobQuery().noRetriesLeft().count());
    execution = refreshExecutionEntity(execution.getId());
    assertEquals(activityId, execution.getActivityId());
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) Job(org.camunda.bpm.engine.runtime.Job)

Example 92 with Job

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

the class FoxJobRetryCmdTest method testFailedJobRetryTimeCycleWithChangingExpression.

public void testFailedJobRetryTimeCycleWithChangingExpression() throws ParseException {
    BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess("process").startEvent().serviceTask().camundaClass("foo").camundaAsyncBefore().camundaFailedJobRetryTimeCycle("${var}").endEvent().done();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    Date startDate = simpleDateFormat.parse("2017-01-01T09:55:00");
    ClockUtil.setCurrentTime(startDate);
    deployment(bpmnModelInstance);
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("process", Variables.createVariables().putValue("var", "R10/PT5M"));
    startDate = simpleDateFormat.parse("2017-01-01T10:00:00");
    ClockUtil.setCurrentTime(startDate);
    Job job = managementService.createJobQuery().singleResult();
    // when
    try {
        managementService.executeJob(job.getId());
    } catch (Exception e) {
    // ignore
    }
    job = managementService.createJobQuery().singleResult();
    Assert.assertEquals(9, job.getRetries());
    startDate = simpleDateFormat.parse("2017-01-01T10:05:00");
    ClockUtil.setCurrentTime(startDate);
    runtimeService.setVariable(pi.getProcessInstanceId(), "var", "R10/PT10M");
    try {
        managementService.executeJob(job.getId());
    } catch (Exception e) {
    // ignore
    }
    // then
    Date expectedDate = simpleDateFormat.parse("2017-01-01T10:15:00");
    Date lockExpirationTime = ((JobEntity) managementService.createJobQuery().singleResult()).getLockExpirationTime();
    assertEquals(expectedDate, lockExpirationTime);
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Job(org.camunda.bpm.engine.runtime.Job) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParseException(java.text.ParseException)

Example 93 with Job

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

the class AsyncAfterTest method testAsyncAfterIntermediateThrowEvent.

@Deployment
public void testAsyncAfterIntermediateThrowEvent() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("testIntermediateThrowEvent");
    // listeners should be fired by now
    assertListenerStartInvoked(pi);
    assertListenerEndInvoked(pi);
    // the process should wait *after* the throw 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 94 with Job

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

the class AsyncAfterTest method testAsyncAfterAndBeforeInclusiveGateway.

@Deployment
public void testAsyncAfterAndBeforeInclusiveGateway() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("testInclusiveGateway");
    // no listeners are fired:
    assertNotListenerStartInvoked(pi);
    assertNotListenerEndInvoked(pi);
    // we should wait *before* the gateway:
    Job job = managementService.createJobQuery().singleResult();
    assertNotNull(job);
    // after executing the gateway:
    managementService.executeJob(job.getId());
    // the listeners are fired:
    assertListenerStartInvoked(pi);
    assertListenerEndInvoked(pi);
    // and we will wait *after* the gateway:
    List<Job> jobs = managementService.createJobQuery().active().list();
    assertEquals(2, jobs.size());
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Job(org.camunda.bpm.engine.runtime.Job) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 95 with Job

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

the class AsyncAfterTest method testAsyncAfterInNestedWithoutTransition.

@Deployment
public void testAsyncAfterInNestedWithoutTransition() {
    // start process instance
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess");
    // the service task is completely invoked
    assertListenerStartInvoked(pi);
    assertBehaviorInvoked(pi);
    assertListenerEndInvoked(pi);
    // and the execution is waiting *after* the service task
    Job continuationJob = managementService.createJobQuery().singleResult();
    assertNotNull(continuationJob);
    // but the subprocess end listeners have not been invoked yet
    assertNull(runtimeService.getVariable(pi.getId(), "subprocess-listenerEndInvoked"));
    // if we execute the job, the listeners are invoked;
    managementService.executeJob(continuationJob.getId());
    assertTrue((Boolean) runtimeService.getVariable(pi.getId(), "subprocess-listenerEndInvoked"));
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Job(org.camunda.bpm.engine.runtime.Job) Deployment(org.camunda.bpm.engine.test.Deployment)

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