Java Code Examples for org.camunda.bpm.engine.management.JobDefinitionQuery#singleResult()

The following examples show how to use org.camunda.bpm.engine.management.JobDefinitionQuery#singleResult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobDefinitionCreationWithParseListenerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateJobDefinitionWithParseListenerAndAsyncInXml() {
  //given the asyncBefore is set in the xml
  String modelFileName = "jobAsyncBeforeCreationWithinParseListener.bpmn20.xml";
  InputStream in = JobDefinitionCreationWithParseListenerTest.class.getResourceAsStream(modelFileName);
  DeploymentBuilder builder = engineRule.getRepositoryService().createDeployment().addInputStream(modelFileName, in);

  //when the asyncBefore is set in the parse listener
  Deployment deployment = builder.deploy();
  engineRule.manageDeployment(deployment);

  //then there exists only one job definition
  JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
  JobDefinition jobDef = query.singleResult();
  assertNotNull(jobDef);
  assertEquals(jobDef.getProcessDefinitionKey(), "oneTaskProcess");
  assertEquals(jobDef.getActivityId(), "servicetask1");
}
 
Example 2
Source File: JobDefinitionCreationAndDeletionWithParseListenerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteNonExistingAndCreateNewJobDefinitionWithParseListener() {
  //given
  String modelFileName = "jobCreationWithinParseListener.bpmn20.xml";
  InputStream in = JobDefinitionCreationWithParseListenerTest.class.getResourceAsStream(modelFileName);
  DeploymentBuilder builder = engineRule.getRepositoryService().createDeployment().addInputStream(modelFileName, in);

  //when the asyncBefore is set to false and the asyncAfter to true in the parse listener
  Deployment deployment = builder.deploy();
  engineRule.manageDeployment(deployment);

  //then there exists one job definition
  JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
  JobDefinition jobDef = query.singleResult();
  assertNotNull(jobDef);
  assertEquals(jobDef.getProcessDefinitionKey(), "oneTaskProcess");
  assertEquals(jobDef.getActivityId(), "servicetask1");
  assertEquals(jobDef.getJobConfiguration(), MessageJobDeclaration.ASYNC_AFTER);
}
 
Example 3
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionByProcessDefinitionKeyUsingBuilder() {
  // 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)
  JobDefinitionQuery query = managementService.createJobDefinitionQuery();
  JobDefinition jobDefinition = query.singleResult();
  assertFalse(jobDefinition.isSuspended());

  // when
  // suspend the job definition
  managementService
    .updateJobDefinitionSuspensionState()
    .byProcessDefinitionKey("suspensionProcess")
    .suspend();

  // then
  // there exists a suspended job definition
  assertEquals(1, query.suspended().count());
}
 
Example 4
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionByIdUsingBuilder() {
  // 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)
  JobDefinitionQuery query = managementService.createJobDefinitionQuery();
  JobDefinition jobDefinition = query.singleResult();
  assertFalse(jobDefinition.isSuspended());

  // when
  // suspend the job definition
  managementService
    .updateJobDefinitionSuspensionState()
    .byJobDefinitionId(jobDefinition.getId())
    .suspend();

  // then
  // there exists a suspended job definition
  assertEquals(1, query.suspended().count());
}
 
Example 5
Source File: JobDefinitionCreationAndDeletionWithParseListenerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteJobDefinitionWithParseListenerAndAsyncBothInXml() {
  //given the asyncBefore AND asyncAfter is set in the xml
  String modelFileName = "jobAsyncBothCreationWithinParseListener.bpmn20.xml";
  InputStream in = JobDefinitionCreationWithParseListenerTest.class.getResourceAsStream(modelFileName);
  DeploymentBuilder builder = engineRule.getRepositoryService().createDeployment().addInputStream(modelFileName, in);

  //when the asyncBefore is set to false and the asyncAfter to true in the parse listener
  Deployment deployment = builder.deploy();
  engineRule.manageDeployment(deployment);

  //then there exists one job definition
  JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
  JobDefinition jobDef = query.singleResult();
  assertNotNull(jobDef);
  assertEquals(jobDef.getProcessDefinitionKey(), "oneTaskProcess");
  assertEquals(jobDef.getActivityId(), "servicetask1");
  assertEquals(jobDef.getJobConfiguration(), MessageJobDeclaration.ASYNC_AFTER);
}
 
Example 6
Source File: ActivateJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testActivationByIdUsingBuilder() {
  // 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();

  assertEquals(0, query.active().count());
  assertEquals(1, query.suspended().count());

  // when
  // activate the job definition
  managementService
    .updateJobDefinitionSuspensionState()
    .byJobDefinitionId(jobDefinition.getId())
    .activate();

  // then
  // there exists a active job definition
  assertEquals(1, query.active().count());
  assertEquals(0, query.suspended().count());
}
 
Example 7
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionByIdAndSuspendJobsFlag_shouldSuspendJobs() {
  // given
  // a deployed process definition with asynchronous continuation

  // a running process instance with a failed job
  Map<String, Object> params = new HashMap<>();
  params.put("fail", Boolean.TRUE);
  runtimeService.startProcessInstanceByKey("suspensionProcess", params);

  // a job definition (which was created for the asynchronous continuation)
  JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();

  // when
  // suspend the job definition
  managementService.suspendJobDefinitionById(jobDefinition.getId(), true);

  // then
  // there exists a suspended job definition...
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery().suspended();

  assertEquals(1, jobDefinitionQuery.count());

  JobDefinition suspendedJobDefinition = jobDefinitionQuery.singleResult();

  assertEquals(jobDefinition.getId(), suspendedJobDefinition.getId());
  assertTrue(suspendedJobDefinition.isSuspended());

  // ...and a suspended job of the provided job definition
  JobQuery jobQuery = managementService.createJobQuery().suspended();

  assertEquals(1, jobQuery.count());

  Job suspendedJob = jobQuery.singleResult();
  assertEquals(jobDefinition.getId(), suspendedJob.getJobDefinitionId());
  assertTrue(suspendedJob.isSuspended());

}
 
Example 8
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionById_shouldExecuteImmediatelyAndSuspendJobs() {
  // given
  // a deployed process definition with asynchronous continuation

  // a running process instance with a failed job
  Map<String, Object> params = new HashMap<>();
  params.put("fail", Boolean.TRUE);
  runtimeService.startProcessInstanceByKey("suspensionProcess", params);

  // a job definition (which was created for the asynchronous continuation)
  JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();

  // when
  // suspend the job definition
  managementService.suspendJobDefinitionById(jobDefinition.getId(), true, null);

  // then
  // there exists a suspended job definition...
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery().suspended();

  assertEquals(1, jobDefinitionQuery.count());

  JobDefinition suspendedJobDefinition = jobDefinitionQuery.singleResult();

  assertEquals(jobDefinition.getId(), suspendedJobDefinition.getId());
  assertTrue(suspendedJobDefinition.isSuspended());

  // ...and a suspended job of the provided job definition
  JobQuery jobQuery = managementService.createJobQuery().suspended();

  assertEquals(1, jobQuery.count());

  Job suspendedJob = jobQuery.singleResult();
  assertEquals(jobDefinition.getId(), suspendedJob.getJobDefinitionId());
  assertTrue(suspendedJob.isSuspended());

}
 
Example 9
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionByProcessDefinitionIdAndSuspendJobsFlag_shouldSuspendJobs() {
  // 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<>();
  params.put("fail", Boolean.TRUE);
  runtimeService.startProcessInstanceByKey("suspensionProcess", params);

  // a job definition (which was created for the asynchronous continuation)
  JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();

  // when
  // suspend the job definition
  managementService.suspendJobDefinitionByProcessDefinitionId(processDefinition.getId(), true);

  // then
  // there exists a suspended job definition...
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery().suspended();

  assertEquals(1, jobDefinitionQuery.count());

  JobDefinition suspendedJobDefinition = jobDefinitionQuery.singleResult();

  assertEquals(jobDefinition.getId(), suspendedJobDefinition.getId());
  assertTrue(suspendedJobDefinition.isSuspended());

  // ...and a suspended job of the provided job definition
  JobQuery jobQuery = managementService.createJobQuery().suspended();

  assertEquals(1, jobQuery.count());

  Job suspendedJob = jobQuery.singleResult();
  assertEquals(jobDefinition.getId(), suspendedJob.getJobDefinitionId());
  assertTrue(suspendedJob.isSuspended());

}
 
Example 10
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionByProcessDefinitionId_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<>();
  params.put("fail", Boolean.TRUE);
  runtimeService.startProcessInstanceByKey("suspensionProcess", params);

  // a job definition (which was created for the asynchronous continuation)
  JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();

  // when
  // suspend the job definition
  managementService.suspendJobDefinitionByProcessDefinitionId(processDefinition.getId(), false, null);

  // then
  // there exists a suspended job definition
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery().suspended();

  assertEquals(1, jobDefinitionQuery.count());

  JobDefinition suspendedJobDefinition = jobDefinitionQuery.singleResult();

  assertEquals(jobDefinition.getId(), suspendedJobDefinition.getId());
  assertTrue(suspendedJobDefinition.isSuspended());

  // the corresponding job is still active
  JobQuery jobQuery = managementService.createJobQuery();

  assertEquals(0, jobQuery.suspended().count());
  assertEquals(1, jobQuery.active().count());

  Job activeJob = jobQuery.active().singleResult();
  assertEquals(jobDefinition.getId(), activeJob.getJobDefinitionId());

  assertFalse(activeJob.isSuspended());
}
 
Example 11
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionByProcessDefinitionId_shouldExecuteImmediatelyAndSuspendJobs() {
  // 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<>();
  params.put("fail", Boolean.TRUE);
  runtimeService.startProcessInstanceByKey("suspensionProcess", params);

  // a job definition (which was created for the asynchronous continuation)
  JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();

  // when
  // suspend the job definition
  managementService.suspendJobDefinitionByProcessDefinitionId(processDefinition.getId(), true, null);

  // then
  // there exists a suspended job definition...
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery().suspended();

  assertEquals(1, jobDefinitionQuery.count());

  JobDefinition suspendedJobDefinition = jobDefinitionQuery.singleResult();

  assertEquals(jobDefinition.getId(), suspendedJobDefinition.getId());
  assertTrue(suspendedJobDefinition.isSuspended());

  // ...and a suspended job of the provided job definition
  JobQuery jobQuery = managementService.createJobQuery().suspended();

  assertEquals(1, jobQuery.count());

  Job suspendedJob = jobQuery.singleResult();
  assertEquals(jobDefinition.getId(), suspendedJob.getJobDefinitionId());
  assertTrue(suspendedJob.isSuspended());

}
 
Example 12
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionByProcessDefinitionIdUsingBuilder() {
  // 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)
  JobDefinitionQuery query = managementService.createJobDefinitionQuery();
  JobDefinition jobDefinition = query.singleResult();
  assertFalse(jobDefinition.isSuspended());

  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();

  // when
  // suspend the job definition
  managementService
    .updateJobDefinitionSuspensionState()
    .byProcessDefinitionId(processDefinition.getId())
    .suspend();

  // then
  // there exists a suspended job definition
  assertEquals(1, query.suspended().count());
}
 
Example 13
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionByProcessDefinitionKey_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<>();
  params.put("fail", Boolean.TRUE);
  runtimeService.startProcessInstanceByKey("suspensionProcess", params);

  // a job definition (which was created for the asynchronous continuation)
  JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();

  // when
  // suspend the job definition
  managementService.suspendJobDefinitionByProcessDefinitionKey(processDefinition.getKey(), false, null);

  // then
  // there exists a suspended job definition
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery().suspended();

  assertEquals(1, jobDefinitionQuery.count());

  JobDefinition suspendedJobDefinition = jobDefinitionQuery.singleResult();

  assertEquals(jobDefinition.getId(), suspendedJobDefinition.getId());
  assertTrue(suspendedJobDefinition.isSuspended());

  // the corresponding job is still active
  JobQuery jobQuery = managementService.createJobQuery();

  assertEquals(0, jobQuery.suspended().count());
  assertEquals(1, jobQuery.active().count());

  Job activeJob = jobQuery.active().singleResult();

  assertEquals(jobDefinition.getId(), activeJob.getJobDefinitionId());
  assertFalse(activeJob.isSuspended());
}
 
Example 14
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionByProcessDefinitionKey_shouldExecuteImmediatelyAndSuspendJobs() {
  // 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<>();
  params.put("fail", Boolean.TRUE);
  runtimeService.startProcessInstanceByKey("suspensionProcess", params);

  // a job definition (which was created for the asynchronous continuation)
  JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();

  // when
  // suspend the job definition
  managementService.suspendJobDefinitionByProcessDefinitionKey(processDefinition.getKey(), true, null);

  // then
  // there exists a suspended job definition...
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery().suspended();

  assertEquals(1, jobDefinitionQuery.count());

  JobDefinition suspendedJobDefinition = jobDefinitionQuery.singleResult();

  assertEquals(jobDefinition.getId(), suspendedJobDefinition.getId());
  assertTrue(suspendedJobDefinition.isSuspended());

  // ...and a suspended job of the provided job definition
  JobQuery jobQuery = managementService.createJobQuery().suspended();

  assertEquals(1, jobQuery.count());

  Job suspendedJob = jobQuery.singleResult();
  assertEquals(jobDefinition.getId(), suspendedJob.getJobDefinitionId());
  assertTrue(suspendedJob.isSuspended());
}
 
Example 15
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionByProcessDefinitionKey_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<>();
  params.put("fail", Boolean.TRUE);
  runtimeService.startProcessInstanceByKey("suspensionProcess", params);

  // a job definition (which was created for the asynchronous continuation)
  JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();

  // when
  // suspend the job definition
  managementService.suspendJobDefinitionByProcessDefinitionKey(processDefinition.getKey());

  // then
  // there exists a suspended job definition
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery().suspended();

  assertEquals(1, jobDefinitionQuery.count());

  JobDefinition suspendedJobDefinition = jobDefinitionQuery.singleResult();

  assertEquals(jobDefinition.getId(), suspendedJobDefinition.getId());

  // there does not exist any active job definition
  jobDefinitionQuery = managementService.createJobDefinitionQuery().active();
  assertTrue(jobDefinitionQuery.list().isEmpty());

  // the corresponding job is still active
  JobQuery jobQuery = managementService.createJobQuery();

  assertEquals(0, jobQuery.suspended().count());
  assertEquals(1, jobQuery.active().count());

  Job activeJob = jobQuery.active().singleResult();

  assertEquals(jobDefinition.getId(), activeJob.getJobDefinitionId());
  assertFalse(activeJob.isSuspended());
}
 
Example 16
Source File: ActivateJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testDelayedActivationUsingBuilder() {
  // 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();

  // when
  // activate the job definition
  managementService
    .updateJobDefinitionSuspensionState()
    .byJobDefinitionId(jobDefinition.getId())
    .executionDate(oneWeekLater())
    .activate();

  // then
  // the job definition is still suspended
  assertEquals(0, query.active().count());
  assertEquals(1, query.suspended().count());

  // there exists a job for the delayed activation execution
  Job delayedActivationJob = managementService.createJobQuery().timers().active().singleResult();
  assertNotNull(delayedActivationJob);
  String expectedDeploymentId = repositoryService.createProcessDefinitionQuery()
      .processDefinitionId(jobDefinition.getProcessDefinitionId()).singleResult().getDeploymentId();
  assertThat(delayedActivationJob.getDeploymentId(), is(expectedDeploymentId));

  // execute job
  managementService.executeJob(delayedActivationJob.getId());

  // the job definition should be suspended
  assertEquals(1, query.active().count());
  assertEquals(0, query.suspended().count());
}
 
Example 17
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionById_shouldRetainJobs() {
  // given
  // a deployed process definition with asynchronous continuation

  // a running process instance with a failed job
  Map<String, Object> params = new HashMap<>();
  params.put("fail", Boolean.TRUE);
  runtimeService.startProcessInstanceByKey("suspensionProcess", params);

  // a job definition (which was created for the asynchronous continuation)
  JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();

  // when
  // suspend the job definition
  managementService.suspendJobDefinitionById(jobDefinition.getId());

  // then
  // there exists a suspended job definition
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery().suspended();

  assertEquals(1, jobDefinitionQuery.count());

  JobDefinition suspendedJobDefinition = jobDefinitionQuery.singleResult();

  assertEquals(jobDefinition.getId(), suspendedJobDefinition.getId());

  // there does not exist any active job definition
  jobDefinitionQuery = managementService.createJobDefinitionQuery().active();
  assertTrue(jobDefinitionQuery.list().isEmpty());

  // the corresponding job is still active
  JobQuery jobQuery = managementService.createJobQuery().active();

  assertEquals(1, jobQuery.count());

  Job activeJob = jobQuery.singleResult();
  assertEquals(jobDefinition.getId(), activeJob.getJobDefinitionId());

  assertFalse(activeJob.isSuspended());

  jobQuery = managementService.createJobQuery().suspended();
  assertEquals(0, jobQuery.count());
}
 
Example 18
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionByProcessDefinitionIdAndSuspendJobsFlag_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<>();
  params.put("fail", Boolean.TRUE);
  runtimeService.startProcessInstanceByKey("suspensionProcess", params);

  // a job definition (which was created for the asynchronous continuation)
  JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();

  // when
  // suspend the job definition
  managementService.suspendJobDefinitionByProcessDefinitionId(processDefinition.getId(), false);

  // then
  // there exists a suspended job definition
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery().suspended();

  assertEquals(1, jobDefinitionQuery.count());

  JobDefinition suspendedJobDefinition = jobDefinitionQuery.singleResult();

  assertEquals(jobDefinition.getId(), suspendedJobDefinition.getId());
  assertTrue(suspendedJobDefinition.isSuspended());

  // the corresponding job is still active
  JobQuery jobQuery = managementService.createJobQuery().active();

  assertEquals(1, jobQuery.count());

  Job activeJob = jobQuery.singleResult();
  assertEquals(jobDefinition.getId(), activeJob.getJobDefinitionId());

  assertFalse(activeJob.isSuspended());

  jobQuery = managementService.createJobQuery().suspended();
  assertEquals(0, jobQuery.count());

}
 
Example 19
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionById_shouldExecuteImmediatelyAndRetainJobs() {
  // given
  // a deployed process definition with asynchronous continuation

  // a running process instance with a failed job
  Map<String, Object> params = new HashMap<>();
  params.put("fail", Boolean.TRUE);
  runtimeService.startProcessInstanceByKey("suspensionProcess", params);

  // a job definition (which was created for the asynchronous continuation)
  JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();

  // when
  // suspend the job definition
  managementService.suspendJobDefinitionById(jobDefinition.getId(), false, null);

  // then
  // there exists a suspended job definition
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery().suspended();

  assertEquals(1, jobDefinitionQuery.count());

  JobDefinition suspendedJobDefinition = jobDefinitionQuery.singleResult();

  assertEquals(jobDefinition.getId(), suspendedJobDefinition.getId());
  assertTrue(suspendedJobDefinition.isSuspended());

  // the corresponding job is still active
  JobQuery jobQuery = managementService.createJobQuery().active();

  assertEquals(1, jobQuery.count());

  Job activeJob = jobQuery.singleResult();
  assertEquals(jobDefinition.getId(), activeJob.getJobDefinitionId());

  assertFalse(activeJob.isSuspended());

  jobQuery = managementService.createJobQuery().suspended();
  assertEquals(0, jobQuery.count());

}
 
Example 20
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"})
public void testSuspensionByIdAndSuspendJobsFlag_shouldRetainJobs() {
  // given
  // a deployed process definition with asynchronous continuation

  // a running process instance with a failed job
  Map<String, Object> params = new HashMap<>();
  params.put("fail", Boolean.TRUE);
  runtimeService.startProcessInstanceByKey("suspensionProcess", params);

  // a job definition (which was created for the asynchronous continuation)
  JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();

  // when
  // suspend the job definition
  managementService.suspendJobDefinitionById(jobDefinition.getId(), false);

  // then
  // there exists a suspended job definition
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery().suspended();

  assertEquals(1, jobDefinitionQuery.count());

  JobDefinition suspendedJobDefinition = jobDefinitionQuery.singleResult();

  assertEquals(jobDefinition.getId(), suspendedJobDefinition.getId());
  assertTrue(suspendedJobDefinition.isSuspended());

  // the corresponding job is still active
  JobQuery jobQuery = managementService.createJobQuery().active();

  assertEquals(1, jobQuery.count());

  Job activeJob = jobQuery.singleResult();
  assertEquals(jobDefinition.getId(), activeJob.getJobDefinitionId());

  assertFalse(activeJob.isSuspended());

  jobQuery = managementService.createJobQuery().suspended();
  assertEquals(0, jobQuery.count());

}