Search in sources :

Example 66 with JobDefinition

use of org.camunda.bpm.engine.management.JobDefinition in project camunda-bpm-platform by camunda.

the class ActivateJobDefinitionTest method testActivationById_shouldExecuteImmediatelyAndRetainJobs.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn" })
public void testActivationById_shouldExecuteImmediatelyAndRetainJobs() {
    // given
    // a deployed process definition with asynchronous continuation
    // a running process instance with a failed job
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("fail", Boolean.TRUE);
    runtimeService.startProcessInstanceByKey("suspensionProcess", params);
    // a job definition (which was created for the asynchronous continuation)
    JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();
    // ...which will be suspended with the corresponding jobs
    managementService.suspendJobDefinitionByProcessDefinitionKey("suspensionProcess", true);
    // when
    // activate the job definition
    managementService.activateJobDefinitionById(jobDefinition.getId(), false, null);
    // then
    // there exists an active job definition
    JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery();
    assertEquals(0, jobDefinitionQuery.suspended().count());
    assertEquals(1, jobDefinitionQuery.active().count());
    JobDefinition activeJobDefinition = jobDefinitionQuery.active().singleResult();
    assertEquals(jobDefinition.getId(), activeJobDefinition.getId());
    assertFalse(activeJobDefinition.isSuspended());
    // the corresponding job is still suspended
    JobQuery jobQuery = managementService.createJobQuery();
    assertEquals(0, jobQuery.active().count());
    assertEquals(1, jobQuery.suspended().count());
    Job suspendedJob = jobQuery.singleResult();
    assertEquals(jobDefinition.getId(), suspendedJob.getJobDefinitionId());
    assertTrue(suspendedJob.isSuspended());
}
Also used : JobDefinitionQuery(org.camunda.bpm.engine.management.JobDefinitionQuery) HashMap(java.util.HashMap) JobQuery(org.camunda.bpm.engine.runtime.JobQuery) Job(org.camunda.bpm.engine.runtime.Job) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 67 with JobDefinition

use of org.camunda.bpm.engine.management.JobDefinition in project camunda-bpm-platform by camunda.

the class ActivateJobDefinitionTest method testActivationById_shouldExecuteDelayedAndRetainJobs.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn" })
public void testActivationById_shouldExecuteDelayedAndRetainJobs() {
    // given
    // a deployed process definition with asynchronous continuation
    // a running process instance with a failed job
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("fail", Boolean.TRUE);
    runtimeService.startProcessInstanceByKey("suspensionProcess", params);
    // a job definition (which was created for the asynchronous continuation)
    JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();
    // ...which will be suspended with the corresponding jobs
    managementService.suspendJobDefinitionByProcessDefinitionKey("suspensionProcess", true);
    // when
    // activate the job definition
    managementService.activateJobDefinitionById(jobDefinition.getId(), false, oneWeekLater());
    // then
    // the job definition is still suspended
    JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery();
    assertEquals(0, jobDefinitionQuery.active().count());
    assertEquals(1, jobDefinitionQuery.suspended().count());
    // there exists a job for the delayed activation execution
    JobQuery jobQuery = managementService.createJobQuery();
    Job delayedActivationJob = jobQuery.timers().active().singleResult();
    assertNotNull(delayedActivationJob);
    // execute job
    managementService.executeJob(delayedActivationJob.getId());
    // the job definition should be suspended
    assertEquals(1, jobDefinitionQuery.active().count());
    assertEquals(0, jobDefinitionQuery.suspended().count());
    JobDefinition activeJobDefinition = jobDefinitionQuery.active().singleResult();
    assertEquals(jobDefinition.getId(), activeJobDefinition.getId());
    assertFalse(activeJobDefinition.isSuspended());
    // the corresponding job is still suspended
    jobQuery = managementService.createJobQuery();
    assertEquals(0, jobQuery.active().count());
    assertEquals(1, jobQuery.suspended().count());
    Job suspendedJob = jobQuery.singleResult();
    assertEquals(jobDefinition.getId(), suspendedJob.getJobDefinitionId());
    assertTrue(suspendedJob.isSuspended());
}
Also used : JobDefinitionQuery(org.camunda.bpm.engine.management.JobDefinitionQuery) HashMap(java.util.HashMap) JobQuery(org.camunda.bpm.engine.runtime.JobQuery) Job(org.camunda.bpm.engine.runtime.Job) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 68 with JobDefinition

use of org.camunda.bpm.engine.management.JobDefinition in project camunda-bpm-platform by camunda.

the class ActivateJobDefinitionTest method testActivationByProcessDefinitionKey_shouldExecuteImmediatelyAndRetainJobs.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn" })
public void testActivationByProcessDefinitionKey_shouldExecuteImmediatelyAndRetainJobs() {
    // given
    // a deployed process definition with asynchronous continuation
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    // a running process instance with a failed job
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("fail", Boolean.TRUE);
    runtimeService.startProcessInstanceByKey("suspensionProcess", params);
    // a job definition (which was created for the asynchronous continuation)
    JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();
    // ...which will be suspended with the corresponding jobs
    managementService.suspendJobDefinitionByProcessDefinitionKey("suspensionProcess", true);
    // when
    // activate the job definition
    managementService.activateJobDefinitionByProcessDefinitionKey(processDefinition.getKey(), false, null);
    // then
    // there exists an active job definition
    JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery();
    assertEquals(0, jobDefinitionQuery.suspended().count());
    assertEquals(1, jobDefinitionQuery.active().count());
    JobDefinition activeJobDefinition = jobDefinitionQuery.active().singleResult();
    assertEquals(jobDefinition.getId(), activeJobDefinition.getId());
    assertFalse(activeJobDefinition.isSuspended());
    // the corresponding job is still suspended
    JobQuery jobQuery = managementService.createJobQuery();
    assertEquals(1, jobQuery.suspended().count());
    assertEquals(0, jobQuery.active().count());
    Job suspendedJob = jobQuery.suspended().singleResult();
    assertEquals(jobDefinition.getId(), suspendedJob.getJobDefinitionId());
    assertTrue(suspendedJob.isSuspended());
}
Also used : JobDefinitionQuery(org.camunda.bpm.engine.management.JobDefinitionQuery) HashMap(java.util.HashMap) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) JobQuery(org.camunda.bpm.engine.runtime.JobQuery) Job(org.camunda.bpm.engine.runtime.Job) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 69 with JobDefinition

use of org.camunda.bpm.engine.management.JobDefinition in project camunda-bpm-platform by camunda.

the class ActivateJobDefinitionTest method testActivationJobDefinitionIncludingJobsUsingBuilder.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn" })
public void testActivationJobDefinitionIncludingJobsUsingBuilder() {
    // given
    // a deployed process definition with asynchronous continuation
    // a running process instance with a failed job
    runtimeService.startProcessInstanceByKey("suspensionProcess", Variables.createVariables().putValue("fail", true));
    // a job definition (which was created for the asynchronous continuation)
    // ...which will be suspended with the corresponding jobs
    managementService.suspendJobDefinitionByProcessDefinitionKey("suspensionProcess", true);
    JobDefinitionQuery query = managementService.createJobDefinitionQuery();
    JobDefinition jobDefinition = query.singleResult();
    JobQuery jobQuery = managementService.createJobQuery();
    assertEquals(0, jobQuery.active().count());
    assertEquals(1, jobQuery.suspended().count());
    // when
    // activate the job definition
    managementService.updateJobDefinitionSuspensionState().byJobDefinitionId(jobDefinition.getId()).includeJobs(true).activate();
    // then
    // there exists a active job definition
    assertEquals(1, jobQuery.active().count());
    assertEquals(0, jobQuery.suspended().count());
}
Also used : JobDefinitionQuery(org.camunda.bpm.engine.management.JobDefinitionQuery) JobQuery(org.camunda.bpm.engine.runtime.JobQuery) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 70 with JobDefinition

use of org.camunda.bpm.engine.management.JobDefinition in project camunda-bpm-platform by camunda.

the class ActivateJobDefinitionTest method testActivationByProcessDefinitionId_shouldRetainJobs.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn" })
public void testActivationByProcessDefinitionId_shouldRetainJobs() {
    // given
    // a deployed process definition with asynchronous continuation
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    // a running process instance with a failed job
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("fail", Boolean.TRUE);
    runtimeService.startProcessInstanceByKey("suspensionProcess", params);
    // a job definition (which was created for the asynchronous continuation)
    JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();
    // ...which will be suspended with the corresponding jobs
    managementService.suspendJobDefinitionByProcessDefinitionKey("suspensionProcess", true);
    // when
    // activate the job definition
    managementService.activateJobDefinitionByProcessDefinitionId(processDefinition.getId());
    // then
    // there exists a active job definition
    JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery();
    assertEquals(0, jobDefinitionQuery.suspended().count());
    assertEquals(1, jobDefinitionQuery.active().count());
    JobDefinition activeJobDefinition = jobDefinitionQuery.active().singleResult();
    assertEquals(jobDefinition.getId(), activeJobDefinition.getId());
    // the corresponding job is still suspended
    JobQuery jobQuery = managementService.createJobQuery();
    assertEquals(0, jobQuery.active().count());
    assertEquals(1, jobQuery.suspended().count());
    Job suspendedJob = jobQuery.suspended().singleResult();
    assertEquals(jobDefinition.getId(), suspendedJob.getJobDefinitionId());
    assertTrue(suspendedJob.isSuspended());
}
Also used : JobDefinitionQuery(org.camunda.bpm.engine.management.JobDefinitionQuery) HashMap(java.util.HashMap) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) JobQuery(org.camunda.bpm.engine.runtime.JobQuery) Job(org.camunda.bpm.engine.runtime.Job) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

JobDefinition (org.camunda.bpm.engine.management.JobDefinition)219 Job (org.camunda.bpm.engine.runtime.Job)135 Deployment (org.camunda.bpm.engine.test.Deployment)112 JobDefinitionQuery (org.camunda.bpm.engine.management.JobDefinitionQuery)86 JobQuery (org.camunda.bpm.engine.runtime.JobQuery)73 HashMap (java.util.HashMap)67 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)64 Test (org.junit.Test)63 Batch (org.camunda.bpm.engine.batch.Batch)28 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)16 Date (java.util.Date)11 InputStream (java.io.InputStream)8 Deployment (org.camunda.bpm.engine.repository.Deployment)8 DeploymentBuilder (org.camunda.bpm.engine.repository.DeploymentBuilder)8 HistoricDecisionInstanceQuery (org.camunda.bpm.engine.history.HistoricDecisionInstanceQuery)6 UserOperationLogEntry (org.camunda.bpm.engine.history.UserOperationLogEntry)4 ScenarioUnderTest (org.camunda.bpm.qa.upgrade.ScenarioUnderTest)4 HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)3 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)3 Response (com.jayway.restassured.response.Response)2