org.activiti.engine.runtime.Job Java Examples

The following examples show how to use org.activiti.engine.runtime.Job. 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: BoundaryTimerNonInterruptingEventTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {"org/activiti5/engine/test/bpmn/event/timer/BoundaryTimerNonInterruptingEventTest.testTimerOnConcurrentTasks.bpmn20.xml"})
public void testTimerOnConcurrentTasks2() {
  String procId = runtimeService.startProcessInstanceByKey("nonInterruptingOnConcurrentTasks").getId();
  assertEquals(2, taskService.createTaskQuery().count());
  
  Job timer = managementService.createTimerJobQuery().singleResult();
  managementService.moveTimerToExecutableJob(timer.getId());
  managementService.executeJob(timer.getId());
  assertEquals(3, taskService.createTaskQuery().count());
  
  // Complete 2 tasks that will trigger the join
  Task task = taskService.createTaskQuery().taskDefinitionKey("firstTask").singleResult();
  taskService.complete(task.getId());
  task = taskService.createTaskQuery().taskDefinitionKey("secondTask").singleResult();
  taskService.complete(task.getId());
  assertEquals(1, taskService.createTaskQuery().count());
  
  // Finally, complete the task that was created due to the timer 
  task = taskService.createTaskQuery().taskDefinitionKey("timerFiredTask").singleResult();
  taskService.complete(task.getId());
  
  assertProcessEnded(procId);
}
 
Example #2
Source File: TimerCustomCalendarTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testCycleTimer() {
  List<Job> jobs = this.managementService.createTimerJobQuery().list();

  assertThat("One job is scheduled", jobs.size(), is(1));
  assertThat("Job must be scheduled by custom business calendar to Date(0)", jobs.get(0).getDuedate(), is(new Date(0)));

  managementService.moveTimerToExecutableJob(jobs.get(0).getId());
  managementService.executeJob(jobs.get(0).getId());

  jobs = this.managementService.createTimerJobQuery().list();

  assertThat("One job is scheduled (repetition is 2x)", jobs.size(), is(1));
  assertThat("Job must be scheduled by custom business calendar to Date(0)", jobs.get(0).getDuedate(), is(new Date(0)));

  managementService.moveTimerToExecutableJob(jobs.get(0).getId());
  managementService.executeJob(jobs.get(0).getId());

  jobs = this.managementService.createTimerJobQuery().list();
  assertThat("There must be no job.", jobs.isEmpty());
}
 
Example #3
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testParallelSubProcessWithTimer() {
  String procId = runtimeService.startProcessInstanceByKey("miParallelSubprocessWithTimer").getId();
  List<Task> tasks = taskService.createTaskQuery().list();
  assertEquals(6, tasks.size());

  // Complete two tasks
  taskService.complete(tasks.get(0).getId());
  taskService.complete(tasks.get(1).getId());

  // Fire timer
  Job timer = managementService.createTimerJobQuery().singleResult();
  managementService.moveTimerToExecutableJob(timer.getId());
  managementService.executeJob(timer.getId());

  Task taskAfterTimer = taskService.createTaskQuery().singleResult();
  assertEquals("taskAfterTimer", taskAfterTimer.getTaskDefinitionKey());
  taskService.complete(taskAfterTimer.getId());

  assertProcessEnded(procId);
}
 
Example #4
Source File: JobExceptionStacktraceResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get the exception stacktrace for a deadletter job", tags = {"Jobs"})
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the requested job was not found and the stacktrace has been returned. The response contains the raw stacktrace and always has a Content-type of text/plain."),
    @ApiResponse(code = 404, message = "Indicates the requested job was not found or the job doesn’t have an exception stacktrace. Status-description contains additional information about the error.")
})
@RequestMapping(value = "/management/deadletter-jobs/{jobId}/exception-stacktrace", method = RequestMethod.GET)
public String getDeadLetterJobStacktrace(@ApiParam(name = "jobId") @PathVariable String jobId, HttpServletResponse response) {
  Job job = managementService.createDeadLetterJobQuery().jobId(jobId).singleResult();
  if (job == null) {
    throw new ActivitiObjectNotFoundException("Could not find a job with id '" + jobId + "'.", Job.class);
  }

  String stackTrace = managementService.getDeadLetterJobExceptionStacktrace(job.getId());

  if (stackTrace == null) {
    throw new ActivitiObjectNotFoundException("Suspended job with id '" + job.getId() + "' doesn't have an exception stacktrace.", String.class);
  }

  response.setContentType("text/plain");
  return stackTrace;
}
 
Example #5
Source File: BoundaryTimerNonInterruptingEventTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testTimerOnConcurrentTasks() {
  String procId = runtimeService.startProcessInstanceByKey("nonInterruptingOnConcurrentTasks").getId();
  assertEquals(2, taskService.createTaskQuery().count());
  
  Job timer = managementService.createTimerJobQuery().singleResult();
  managementService.moveTimerToExecutableJob(timer.getId());
  managementService.executeJob(timer.getId());
  assertEquals(3, taskService.createTaskQuery().count());
  
  // Complete task that was reached by non interrupting timer 
  Task task = taskService.createTaskQuery().taskDefinitionKey("timerFiredTask").singleResult();
  taskService.complete(task.getId());
  assertEquals(2, taskService.createTaskQuery().count());
  
  // Complete other tasks
  for (Task t : taskService.createTaskQuery().list()) {
    taskService.complete(t.getId());
  }
  assertProcessEnded(procId);
}
 
Example #6
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti5/engine/test/bpmn/multiinstance/MultiInstanceTest.testSequentialCallActivityWithTimer.bpmn20.xml",
    "org/activiti5/engine/test/bpmn/multiinstance/MultiInstanceTest.externalSubProcess.bpmn20.xml" })
public void testSequentialCallActivityWithTimer() {
  String procId = runtimeService.startProcessInstanceByKey("miSequentialCallActivityWithTimer").getId();

  // Complete first subprocess
  List<Task> tasks = taskService.createTaskQuery().orderByTaskName().asc().list();
  assertEquals(2, tasks.size());
  assertEquals("task one", tasks.get(0).getName());
  assertEquals("task two", tasks.get(1).getName());
  taskService.complete(tasks.get(0).getId());
  taskService.complete(tasks.get(1).getId());
  
  // Fire timer
  Job timer = managementService.createTimerJobQuery().singleResult();
  managementService.moveTimerToExecutableJob(timer.getId());
  managementService.executeJob(timer.getId());
  
  Task taskAfterTimer = taskService.createTaskQuery().singleResult();
  assertEquals("taskAfterTimer", taskAfterTimer.getTaskDefinitionKey());
  taskService.complete(taskAfterTimer.getId());
  
  assertProcessEnded(procId);
}
 
Example #7
Source File: ProcessInstanceSuspensionTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={"org/activiti5/engine/test/db/oneJobProcess.bpmn20.xml"})
public void testJobsNotVisisbleToAcquisitionIfInstanceSuspended() {
  
  ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().singleResult();    
  ProcessInstance pi = runtimeService.startProcessInstanceByKey(pd.getKey());
  
  // now there is one job:
  Job job = managementService.createTimerJobQuery().singleResult();
  assertNotNull(job);
  
  makeSureJobDue(job);
  
  // suspend the process instance:
  runtimeService.suspendProcessInstanceById(pi.getId());
  
  job = managementService.createTimerJobQuery().singleResult();
  assertNull(job);
  
  assertEquals(1, managementService.createSuspendedJobQuery().processInstanceId(pi.getId()).count());
}
 
Example #8
Source File: DeleteReasonTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testInterruptingBoundaryEvent() {
  ProcessInstance  processInstance = runtimeService.startProcessInstanceByKey("deleteReasonProcess");
  Task task = taskService.createTaskQuery().singleResult();
  assertEquals("A", task.getName());
  taskService.complete(task.getId());
  
  // Timer firing should delete all tasks
  Job timerJob = managementService.createTimerJobQuery().singleResult();
  managementService.moveTimerToExecutableJob(timerJob.getId());
  managementService.executeJob(timerJob.getId());
  
  assertHistoricTasksDeleteReason(processInstance, null, "A");
  assertHistoricTasksDeleteReason(processInstance, DeleteReason.BOUNDARY_EVENT_INTERRUPTING, "B", "C", "D");
  assertHistoricActivitiesDeleteReason(processInstance, null, "A");
  assertHistoricActivitiesDeleteReason(processInstance, DeleteReason.BOUNDARY_EVENT_INTERRUPTING, "B", "C", "D", "theSubprocess");
}
 
Example #9
Source File: ManagementServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/mgmt/ManagementServiceTest.testGetJobExceptionStacktrace.bpmn20.xml" })
public void testSetJobRetries() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exceptionInJobExecution");

  // The execution is waiting in the first usertask. This contains a boundary timer event.
  Job timerJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
  
  Date duedate = timerJob.getDuedate();

  assertNotNull("No job found for process instance", timerJob);
  assertEquals(processEngineConfiguration.getAsyncExecutorNumberOfRetries(), timerJob.getRetries());

  managementService.setTimerJobRetries(timerJob.getId(), 5);

  timerJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
  assertEquals(5, timerJob.getRetries());
  assertEquals(duedate, timerJob.getDuedate());
}
 
Example #10
Source File: JobExceptionStacktraceResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get the exception stacktrace for a job", tags = {"Jobs"})
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the requested job was not found and the stacktrace has been returned. The response contains the raw stacktrace and always has a Content-type of text/plain."),
    @ApiResponse(code = 404, message = "Indicates the requested job was not found or the job doesn’t have an exception stacktrace. Status-description contains additional information about the error.")
})
@RequestMapping(value = "/management/jobs/{jobId}/exception-stacktrace", method = RequestMethod.GET)
public String getJobStacktrace(@ApiParam(name = "jobId", value="Id of the job to get the stacktrace for.") @PathVariable String jobId, HttpServletResponse response) {
  Job job = managementService.createJobQuery().jobId(jobId).singleResult();
  if (job == null) {
    throw new ActivitiObjectNotFoundException("Could not find a job with id '" + jobId + "'.", Job.class);
  }

  String stackTrace = managementService.getJobExceptionStacktrace(job.getId());

  if (stackTrace == null) {
    throw new ActivitiObjectNotFoundException("Job with id '" + job.getId() + "' doesn't have an exception stacktrace.", String.class);
  }

  response.setContentType("text/plain");
  return stackTrace;
}
 
Example #11
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.sequentialUserTasks.bpmn20.xml" })
public void testSequentialUserTasksWithTimer() {
  String procId = runtimeService.startProcessInstanceByKey("miSequentialUserTasks", CollectionUtil.singletonMap(NR_OF_LOOPS_KEY, 3)).getId();

  // Complete 1 tasks
  taskService.complete(taskService.createTaskQuery().singleResult().getId());

  // Fire timer
  Job timer = managementService.createTimerJobQuery().singleResult();
  managementService.moveTimerToExecutableJob(timer.getId());
  managementService.executeJob(timer.getId());

  Task taskAfterTimer = taskService.createTaskQuery().singleResult();
  assertEquals("taskAfterTimer", taskAfterTimer.getTaskDefinitionKey());
  taskService.complete(taskAfterTimer.getId());
  assertProcessEnded(procId);
}
 
Example #12
Source File: ProcessInstanceQueryAndWithExceptionTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
private ProcessInstance startProcessInstanceWithFailingJob(String processInstanceByKey) {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processInstanceByKey);
  
  List<Job> jobList = managementService.createJobQuery()
    .processInstanceId(processInstance.getId())
    .list();

  for(Job job : jobList){
      try {
        managementService.executeJob(job.getId());
        fail("RuntimeException");
      } catch(RuntimeException re) {
    }
  }
  return processInstance;
}
 
Example #13
Source File: ActivityEventsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = "org/activiti5/engine/test/api/event/JobEventsTest.testJobEntityEvents.bpmn20.xml")
public void testActivityTimeOutEvent(){
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testJobEvents");
  Job theJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
  assertNotNull(theJob);

  // Force timer to fire
  Calendar tomorrow = Calendar.getInstance();
  tomorrow.add(Calendar.DAY_OF_YEAR, 1);
  processEngineConfiguration.getClock().setCurrentTime(tomorrow.getTime());
  waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(2000, 100);

  // Check timeout has been dispatched
  assertEquals(1, listener.getEventsReceived().size());
  ActivitiEvent activitiEvent = listener.getEventsReceived().get(0);
  assertEquals("ACTIVITY_CANCELLED event expected", ActivitiEventType.ACTIVITY_CANCELLED, activitiEvent.getType());
  ActivitiActivityCancelledEvent cancelledEvent = (ActivitiActivityCancelledEvent) activitiEvent;
  assertTrue("TIMER is the cause of the cancellation", cancelledEvent.getCause() instanceof JobEntity);
}
 
Example #14
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testParallelUserTasksWithTimer() {
  String procId = runtimeService.startProcessInstanceByKey("miParallelUserTasksWithTimer").getId();

  List<Task> tasks = taskService.createTaskQuery().list();
  taskService.complete(tasks.get(0).getId());

  // Fire timer
  Job timer = managementService.createTimerJobQuery().singleResult();
  managementService.moveTimerToExecutableJob(timer.getId());
  managementService.executeJob(timer.getId());

  Task taskAfterTimer = taskService.createTaskQuery().singleResult();
  assertEquals("taskAfterTimer", taskAfterTimer.getTaskDefinitionKey());
  taskService.complete(taskAfterTimer.getId());
  assertProcessEnded(procId);
}
 
Example #15
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testSequentialCallActivityWithTimer.bpmn20.xml",
    "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.externalSubProcess.bpmn20.xml" })
public void testSequentialCallActivityWithTimer() {
  String procId = runtimeService.startProcessInstanceByKey("miSequentialCallActivityWithTimer").getId();

  // Complete first subprocess
  List<Task> tasks = taskService.createTaskQuery().orderByTaskName().asc().list();
  assertEquals(2, tasks.size());
  assertEquals("task one", tasks.get(0).getName());
  assertEquals("task two", tasks.get(1).getName());
  taskService.complete(tasks.get(0).getId());
  taskService.complete(tasks.get(1).getId());

  // Fire timer
  Job timer = managementService.createTimerJobQuery().singleResult();
  managementService.moveTimerToExecutableJob(timer.getId());
  managementService.executeJob(timer.getId());

  Task taskAfterTimer = taskService.createTaskQuery().singleResult();
  assertEquals("taskAfterTimer", taskAfterTimer.getTaskDefinitionKey());
  taskService.complete(taskAfterTimer.getId());

  assertProcessEnded(procId);
}
 
Example #16
Source File: TimerEventsAndNewVersionDeploymentsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testTimerRestoreOnDeploymentDelete2() {
  String deploymentId1 = deployTimerProcess();
  String deploymentId2 = deployProcessWithoutTimers(); // Process has same key
  String deploymentId3 = deployTimerProcess();
  String deploymentId4 = deployProcessWithoutTimers();
  
  assertTimerJobs(0);
  
  repositoryService.deleteDeployment(deploymentId3, true);
  assertTimerJobs(0);
  repositoryService.deleteDeployment(deploymentId2, true);
  assertTimerJobs(0);
  repositoryService.deleteDeployment(deploymentId4, true);
  assertTimerJobs(1);
  Job job = managementService.createTimerJobQuery().singleResult();
  assertEquals(repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId1).singleResult().getId(), job.getProcessDefinitionId());
  
  cleanup(deploymentId1);
}
 
Example #17
Source File: DeleteJobCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected JobEntity getJobToDelete(CommandContext commandContext) {
  if (jobId == null) {
    throw new ActivitiIllegalArgumentException("jobId is null");
  }
  if (log.isDebugEnabled()) {
    log.debug("Deleting job {}", jobId);
  }

  JobEntity job = commandContext.getJobEntityManager().findById(jobId);
  if (job == null) {
    throw new ActivitiObjectNotFoundException("No job found with id '" + jobId + "'", Job.class);
  }

  // We need to check if the job was locked, ie acquired by the job acquisition thread
  // This happens if the the job was already acquired, but not yet executed.
  // In that case, we can't allow to delete the job.
  if (job.getLockOwner() != null) {
    throw new ActivitiException("Cannot delete job when the job is being executed. Try again later.");
  }
  return job;
}
 
Example #18
Source File: GetJobExceptionStacktraceCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public String execute(CommandContext commandContext) {
  if (jobId == null) {
    throw new ActivitiIllegalArgumentException("jobId is null");
  }

  AbstractJobEntity job = null;
  switch (jobType) {
  case ASYNC:
    job = commandContext.getJobEntityManager().findById(jobId);
    break;
  case TIMER:
    job = commandContext.getTimerJobEntityManager().findById(jobId);
    break;
  case SUSPENDED:
    job = commandContext.getSuspendedJobEntityManager().findById(jobId);
    break;
  case DEADLETTER:
    job = commandContext.getDeadLetterJobEntityManager().findById(jobId);
    break;
  }
     
  if (job == null) {
    throw new ActivitiObjectNotFoundException("No job found with id " + jobId, Job.class);
  }

  return job.getExceptionStacktrace();
}
 
Example #19
Source File: GetJobExceptionStacktraceCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public String execute(CommandContext commandContext) {
  if(jobId == null) {
    throw new ActivitiIllegalArgumentException("jobId is null");
  }
  
  JobEntity job = commandContext
    .getJobEntityManager()
    .findJobById(jobId);
  
  if(job == null) {
    throw new ActivitiObjectNotFoundException("No job found with id " + jobId, Job.class);
  }
  
  return job.getExceptionStacktrace();
}
 
Example #20
Source File: BoundaryTimerNonInterruptingEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testJoin() {
  // Set the clock fixed
  Date startTime = new Date();

  // After process start, there should be 3 timers created
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("testJoin");
  Task task1 = taskService.createTaskQuery().singleResult();
  assertEquals("Main Task", task1.getName());
  
  TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
  List<Job> jobs = jobQuery.list();
  assertEquals(1, jobs.size());

  // After setting the clock to time '1 hour and 5 seconds', the first timer should fire
  processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((60 * 60 * 1000) + 5000)));
  waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(5000L, 200L);
  
  // timer has fired
  assertEquals(0L, jobQuery.count());

  // we now have both tasks
  assertEquals(2L, taskService.createTaskQuery().count());
  
  // end the first
  taskService.complete(task1.getId());
  
  // we now have one task left
  assertEquals(1L, taskService.createTaskQuery().count());    
  Task task2 = taskService.createTaskQuery().singleResult();
  assertEquals("Escalation Task", task2.getName());

  // complete the task, the parallel gateway should fire
  taskService.complete(task2.getId());

  // and the process has ended
  assertProcessEnded(pi.getId());
}
 
Example #21
Source File: BoundaryTimerNonInterruptingEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
  /**
   * see https://activiti.atlassian.net/browse/ACT-1106
   */
  public void testReceiveTaskWithBoundaryTimer(){
    // Set the clock fixed
    HashMap<String, Object> variables = new HashMap<String, Object>();
    variables.put("timeCycle", "R/PT1H");
    
    // After process start, there should be a timer created
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("nonInterruptingCycle",variables);

    TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
    List<Job> jobs = jobQuery.list();
    assertEquals(1, jobs.size());
    
    // The Execution Query should work normally and find executions in state "task"
    List<Execution> executions = runtimeService.createExecutionQuery()
      .activityId("task")
      .list();
    assertEquals(1, executions.size());
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(executions.get(0).getId());
    assertEquals(1, activeActivityIds.size());
    assertEquals("task", activeActivityIds.get(0));
    
    runtimeService.trigger(executions.get(0).getId());

//    // After setting the clock to time '1 hour and 5 seconds', the second timer should fire
//    processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((60 * 60 * 1000) + 5000)));
//    waitForJobExecutorToProcessAllJobs(5000L, 25L);
//    assertEquals(0L, jobQuery.count());

    // which means the process has ended
    assertProcessEnded(pi.getId());
  }
 
Example #22
Source File: DefaultActiviti5CompatibilityHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void executeJobWithLockAndRetry(Job job) {
  if (job == null) return;
  final ProcessEngineConfigurationImpl processEngineConfig = (ProcessEngineConfigurationImpl) getProcessEngine().getProcessEngineConfiguration();
  org.activiti5.engine.impl.persistence.entity.JobEntity activity5Job = null;
  if (job instanceof org.activiti5.engine.impl.persistence.entity.JobEntity) {
    activity5Job = (org.activiti5.engine.impl.persistence.entity.JobEntity) job;
  } else {
    activity5Job = convertToActiviti5JobEntity((JobEntity) job, processEngineConfig);
  }
  AsyncJobUtil.executeJob(activity5Job, processEngineConfig.getCommandExecutor());
}
 
Example #23
Source File: ManagementServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testExecuteJobUnexistingJob() {
  try {
    managementService.executeJob("unexistingjob");
    fail("ActivitiException expected");
  } catch (JobNotFoundException jnfe) {
    assertTextPresent("No job found with id", jnfe.getMessage());
    assertEquals(Job.class, jnfe.getObjectClass());
  }
}
 
Example #24
Source File: ExclusiveTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testExclusiveService() {
  // start process
  runtimeService.startProcessInstanceByKey("exclusive");
  // now there should be 1 exclusive job in the database:
  Job job = managementService.createJobQuery().singleResult();
  assertNotNull(job);
  assertTrue(((JobEntity) job).isExclusive());

  waitForJobExecutorToProcessAllJobs(6000L, 100L);

  // all the jobs are done
  assertEquals(0, managementService.createJobQuery().count());
}
 
Example #25
Source File: TimerStartEventJobHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void execute(Job job, String configuration, ExecutionEntity execution, CommandContext commandContext) {
  
  DeploymentManager deploymentManager = Context
      .getProcessEngineConfiguration()
      .getDeploymentManager();
  
  if (TimerEventHandler.hasRealActivityId(configuration)) {
    startProcessInstanceWithInitialActivity(job, configuration, deploymentManager, commandContext);
  } else {
    startProcessDefinitionByKey(job, configuration, deploymentManager, commandContext);
  }
}
 
Example #26
Source File: JobEventsTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/activiti5/engine/test/api/event/JobEventsTest.testJobCanceledEventOnBoundaryEvent.bpmn20.xml")
public void testJobCanceledEventByManagementService() throws Exception {
  // GIVEN
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testTimerCancelledEvent");
  listener.clearEventsReceived();

  Job job = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();

  // WHEN
  managementService.deleteTimerJob(job.getId());

  // THEN
  checkEventCount(1, ActivitiEventType.JOB_CANCELED);
}
 
Example #27
Source File: ProcessInstanceSuspensionTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testJobNotExecutedAfterProcessInstanceSuspend() {

  Date now = new Date();
  processEngineConfiguration.getClock().setCurrentTime(now);

  // Suspending the process instance should also stop the execution of jobs for that process instance
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
  ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
  assertEquals(1, managementService.createTimerJobQuery().count());
  runtimeService.suspendProcessInstanceById(processInstance.getId());
  assertEquals(1, managementService.createSuspendedJobQuery().count());

  // The jobs should not be executed now
  processEngineConfiguration.getClock().setCurrentTime(new Date(now.getTime() + (60 * 60 * 1000))); // Timer is set to fire on 5 minutes
  Job job = managementService.createTimerJobQuery().executable().singleResult();
  assertNull(job);

  assertEquals(1, managementService.createSuspendedJobQuery().count());

  // Activation of the process instance should now allow for job execution
  runtimeService.activateProcessInstanceById(processInstance.getId());
  waitForJobExecutorToProcessAllJobs(10000L, 100L);
  assertEquals(0, managementService.createJobQuery().count());
  assertEquals(0, managementService.createTimerJobQuery().count());
  assertEquals(0, managementService.createSuspendedJobQuery().count());
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
 
Example #28
Source File: TimerCustomCalendarTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testBoundaryTimer() {
  this.runtimeService.startProcessInstanceByKey("testBoundaryTimer");

  List<Job> jobs = this.managementService.createTimerJobQuery().list();
  assertThat("One job is scheduled", jobs.size(), is(1));
  assertThat("Job must be scheduled by custom business calendar to Date(0)", jobs.get(0).getDuedate(), is(new Date(0)));

  this.managementService.moveTimerToExecutableJob(jobs.get(0).getId());
  this.managementService.executeJob(jobs.get(0).getId());
  waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(10000, 200);
}
 
Example #29
Source File: SuspendedJobEntityManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public List<Job> findSuspendedJobsByTypeAndProcessDefinitionId(String jobHandlerType, String processDefinitionId) {
	 Map<String, String> params = new HashMap<String, String>(2);
   params.put("handlerType", jobHandlerType);
   params.put("processDefinitionId", processDefinitionId);
   return getDbSqlSession().selectList("selectSuspendedJobByTypeAndProcessDefinitionId", params);
}
 
Example #30
Source File: BoundaryTimerEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testExpressionOnTimer(){
  Clock clock = processEngineConfiguration.getClock();
  // Set the clock fixed
  clock.reset();
  Date startTime = clock.getCurrentTime();
  processEngineConfiguration.setClock(clock);
  
  HashMap<String, Object> variables = new HashMap<String, Object>();
  variables.put("duration", "PT1H");
  
  // After process start, there should be a timer created
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("testExpressionOnTimer", variables);

  TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
  List<Job> jobs = jobQuery.list();
  assertEquals(1, jobs.size());

  // After setting the clock to time '1 hour and 5 seconds', the second timer should fire
  clock.setCurrentTime(new Date(startTime.getTime() + ((60 * 60 * 1000) + 5000)));
  processEngineConfiguration.setClock(clock);
  
  waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(5000L, 200L);
  assertEquals(0L, jobQuery.count());
  
  // start execution listener is not executed
  assertFalse(listenerExecutedStartEvent);
  assertTrue(listenerExecutedEndEvent);

  // which means the process has ended
  assertProcessEnded(pi.getId());
  
  processEngineConfiguration.resetClock();
}