use of org.camunda.bpm.engine.management.JobDefinition in project camunda-bpm-platform by camunda.
the class ConcurrentJobExecutorTest method testCompletingSuspensionJobDuringPriorityUpdate.
@Test
public void testCompletingSuspensionJobDuringPriorityUpdate() {
testRule.deploy(SIMPLE_ASYNC_PROCESS);
// given
// two running instances (ie two jobs)
runtimeService.startProcessInstanceByKey("simpleAsyncProcess");
runtimeService.startProcessInstanceByKey("simpleAsyncProcess");
// a job definition
JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();
// when suspending the jobs is attempted
JobSuspensionByJobDefinitionThread suspensionThread = new JobSuspensionByJobDefinitionThread(jobDefinition.getId());
suspensionThread.startAndWaitUntilControlIsReturned();
// and updating the priority is attempted
JobDefinitionPriorityThread priorityUpdateThread = new JobDefinitionPriorityThread(jobDefinition.getId(), 42L, true);
priorityUpdateThread.startAndWaitUntilControlIsReturned();
// and both commands overlap each other
suspensionThread.proceedAndWaitTillDone();
priorityUpdateThread.proceedAndWaitTillDone();
// then both updates have been performed
List<Job> updatedJobs = managementService.createJobQuery().list();
assertEquals(2, updatedJobs.size());
for (Job job : updatedJobs) {
assertEquals(42, job.getPriority());
assertTrue(job.isSuspended());
}
}
use of org.camunda.bpm.engine.management.JobDefinition in project camunda-bpm-platform by camunda.
the class UserOperationLogJobDefinitionTest method testClearOverridingPriority.
@Deployment(resources = { "org/camunda/bpm/engine/test/history/asyncTaskProcess.bpmn20.xml" })
public void testClearOverridingPriority() {
// given a job definition
JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();
// with an overriding priority
ClockUtil.setCurrentTime(new Date(System.currentTimeMillis()));
managementService.setOverridingJobPriorityForJobDefinition(jobDefinition.getId(), 42);
// when I clear that priority
ClockUtil.setCurrentTime(new Date(System.currentTimeMillis() + 10000));
managementService.clearOverridingJobPriorityForJobDefinition(jobDefinition.getId());
// then this is accessible via the op log
UserOperationLogEntry userOperationLogEntry = historyService.createUserOperationLogQuery().orderByTimestamp().desc().listPage(0, 1).get(0);
assertNotNull(userOperationLogEntry);
assertEquals(EntityTypes.JOB_DEFINITION, userOperationLogEntry.getEntityType());
assertEquals(jobDefinition.getId(), userOperationLogEntry.getJobDefinitionId());
assertEquals(UserOperationLogEntry.OPERATION_TYPE_SET_PRIORITY, userOperationLogEntry.getOperationType());
assertEquals("overridingPriority", userOperationLogEntry.getProperty());
assertNull(userOperationLogEntry.getNewValue());
assertEquals("42", userOperationLogEntry.getOrgValue());
assertEquals(USER_ID, userOperationLogEntry.getUserId());
assertEquals(jobDefinition.getProcessDefinitionId(), userOperationLogEntry.getProcessDefinitionId());
assertEquals(jobDefinition.getProcessDefinitionKey(), userOperationLogEntry.getProcessDefinitionKey());
assertEquals(deploymentId, userOperationLogEntry.getDeploymentId());
}
use of org.camunda.bpm.engine.management.JobDefinition in project camunda-bpm-platform by camunda.
the class UserOperationLogJobDefinitionTest method testOverwriteOverridingPriority.
@Deployment(resources = { "org/camunda/bpm/engine/test/history/asyncTaskProcess.bpmn20.xml" })
public void testOverwriteOverridingPriority() {
// given a job definition
JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();
// with an overriding priority
ClockUtil.setCurrentTime(new Date(System.currentTimeMillis()));
managementService.setOverridingJobPriorityForJobDefinition(jobDefinition.getId(), 42);
// when I overwrite that priority
ClockUtil.setCurrentTime(new Date(System.currentTimeMillis() + 10000));
managementService.setOverridingJobPriorityForJobDefinition(jobDefinition.getId(), 43);
// then this is accessible via the op log
UserOperationLogEntry userOperationLogEntry = historyService.createUserOperationLogQuery().orderByTimestamp().desc().listPage(0, 1).get(0);
assertNotNull(userOperationLogEntry);
assertEquals(EntityTypes.JOB_DEFINITION, userOperationLogEntry.getEntityType());
assertEquals(jobDefinition.getId(), userOperationLogEntry.getJobDefinitionId());
assertEquals(UserOperationLogEntry.OPERATION_TYPE_SET_PRIORITY, userOperationLogEntry.getOperationType());
assertEquals("overridingPriority", userOperationLogEntry.getProperty());
assertEquals("43", userOperationLogEntry.getNewValue());
assertEquals("42", userOperationLogEntry.getOrgValue());
}
use of org.camunda.bpm.engine.management.JobDefinition in project camunda-bpm-platform by camunda.
the class JobDefinitionFunctionalTest method testExclusiveJobs.
@Test
public void testExclusiveJobs() {
testRule.deploy(Bpmn.createExecutableProcess("testProcess").startEvent().serviceTask("task1").camundaExpression("${true}").camundaAsyncBefore().serviceTask("task2").camundaExpression("${true}").camundaAsyncBefore().endEvent().done());
JobDefinition jobDefinition = managementService.createJobDefinitionQuery().activityIdIn("task2").singleResult();
// given that the second task is suspended
managementService.suspendJobDefinitionById(jobDefinition.getId());
// if I start a process instance
runtimeService.startProcessInstanceByKey("testProcess");
testRule.waitForJobExecutorToProcessAllJobs(10000);
// then the second task is not executed
assertEquals(1, runtimeService.createProcessInstanceQuery().count());
// there is a suspended job instance
Job job = managementService.createJobQuery().singleResult();
assertEquals(job.getJobDefinitionId(), jobDefinition.getId());
assertTrue(job.isSuspended());
// if I unsuspend the job definition, the job is executed:
managementService.activateJobDefinitionById(jobDefinition.getId(), true);
testRule.waitForJobExecutorToProcessAllJobs(10000);
assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
use of org.camunda.bpm.engine.management.JobDefinition in project camunda-bpm-platform by camunda.
the class JobDefinitionCreationAndDeletionWithParseListenerTest method testDeleteNonExistingAndCreateNewJobDefinitionWithParseListener.
@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);
}
Aggregations