Search in sources :

Example 11 with JobQuery

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

the class BoundaryTimerEventTest method testExpressionOnTimer.

@Deployment
public void testExpressionOnTimer() {
    // Set the clock fixed
    Date startTime = new Date();
    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);
    JobQuery jobQuery = managementService.createJobQuery().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
    processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((60 * 60 * 1000) + 5000)));
    waitForJobExecutorToProcessAllJobs(5000L, 25L);
    assertEquals(0L, jobQuery.count());
    // start execution listener is not executed
    assertFalse(listenerExecutedStartEvent);
    assertTrue(listenerExecutedEndEvent);
    // which means the process has ended
    assertProcessEnded(pi.getId());
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JobQuery(org.activiti.engine.runtime.JobQuery) Job(org.activiti.engine.runtime.Job) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 12 with JobQuery

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

the class ProcessInstanceQueryAndWithExceptionTest method testQueryWithException.

public void testQueryWithException() throws InterruptedException {
    ProcessInstance processNoException = runtimeService.startProcessInstanceByKey(PROCESS_DEFINITION_KEY_NO_EXCEPTION);
    ProcessInstanceQuery queryNoException = runtimeService.createProcessInstanceQuery();
    assertEquals(1, queryNoException.count());
    assertEquals(1, queryNoException.list().size());
    assertEquals(processNoException.getId(), queryNoException.list().get(0).getId());
    ProcessInstanceQuery queryWithException = runtimeService.createProcessInstanceQuery();
    assertEquals(0, queryWithException.withJobException().count());
    assertEquals(0, queryWithException.withJobException().list().size());
    ProcessInstance processWithException1 = startProcessInstanceWithFailingJob(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_1);
    JobQuery jobQuery1 = managementService.createJobQuery().processInstanceId(processWithException1.getId());
    assertEquals(1, jobQuery1.withException().count());
    assertEquals(1, jobQuery1.withException().list().size());
    assertEquals(1, queryWithException.withJobException().count());
    assertEquals(1, queryWithException.withJobException().list().size());
    assertEquals(processWithException1.getId(), queryWithException.withJobException().list().get(0).getId());
    ProcessInstance processWithException2 = startProcessInstanceWithFailingJob(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_2);
    JobQuery jobQuery2 = managementService.createJobQuery().processInstanceId(processWithException2.getId());
    assertEquals(2, jobQuery2.withException().count());
    assertEquals(2, jobQuery2.withException().list().size());
    assertEquals(2, queryWithException.withJobException().count());
    assertEquals(2, queryWithException.withJobException().list().size());
    assertEquals(processWithException1.getId(), queryWithException.withJobException().processDefinitionKey(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_1).list().get(0).getId());
    assertEquals(processWithException2.getId(), queryWithException.withJobException().processDefinitionKey(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_2).list().get(0).getId());
}
Also used : ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JobQuery(org.activiti.engine.runtime.JobQuery)

Example 13 with JobQuery

use of org.activiti.engine.runtime.JobQuery in project herd by FINRAOS.

the class ActivitiServiceTest method testGetJobsWithExceptionByProcessInstanceId.

@Test
public void testGetJobsWithExceptionByProcessInstanceId() {
    String processInstanceId = "processInstanceId";
    JobQuery jobQuery = mock(JobQuery.class);
    when(activitiManagementService.createJobQuery()).thenReturn(jobQuery);
    when(jobQuery.withException()).thenReturn(jobQuery);
    when(jobQuery.processInstanceId(processInstanceId)).thenReturn(jobQuery);
    List<Job> expectedJobs = new ArrayList<>();
    when(jobQuery.list()).thenReturn(expectedJobs);
    List<Job> actualJobs = activitiService.getJobsWithExceptionByProcessInstanceId(processInstanceId);
    assertSame(expectedJobs, actualJobs);
    InOrder inOrder = inOrder(jobQuery);
    inOrder.verify(jobQuery).withException();
    inOrder.verify(jobQuery).processInstanceId(processInstanceId);
    inOrder.verify(jobQuery).list();
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) ArrayList(java.util.ArrayList) JobQuery(org.activiti.engine.runtime.JobQuery) Job(org.activiti.engine.runtime.Job) Test(org.junit.Test)

Example 14 with JobQuery

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

the class JobQueryTest method testQueryByInvalidProcessInstanceId.

public void testQueryByInvalidProcessInstanceId() {
    JobQuery query = managementService.createJobQuery().processInstanceId("invalid");
    verifyQueryResults(query, 0);
    try {
        managementService.createJobQuery().processInstanceId(null);
        fail();
    } catch (ActivitiIllegalArgumentException e) {
    }
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) JobQuery(org.activiti.engine.runtime.JobQuery)

Example 15 with JobQuery

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

the class JobQueryTest method testQueryByRetriesLeft.

public void testQueryByRetriesLeft() {
    JobQuery query = managementService.createJobQuery().withRetriesLeft();
    verifyQueryResults(query, 4);
    setRetries(processInstanceIdOne, 0);
    // Re-running the query should give only 3 jobs now, since one job has retries=0
    verifyQueryResults(query, 3);
}
Also used : JobQuery(org.activiti.engine.runtime.JobQuery)

Aggregations

JobQuery (org.activiti.engine.runtime.JobQuery)39 Deployment (org.activiti.engine.test.Deployment)20 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)17 Date (java.util.Date)15 Job (org.activiti.engine.runtime.Job)9 Task (org.activiti.engine.task.Task)5 HashMap (java.util.HashMap)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 Execution (org.activiti.engine.runtime.Execution)2 ProcessInstanceQuery (org.activiti.engine.runtime.ProcessInstanceQuery)2 Test (org.junit.Test)2 InOrder (org.mockito.InOrder)2 ArrayList (java.util.ArrayList)1 HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)1