Search in sources :

Example 26 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class DeploymentAwareJobExecutorTest method testIntermediateTimerEvent.

@Deployment(resources = "org/camunda/bpm/engine/test/jobexecutor/processWithTimerCatch.bpmn20.xml")
public void testIntermediateTimerEvent() {
    runtimeService.startProcessInstanceByKey("testProcess");
    Set<String> registeredDeployments = processEngineConfiguration.getRegisteredDeployments();
    Job existingJob = managementService.createJobQuery().singleResult();
    ClockUtil.setCurrentTime(new Date(System.currentTimeMillis() + 61 * 1000));
    List<JobEntity> acquirableJobs = findAcquirableJobs();
    assertEquals(1, acquirableJobs.size());
    assertEquals(existingJob.getId(), acquirableJobs.get(0).getId());
    registeredDeployments.clear();
    acquirableJobs = findAcquirableJobs();
    assertEquals(0, acquirableJobs.size());
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) Job(org.camunda.bpm.engine.runtime.Job) Date(java.util.Date) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 27 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class JobExecutorFollowUpTest method testExecuteExclusiveFollowUpJobInDifferentProcessInstance.

@Test
public void testExecuteExclusiveFollowUpJobInDifferentProcessInstance() {
    testHelper.deploy(CALL_ACTIVITY_PROCESS, ONE_TASK_PROCESS);
    // given
    // a process instance with a single job
    ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceByKey("callActivityProcess");
    jobExecutor.start();
    // and first job acquisition that acquires the job
    acquisitionThread.waitForSync();
    acquisitionThread.makeContinueAndWaitForSync();
    // and job is executed
    acquisitionThread.makeContinueAndWaitForSync();
    // then
    // the called instance has been created
    ProcessInstance calledInstance = engineRule.getRuntimeService().createProcessInstanceQuery().superProcessInstanceId(processInstance.getId()).singleResult();
    Assert.assertNotNull(calledInstance);
    // and there is a transition instance for the service task
    ActivityInstance activityInstance = engineRule.getRuntimeService().getActivityInstance(calledInstance.getId());
    Assert.assertEquals(1, activityInstance.getTransitionInstances("serviceTask").length);
    // but the corresponding job is not locked
    JobEntity followUpJob = (JobEntity) engineRule.getManagementService().createJobQuery().singleResult();
    Assert.assertNotNull(followUpJob);
    Assert.assertNull(followUpJob.getLockOwner());
    Assert.assertNull(followUpJob.getLockExpirationTime());
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test)

Example 28 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class JobEntityTest method testInsertJobWithExceptionMessage.

/**
 * Note: This does not test a message with 4-byte Unicode supplementary
 * characters for two reasons:
 * - MySQL 5.1 does not support 4-byte supplementary characters (support from 5.5.3 onwards)
 * - {@link String#length()} counts these characters twice (since they are represented by two
 * chars), so essentially the cutoff would be half the actual cutoff for such a string
 */
public void testInsertJobWithExceptionMessage() {
    String fittingThreeByteMessage = repeatCharacter("\u9faf", JobEntity.MAX_EXCEPTION_MESSAGE_LENGTH);
    JobEntity threeByteJobEntity = new MessageEntity();
    threeByteJobEntity.setExceptionMessage(fittingThreeByteMessage);
    // should not fail
    insertJob(threeByteJobEntity);
    deleteJob(threeByteJobEntity);
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity)

Example 29 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class DeleteProcessInstancesJobHandler method createJobEntities.

protected void createJobEntities(BatchEntity batch, DeleteProcessInstanceBatchConfiguration configuration, String deploymentId, List<String> processInstancesToHandle, int invocationsPerBatchJob) {
    CommandContext commandContext = Context.getCommandContext();
    ByteArrayManager byteArrayManager = commandContext.getByteArrayManager();
    JobManager jobManager = commandContext.getJobManager();
    int createdJobs = 0;
    while (!processInstancesToHandle.isEmpty()) {
        int lastIdIndex = Math.min(invocationsPerBatchJob, processInstancesToHandle.size());
        // view of process instances for this job
        List<String> idsForJob = processInstancesToHandle.subList(0, lastIdIndex);
        DeleteProcessInstanceBatchConfiguration jobConfiguration = createJobConfiguration(configuration, idsForJob);
        ByteArrayEntity configurationEntity = saveConfiguration(byteArrayManager, jobConfiguration);
        JobEntity job = createBatchJob(batch, configurationEntity);
        job.setDeploymentId(deploymentId);
        jobManager.insertAndHintJobExecutor(job);
        createdJobs++;
        idsForJob.clear();
    }
    // update created jobs for batch
    batch.setJobsCreated(batch.getJobsCreated() + createdJobs);
    // update batch configuration
    batch.setConfigurationBytes(writeConfiguration(configuration));
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) ByteArrayManager(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayManager) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager)

Example 30 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class AbstractBatchJobHandler method createJobs.

@Override
public boolean createJobs(BatchEntity batch) {
    CommandContext commandContext = Context.getCommandContext();
    ByteArrayManager byteArrayManager = commandContext.getByteArrayManager();
    JobManager jobManager = commandContext.getJobManager();
    T configuration = readConfiguration(batch.getConfigurationBytes());
    int batchJobsPerSeed = batch.getBatchJobsPerSeed();
    int invocationsPerBatchJob = batch.getInvocationsPerBatchJob();
    List<String> ids = configuration.getIds();
    int numberOfItemsToProcess = Math.min(invocationsPerBatchJob * batchJobsPerSeed, ids.size());
    // view of process instances to process
    List<String> processIds = ids.subList(0, numberOfItemsToProcess);
    int createdJobs = 0;
    while (!processIds.isEmpty()) {
        int lastIdIndex = Math.min(invocationsPerBatchJob, processIds.size());
        // view of process instances for this job
        List<String> idsForJob = processIds.subList(0, lastIdIndex);
        T jobConfiguration = createJobConfiguration(configuration, idsForJob);
        ByteArrayEntity configurationEntity = saveConfiguration(byteArrayManager, jobConfiguration);
        JobEntity job = createBatchJob(batch, configurationEntity);
        postProcessJob(configuration, job);
        jobManager.insertAndHintJobExecutor(job);
        idsForJob.clear();
        createdJobs++;
    }
    // update created jobs for batch
    batch.setJobsCreated(batch.getJobsCreated() + createdJobs);
    // update batch configuration
    batch.setConfigurationBytes(writeConfiguration(configuration));
    return ids.isEmpty();
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) ByteArrayManager(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayManager) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager)

Aggregations

JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)68 Test (org.junit.Test)26 Date (java.util.Date)18 Job (org.camunda.bpm.engine.runtime.Job)13 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)11 HistoryCleanupJobHandlerConfiguration (org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration)9 Deployment (org.camunda.bpm.engine.test.Deployment)9 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)7 SimpleDateFormat (java.text.SimpleDateFormat)6 List (java.util.List)6 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)6 Page (org.camunda.bpm.engine.impl.Page)5 JobDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity)5 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)4 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)4 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)4 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)4 ArrayList (java.util.ArrayList)3 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)3