Search in sources :

Example 16 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.

the class JobQueryTest method testQueryByExceptionMessage.

@Deployment(resources = { "org/activiti/engine/test/api/mgmt/ManagementServiceTest.testGetJobExceptionStacktrace.bpmn20.xml" })
public void testQueryByExceptionMessage() {
    TimerJobQuery query = managementService.createTimerJobQuery().exceptionMessage(EXCEPTION_MESSAGE);
    verifyQueryResults(query, 0);
    ProcessInstance processInstance = startProcessInstanceWithFailingJob();
    query = managementService.createTimerJobQuery().exceptionMessage(EXCEPTION_MESSAGE);
    verifyFailedJob(query, processInstance);
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) Deployment(org.activiti.engine.test.Deployment)

Example 17 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.

the class JobQueryTest method testQueryByException.

@Deployment(resources = { "org/activiti/engine/test/api/mgmt/ManagementServiceTest.testGetJobExceptionStacktrace.bpmn20.xml" })
public void testQueryByException() {
    TimerJobQuery query = managementService.createTimerJobQuery().withException();
    verifyQueryResults(query, 0);
    ProcessInstance processInstance = startProcessInstanceWithFailingJob();
    query = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).withException();
    verifyFailedJob(query, processInstance);
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) Deployment(org.activiti.engine.test.Deployment)

Example 18 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.

the class JobQueryTest method testQueryByRetriesLeft.

public void testQueryByRetriesLeft() {
    JobQuery query = managementService.createJobQuery();
    verifyQueryResults(query, 1);
    TimerJobQuery timerQuery = managementService.createTimerJobQuery();
    verifyQueryResults(timerQuery, 3);
    final Job job = managementService.createTimerJobQuery().processInstanceId(processInstanceIdOne).singleResult();
    managementService.setTimerJobRetries(job.getId(), 0);
    managementService.moveJobToDeadLetterJob(job.getId());
    // Re-running the query should give only 3 jobs now, since one job has retries=0
    verifyQueryResults(query, 1);
    verifyQueryResults(timerQuery, 2);
}
Also used : TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) JobQuery(org.activiti.engine.runtime.JobQuery) Job(org.activiti.engine.runtime.Job) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery)

Example 19 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.

the class JobQueryTest method testQuerySorting.

// sorting //////////////////////////////////////////
public void testQuerySorting() {
    // asc
    assertThat(managementService.createJobQuery().orderByJobId().asc().count()).isEqualTo(1);
    assertThat(managementService.createJobQuery().orderByJobDuedate().asc().count()).isEqualTo(1);
    assertThat(managementService.createJobQuery().orderByExecutionId().asc().count()).isEqualTo(1);
    assertThat(managementService.createJobQuery().orderByProcessInstanceId().asc().count()).isEqualTo(1);
    assertThat(managementService.createJobQuery().orderByJobRetries().asc().count()).isEqualTo(1);
    assertThat(managementService.createTimerJobQuery().orderByJobId().asc().count()).isEqualTo(3);
    assertThat(managementService.createTimerJobQuery().orderByJobDuedate().asc().count()).isEqualTo(3);
    assertThat(managementService.createTimerJobQuery().orderByExecutionId().asc().count()).isEqualTo(3);
    assertThat(managementService.createTimerJobQuery().orderByProcessInstanceId().asc().count()).isEqualTo(3);
    assertThat(managementService.createTimerJobQuery().orderByJobRetries().asc().count()).isEqualTo(3);
    // desc
    assertThat(managementService.createJobQuery().orderByJobId().desc().count()).isEqualTo(1);
    assertThat(managementService.createJobQuery().orderByJobDuedate().desc().count()).isEqualTo(1);
    assertThat(managementService.createJobQuery().orderByExecutionId().desc().count()).isEqualTo(1);
    assertThat(managementService.createJobQuery().orderByProcessInstanceId().desc().count()).isEqualTo(1);
    assertThat(managementService.createJobQuery().orderByJobRetries().desc().count()).isEqualTo(1);
    assertThat(managementService.createTimerJobQuery().orderByJobId().desc().count()).isEqualTo(3);
    assertThat(managementService.createTimerJobQuery().orderByJobDuedate().desc().count()).isEqualTo(3);
    assertThat(managementService.createTimerJobQuery().orderByExecutionId().desc().count()).isEqualTo(3);
    assertThat(managementService.createTimerJobQuery().orderByProcessInstanceId().desc().count()).isEqualTo(3);
    assertThat(managementService.createTimerJobQuery().orderByJobRetries().desc().count()).isEqualTo(3);
    // sorting on multiple fields
    setRetries(processInstanceIdTwo, 2);
    // make sure all timers can fire
    processEngineConfiguration.getClock().setCurrentTime(new Date(timerThreeFireTime.getTime() + ONE_SECOND));
    TimerJobQuery query = managementService.createTimerJobQuery().timers().executable().orderByJobRetries().asc().orderByJobDuedate().desc();
    List<Job> jobs = query.list();
    assertThat(jobs).hasSize(3);
    assertThat(jobs.get(0).getRetries()).isEqualTo(2);
    assertThat(jobs.get(1).getRetries()).isEqualTo(3);
    assertThat(jobs.get(2).getRetries()).isEqualTo(3);
    assertThat(jobs.get(0).getProcessInstanceId()).isEqualTo(processInstanceIdTwo);
    assertThat(jobs.get(1).getProcessInstanceId()).isEqualTo(processInstanceIdThree);
    assertThat(jobs.get(2).getProcessInstanceId()).isEqualTo(processInstanceIdOne);
}
Also used : Job(org.activiti.engine.runtime.Job) Date(java.util.Date) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery)

Example 20 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.

the class JobQueryTest method testQueryByExecutable.

public void testQueryByExecutable() {
    // all obs should be executable at t3 + 1hour.1second
    processEngineConfiguration.getClock().setCurrentTime(new Date(timerThreeFireTime.getTime() + ONE_SECOND));
    JobQuery query = managementService.createJobQuery();
    verifyQueryResults(query, 1);
    TimerJobQuery timerQuery = managementService.createTimerJobQuery().executable();
    verifyQueryResults(timerQuery, 3);
    // Setting retries of one job to 0, makes it non-executable
    final Job job = managementService.createTimerJobQuery().processInstanceId(processInstanceIdOne).singleResult();
    managementService.setTimerJobRetries(job.getId(), 0);
    managementService.moveJobToDeadLetterJob(job.getId());
    verifyQueryResults(query, 1);
    verifyQueryResults(timerQuery, 2);
    // Setting the clock before the start of the process instance, makes
    // none of the timer jobs executable
    processEngineConfiguration.getClock().setCurrentTime(testStartTime);
    verifyQueryResults(query, 1);
    verifyQueryResults(timerQuery, 0);
    // Moving the job back to be executable
    managementService.moveDeadLetterJobToExecutableJob(job.getId(), 5);
    verifyQueryResults(query, 2);
    verifyQueryResults(timerQuery, 0);
}
Also used : TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) JobQuery(org.activiti.engine.runtime.JobQuery) Job(org.activiti.engine.runtime.Job) Date(java.util.Date) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery)

Aggregations

TimerJobQuery (org.activiti.engine.runtime.TimerJobQuery)35 Deployment (org.activiti.engine.test.Deployment)20 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)18 Date (java.util.Date)16 Job (org.activiti.engine.runtime.Job)10 JobQuery (org.activiti.engine.runtime.JobQuery)7 Task (org.activiti.engine.task.Task)5 HashMap (java.util.HashMap)3 Execution (org.activiti.engine.runtime.Execution)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 ProcessInstanceQuery (org.activiti.engine.runtime.ProcessInstanceQuery)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 List (java.util.List)1 HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)1 Test (org.junit.Test)1