Search in sources :

Example 96 with JobDefinition

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());
    }
}
Also used : Job(org.camunda.bpm.engine.runtime.Job) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Test(org.junit.Test)

Example 97 with JobDefinition

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());
}
Also used : UserOperationLogEntry(org.camunda.bpm.engine.history.UserOperationLogEntry) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Date(java.util.Date) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 98 with JobDefinition

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());
}
Also used : UserOperationLogEntry(org.camunda.bpm.engine.history.UserOperationLogEntry) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Date(java.util.Date) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 99 with JobDefinition

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());
}
Also used : Job(org.camunda.bpm.engine.runtime.Job) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Test(org.junit.Test)

Example 100 with JobDefinition

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);
}
Also used : JobDefinitionQuery(org.camunda.bpm.engine.management.JobDefinitionQuery) InputStream(java.io.InputStream) Deployment(org.camunda.bpm.engine.repository.Deployment) DeploymentBuilder(org.camunda.bpm.engine.repository.DeploymentBuilder) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Test(org.junit.Test)

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