org.camunda.bpm.engine.management.JobDefinitionQuery Java Examples

The following examples show how to use org.camunda.bpm.engine.management.JobDefinitionQuery. 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: 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 #2
Source File: MultiTenancyJobDefinitionSuspensionStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void suspendJobDefinitionNoAuthenticatedTenants() {
  // given activated job definitions
  JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
  assertThat(query.active().count(), is(3L));
  assertThat(query.suspended().count(), is(0L));

  engineRule.getIdentityService().setAuthentication("user", null, null);

  engineRule.getManagementService()
    .updateJobDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .suspend();

  engineRule.getIdentityService().clearAuthentication();

  assertThat(query.active().count(), is(2L));
  assertThat(query.suspended().count(), is(1L));
  assertThat(query.suspended().withoutTenantId().count(), is(1L));
}
 
Example #3
Source File: MultiTenancyJobDefinitionSuspensionStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void delayedSuspendJobDefinitionsForAllTenants() {
  // given activated job definitions

  engineRule.getManagementService()
    .updateJobDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .executionDate(tomorrow())
    .suspend();

  JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
  assertThat(query.active().count(), is(3L));
  assertThat(query.suspended().count(), is(0L));

  // when execute the job to suspend the job definitions
  Job job = engineRule.getManagementService().createJobQuery().timers().singleResult();
  assertThat(job, is(notNullValue()));
  assertThat(getDeploymentIds(query.active()), hasItem(job.getDeploymentId()));

  engineRule.getManagementService().executeJob(job.getId());

  assertThat(query.active().count(), is(0L));
  assertThat(query.suspended().count(), is(3L));
}
 
Example #4
Source File: MultiTenancyJobDefinitionSuspensionStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void suspendJobDefinitionWithAuthenticatedTenant() {
  // given activated job definitions
  JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
  assertThat(query.active().count(), is(3L));
  assertThat(query.suspended().count(), is(0L));

  engineRule.getIdentityService().setAuthentication("user", null, Arrays.asList(TENANT_ONE));

  engineRule.getManagementService()
    .updateJobDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .suspend();

  engineRule.getIdentityService().clearAuthentication();

  assertThat(query.active().count(), is(1L));
  assertThat(query.suspended().count(), is(2L));
  assertThat(query.active().tenantIdIn(TENANT_TWO).count(), is(1L));
  assertThat(query.suspended().withoutTenantId().count(), is(1L));
  assertThat(query.suspended().tenantIdIn(TENANT_ONE).count(), is(1L));
}
 
Example #5
Source File: MultiTenancyJobDefinitionSuspensionStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void suspendJobDefinitionForNonTenant() {
  // given activated job definitions
  JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
  assertThat(query.active().count(), is(3L));
  assertThat(query.suspended().count(), is(0L));

  engineRule.getManagementService()
    .updateJobDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .processDefinitionWithoutTenantId()
    .suspend();

  assertThat(query.active().count(), is(2L));
  assertThat(query.suspended().count(), is(1L));
  assertThat(query.suspended().withoutTenantId().count(), is(1L));
}
 
Example #6
Source File: JobDefinitionRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public List<JobDefinitionDto> queryJobDefinitions(JobDefinitionQueryDto queryDto, Integer firstResult, Integer maxResults) {
  queryDto.setObjectMapper(getObjectMapper());
  JobDefinitionQuery query = queryDto.toQuery(getProcessEngine());

  List<JobDefinition> matchingJobDefinitions;
  if (firstResult != null || maxResults != null) {
    matchingJobDefinitions = executePaginatedQuery(query, firstResult, maxResults);
  } else {
    matchingJobDefinitions = query.list();
  }

  List<JobDefinitionDto> jobDefinitionResults = new ArrayList<JobDefinitionDto>();
  for (JobDefinition jobDefinition : matchingJobDefinitions) {
    JobDefinitionDto result = JobDefinitionDto.fromJobDefinition(jobDefinition);
    jobDefinitionResults.add(result);
  }

  return jobDefinitionResults;
}
 
Example #7
Source File: JobDefinitionDeploymentTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testEventBasedGateway() {

  // given
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery().processDefinitionKey("testProcess");

  // then assert
  assertEquals(2, jobDefinitionQuery.count());

  JobDefinition jobDefinition = jobDefinitionQuery.activityIdIn("timer1").singleResult();
  assertNotNull(jobDefinition);
  assertEquals(TimerCatchIntermediateEventJobHandler.TYPE, jobDefinition.getJobType());
  assertEquals("timer1", jobDefinition.getActivityId());
  assertEquals("DURATION: PT5M", jobDefinition.getJobConfiguration());
  assertEquals(processDefinition.getId(), jobDefinition.getProcessDefinitionId());

  jobDefinition = jobDefinitionQuery.activityIdIn("timer2").singleResult();
  assertNotNull(jobDefinition);
  assertEquals(TimerCatchIntermediateEventJobHandler.TYPE, jobDefinition.getJobType());
  assertEquals("timer2", jobDefinition.getActivityId());
  assertEquals("DURATION: PT10M", jobDefinition.getJobConfiguration());
  assertEquals(processDefinition.getId(), jobDefinition.getProcessDefinitionId());
}
 
Example #8
Source File: JobDefinitionQueryDto.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected void applySortBy(JobDefinitionQuery query, String sortBy, Map<String, Object> parameters, ProcessEngine engine) {
  if (sortBy.equals(SORT_BY_JOB_DEFINITION_ID)) {
    query.orderByJobDefinitionId();
  } else if (sortBy.equals(SORT_BY_ACTIVITY_ID)) {
    query.orderByActivityId();
  } else if (sortBy.equals(SORT_BY_PROCESS_DEFINITION_ID)) {
    query.orderByProcessDefinitionId();
  } else if (sortBy.equals(SORT_BY_PROCESS_DEFINITION_KEY)) {
    query.orderByProcessDefinitionKey();
  } else if (sortBy.equals(SORT_BY_JOB_TYPE)) {
    query.orderByJobType();
  } else if (sortBy.equals(SORT_BY_JOB_CONFIGURATION)) {
    query.orderByJobConfiguration();
  } else if (sortBy.equals(SORT_BY_TENANT_ID)) {
    query.orderByTenantId();
  }
}
 
Example #9
Source File: MultiTenancyProcessDefinitionSuspensionStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void suspendProcessDefinitionIncludingJobDefinitionsForNonTenant() {
  // given activated jobs
  JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
  assertThat(query.active().count(), is(3L));
  assertThat(query.suspended().count(), is(0L));

  engineRule.getRepositoryService()
    .updateProcessDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .processDefinitionWithoutTenantId()
    .suspend();

  assertThat(query.active().count(), is(2L));
  assertThat(query.suspended().count(), is(1L));
  assertThat(query.suspended().withoutTenantId().count(), is(1L));
}
 
Example #10
Source File: MultiTenancyProcessDefinitionSuspensionStateTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void activateProcessDefinitionIncludingJobDefinitionsForAllTenants() {
  // given suspended jobs
  engineRule.getRepositoryService()
    .updateProcessDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .suspend();

  JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
  assertThat(query.active().count(), is(0L));
  assertThat(query.suspended().count(), is(3L));

  engineRule.getRepositoryService()
    .updateProcessDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .activate();

  assertThat(query.suspended().count(), is(0L));
  assertThat(query.active().count(), is(3L));
}
 
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_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 #12
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testMultipleSuspensionByProcessDefinitionKey_shouldExecuteImmediatelyAndSuspendJobs() {
  // given
  String key = "suspensionProcess";

  // Deploy three processes and start for each deployment a process instance
  // with a failed job
  int nrOfProcessDefinitions = 3;
  for (int i=0; i<nrOfProcessDefinitions; i++) {
    repositoryService.createDeployment()
      .addClasspathResource("org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn").deploy();
    Map<String, Object> params = new HashMap<>();
    params.put("fail", Boolean.TRUE);
    runtimeService.startProcessInstanceByKey(key, params);
  }

  // a job definition (which was created for the asynchronous continuation)

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

  // then
  // all job definitions are suspended
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery();
  assertEquals(3, jobDefinitionQuery.suspended().count());
  assertEquals(0, jobDefinitionQuery.active().count());

  // and the jobs too
  JobQuery jobQuery = managementService.createJobQuery();
  assertEquals(3, jobQuery.suspended().count());
  assertEquals(0, jobQuery.active().count());

  // Clean DB
  for (org.camunda.bpm.engine.repository.Deployment deployment : repositoryService.createDeploymentQuery().list()) {
    repositoryService.deleteDeployment(deployment.getId(), true);
  }
}
 
Example #13
Source File: JobDefinitionQueryTest.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/JobDefinitionQueryTest.testBase.bpmn"})
public void testQueryByInvalidJobDefinitionId() {
  JobDefinitionQuery query = managementService.createJobDefinitionQuery().jobDefinitionId("invalid");
  verifyQueryResults(query, 0);

  try {
    managementService.createJobDefinitionQuery().jobDefinitionId(null);
    fail("A ProcessEngineExcpetion was expected.");
  } catch (ProcessEngineException e) {}
}
 
Example #14
Source File: JobDefinitionRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private List<JobDefinition> executePaginatedQuery(JobDefinitionQuery query, Integer firstResult, Integer maxResults) {
  if (firstResult == null) {
    firstResult = 0;
  }
  if (maxResults == null) {
    maxResults = Integer.MAX_VALUE;
  }
  return query.listPage(firstResult, maxResults);
}
 
Example #15
Source File: ActivateJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testMultipleSuspensionByProcessDefinitionKeyAndActivateJobsFlag_shouldRetainJobs() {
  // given
  String key = "suspensionProcess";

  // Deploy three processes and start for each deployment a process instance
  // with a failed job
  int nrOfProcessDefinitions = 3;
  for (int i=0; i<nrOfProcessDefinitions; i++) {
    repositoryService.createDeployment()
      .addClasspathResource("org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn").deploy();
    Map<String, Object> params = new HashMap<>();
    params.put("fail", Boolean.TRUE);
    runtimeService.startProcessInstanceByKey(key, params);
  }

  // a job definition (which was created for the asynchronous continuation)
  // ...which will be suspended with the corresponding jobs
  managementService.suspendJobDefinitionByProcessDefinitionKey("suspensionProcess", true);

  // when
  // activate the job definition
  managementService.activateJobDefinitionByProcessDefinitionKey(key, false);

  // then
  // all job definitions are active
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery();
  assertEquals(0, jobDefinitionQuery.suspended().count());
  assertEquals(3, jobDefinitionQuery.active().count());

  // but the jobs are still suspended
  JobQuery jobQuery = managementService.createJobQuery();
  assertEquals(3, jobQuery.suspended().count());
  assertEquals(0, jobQuery.active().count());

  // Clean DB
  for (org.camunda.bpm.engine.repository.Deployment deployment : repositoryService.createDeploymentQuery().list()) {
    repositoryService.deleteDeployment(deployment.getId(), true);
  }
}
 
Example #16
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 #17
Source File: MultiTenancyJobDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByTenantId() {
  JobDefinitionQuery query = managementService
      .createJobDefinitionQuery()
      .tenantIdIn(TENANT_ONE);

  assertThat(query.count(), is(1L));

  query = managementService
      .createJobDefinitionQuery()
      .tenantIdIn(TENANT_TWO);

  assertThat(query.count(), is(1L));
}
 
Example #18
Source File: ActivateJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testMultipleSuspensionByProcessDefinitionKeyAndActivateJobsFlag_shouldSuspendJobs() {
  // given
  String key = "suspensionProcess";

  // Deploy three processes and start for each deployment a process instance
  // with a failed job
  int nrOfProcessDefinitions = 3;
  for (int i=0; i<nrOfProcessDefinitions; i++) {
    repositoryService.createDeployment()
      .addClasspathResource("org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn").deploy();
    Map<String, Object> params = new HashMap<>();
    params.put("fail", Boolean.TRUE);
    runtimeService.startProcessInstanceByKey(key, params);
  }

  // a job definition (which was created for the asynchronous continuation)
  // ...which will be suspended with the corresponding jobs
  managementService.suspendJobDefinitionByProcessDefinitionKey("suspensionProcess", true);

  // when
  // activate the job definition
  managementService.activateJobDefinitionByProcessDefinitionKey(key, true);

  // then
  // all job definitions are active
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery();
  assertEquals(0, jobDefinitionQuery.suspended().count());
  assertEquals(3, jobDefinitionQuery.active().count());

  // and the jobs too
  JobQuery jobQuery = managementService.createJobQuery();
  assertEquals(0, jobQuery.suspended().count());
  assertEquals(3, jobQuery.active().count());

  // Clean DB
  for (org.camunda.bpm.engine.repository.Deployment deployment : repositoryService.createDeploymentQuery().list()) {
    repositoryService.deleteDeployment(deployment.getId(), true);
  }

}
 
Example #19
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 #20
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 testDelayedSuspensionUsingBuilder() {
  // 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();

  // when
  // suspend the job definition in one week
  managementService
    .updateJobDefinitionSuspensionState()
    .byJobDefinitionId(jobDefinition.getId())
    .executionDate(oneWeekLater())
    .suspend();

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

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

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

  // the job definition should be suspended
  assertEquals(0, query.active().count());
  assertEquals(1, query.suspended().count());
}
 
Example #21
Source File: JobDefinitionCreationBothAsyncWithParseListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateBothAsyncJobDefinitionWithParseListener() {
  //given
  String modelFileName = "jobCreationWithinParseListener.bpmn20.xml";
  InputStream in = JobDefinitionCreationWithParseListenerTest.class.getResourceAsStream(modelFileName);
  DeploymentBuilder builder = engineRule.getRepositoryService().createDeployment().addInputStream(modelFileName, in);

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

  //then there exists two job definitions
  JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
  List<JobDefinition> definitions = query.orderByJobConfiguration().asc().list();
  assertEquals(definitions.size(), 2);

  //asyncAfter
  JobDefinition asyncAfterAfter = definitions.get(0);
  assertEquals(asyncAfterAfter.getProcessDefinitionKey(), "oneTaskProcess");
  assertEquals(asyncAfterAfter.getActivityId(), "servicetask1");
  assertEquals(asyncAfterAfter.getJobConfiguration(), MessageJobDeclaration.ASYNC_AFTER);

  //asyncBefore
  JobDefinition asyncAfterBefore = definitions.get(1);
  assertEquals(asyncAfterBefore.getProcessDefinitionKey(), "oneTaskProcess");
  assertEquals(asyncAfterBefore.getActivityId(), "servicetask1");
  assertEquals(asyncAfterBefore.getJobConfiguration(), MessageJobDeclaration.ASYNC_BEFORE);
}
 
Example #22
Source File: ProcessDefinitionSuspensionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources={"org/camunda/bpm/engine/test/api/repository/ProcessDefinitionSuspensionTest.testWithOneAsyncServiceTask.bpmn"})
public void testSuspendByIdAndIncludeInstancesFlag_shouldSuspendJobDefinitionAndJob() {
  // a process definition with a asynchronous continuation, so that there
  // exists a job definition
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
  JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();

  // a running process instance with a failed service task
  Map<String, Object> params = new HashMap<>();
  params.put("fail", Boolean.TRUE);
  runtimeService.startProcessInstanceById(processDefinition.getId(), params);

  // when
  // the process definition will be suspended
  repositoryService.suspendProcessDefinitionById(processDefinition.getId(), true, null);

  // then
  // the job definition should be suspended...
  JobDefinitionQuery jobDefinitionQuery = managementService.createJobDefinitionQuery();

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

  JobDefinition suspendedJobDefinition = jobDefinitionQuery.suspended().singleResult();

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

  // ...and the corresponding job should be suspended too
  JobQuery jobQuery = managementService.createJobQuery();

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

  Job job = jobQuery.suspended().singleResult();

  assertEquals(jobDefinition.getId(), job.getJobDefinitionId());
  assertTrue(job.isSuspended());
}
 
Example #23
Source File: JobDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void verifyQueryResults(JobDefinitionQuery query, int countExpected) {
  assertEquals(countExpected, query.list().size());
  assertEquals(countExpected, query.count());

  if (countExpected == 1) {
    assertNotNull(query.singleResult());
  } else if (countExpected > 1){
    verifySingleResultFails(query);
  } else if (countExpected == 0) {
    assertNull(query.singleResult());
  }
}
 
Example #24
Source File: MultiTenancyJobDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryAuthenticatedTenants() {
  identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE, TENANT_TWO));

  JobDefinitionQuery query = managementService.createJobDefinitionQuery();

  assertThat(query.count(), is(3L));
  assertThat(query.tenantIdIn(TENANT_ONE).count(), is(1L));
  assertThat(query.tenantIdIn(TENANT_TWO).count(), is(1L));
  assertThat(query.withoutTenantId().count(), is(1L));
}
 
Example #25
Source File: MultiTenancyJobDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByNonExistingTenantId() {
  JobDefinitionQuery query = managementService
      .createJobDefinitionQuery()
      .tenantIdIn("nonExisting");

  assertThat(query.count(), is(0L));
}
 
Example #26
Source File: MultiTenancyJobDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryByDefinitionsWithoutTenantIds() {
  JobDefinitionQuery query = managementService
      .createJobDefinitionQuery()
      .withoutTenantId();

  assertThat(query.count(), is(1L));
}
 
Example #27
Source File: JobDefinitionCreationBothAsyncWithParseListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateBothJobDefinitionWithParseListenerAndAsyncBeforeInXml() {
  //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 and asyncAfter is set to true in the parse listener
  Deployment deployment = builder.deploy();
  engineRule.manageDeployment(deployment);

  //then there exists two job definitions
  JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
  List<JobDefinition> definitions = query.orderByJobConfiguration().asc().list();
  assertEquals(definitions.size(), 2);

  //asyncAfter
  JobDefinition asyncAfterAfter = definitions.get(0);
  assertEquals(asyncAfterAfter.getProcessDefinitionKey(), "oneTaskProcess");
  assertEquals(asyncAfterAfter.getActivityId(), "servicetask1");
  assertEquals(asyncAfterAfter.getJobConfiguration(), MessageJobDeclaration.ASYNC_AFTER);

  //asyncBefore
  JobDefinition asyncAfterBefore = definitions.get(1);
  assertEquals(asyncAfterBefore.getProcessDefinitionKey(), "oneTaskProcess");
  assertEquals(asyncAfterBefore.getActivityId(), "servicetask1");
  assertEquals(asyncAfterBefore.getJobConfiguration(), MessageJobDeclaration.ASYNC_BEFORE);
}
 
Example #28
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 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());
}
 
Example #29
Source File: JobDefinitionAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryWithReadPermissionOnProcessDefinition() {
  // given
  createGrantAuthorization(PROCESS_DEFINITION, TIMER_START_PROCESS_KEY, userId, READ);

  // when
  JobDefinitionQuery query = managementService.createJobDefinitionQuery();

  // then
  verifyQueryResults(query, 1);
}
 
Example #30
Source File: MultiTenancyJobDefinitionSuspensionStateTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void delayedActivateJobDefinitionsForTenant() {
  // given suspend job definitions
  engineRule.getManagementService()
    .updateJobDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .suspend();

  engineRule.getManagementService()
    .updateJobDefinitionSuspensionState()
    .byProcessDefinitionKey(PROCESS_DEFINITION_KEY)
    .processDefinitionTenantId(TENANT_ONE)
    .executionDate(tomorrow())
    .activate();

  JobDefinitionQuery query = engineRule.getManagementService().createJobDefinitionQuery();
  assertThat(query.active().count(), is(0L));
  assertThat(query.suspended().count(), is(3L));

  // when execute the job to activate the job definitions
  Job job = engineRule.getManagementService().createJobQuery().timers().singleResult();
  assertThat(job, is(notNullValue()));
  JobDefinition expectedJobDefinition = engineRule.getManagementService().createJobDefinitionQuery()
      .suspended().tenantIdIn(TENANT_ONE).singleResult();
  assertThat(job.getDeploymentId(), is(getDeploymentId(expectedJobDefinition)));

  engineRule.getManagementService().executeJob(job.getId());

  assertThat(query.suspended().count(), is(2L));
  assertThat(query.active().count(), is(1L));
  assertThat(query.active().tenantIdIn(TENANT_ONE).count(), is(1L));
}