use of org.activiti.engine.runtime.JobQuery in project Activiti by Activiti.
the class JobQueryTest method testQueryByDuedateHigherThan.
public void testQueryByDuedateHigherThan() {
JobQuery query = managementService.createJobQuery().duedateHigherThan(testStartTime);
verifyQueryResults(query, 4);
query = managementService.createJobQuery().duedateHigherThan(timerOneFireTime);
verifyQueryResults(query, 3);
query = managementService.createJobQuery().duedateHigherThan(timerTwoFireTime);
verifyQueryResults(query, 2);
query = managementService.createJobQuery().duedateHigherThan(timerThreeFireTime);
verifyQueryResults(query, 0);
}
use of org.activiti.engine.runtime.JobQuery in project Activiti by Activiti.
the class JobQueryTest method testQueryByProcessInstanceId.
public void testQueryByProcessInstanceId() {
JobQuery query = managementService.createJobQuery().processInstanceId(processInstanceIdOne);
verifyQueryResults(query, 1);
}
use of org.activiti.engine.runtime.JobQuery in project Activiti by Activiti.
the class JobQueryTest method testQueryByDuedateLowerThan.
public void testQueryByDuedateLowerThan() {
JobQuery query = managementService.createJobQuery().duedateLowerThan(testStartTime);
verifyQueryResults(query, 0);
query = managementService.createJobQuery().duedateLowerThan(new Date(timerOneFireTime.getTime() + ONE_SECOND));
verifyQueryResults(query, 1);
query = managementService.createJobQuery().duedateLowerThan(new Date(timerTwoFireTime.getTime() + ONE_SECOND));
verifyQueryResults(query, 2);
query = managementService.createJobQuery().duedateLowerThan(new Date(timerThreeFireTime.getTime() + ONE_SECOND));
verifyQueryResults(query, 4);
}
use of org.activiti.engine.runtime.JobQuery in project Activiti by Activiti.
the class MessageBoundaryEventTest method testSingleBoundaryMessageEventWithBoundaryTimerEvent.
@Deployment
public void testSingleBoundaryMessageEventWithBoundaryTimerEvent() {
final Date startTime = new Date();
runtimeService.startProcessInstanceByKey("process");
assertEquals(2, runtimeService.createExecutionQuery().count());
Execution execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
assertNull(execution);
// ///////////////////////////////////
// Verify the first task
Task userTask = taskService.createTaskQuery().singleResult();
assertNotNull(userTask);
assertEquals("task", userTask.getTaskDefinitionKey());
// ///////////////////////////////////
// Advance the clock to trigger the timer.
final JobQuery jobQuery = managementService.createJobQuery().processInstanceId(userTask.getProcessInstanceId());
assertEquals(1, jobQuery.count());
// After setting the clock to time '1 hour and 5 seconds', the timer should fire.
processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((60 * 60 * 1000) + 5000)));
waitForJobExecutorOnCondition(12000L, 100L, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return taskService.createTaskQuery().count() == 2;
}
});
// It is a repeating job, so it will come back.
assertEquals(1L, jobQuery.count());
// ///////////////////////////////////
// Verify and complete the first task
userTask = taskService.createTaskQuery().taskDefinitionKey("task").singleResult();
assertNotNull(userTask);
taskService.complete(userTask.getId());
// ///////////////////////////////////
// Complete the after timer task
userTask = taskService.createTaskQuery().taskDefinitionKey("taskTimer").singleResult();
assertNotNull(userTask);
taskService.complete(userTask.getId());
// Timer job of boundary event of task should be deleted and timer job of task timer boundary event should be created.
assertEquals(1L, jobQuery.count());
// ///////////////////////////////////
// Verify that the message exists
userTask = taskService.createTaskQuery().singleResult();
assertEquals("taskAfterTask", userTask.getTaskDefinitionKey());
execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
assertNotNull(execution);
// ///////////////////////////////////
// Send the message and verify that we went back to the right spot.
runtimeService.messageEventReceived("messageName", execution.getId());
userTask = taskService.createTaskQuery().singleResult();
assertNotNull(userTask);
assertEquals("task", userTask.getTaskDefinitionKey());
execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
assertNull(execution);
// ///////////////////////////////////
// Complete the first task (again).
taskService.complete(userTask.getId());
userTask = taskService.createTaskQuery().singleResult();
assertNotNull(userTask);
assertEquals("taskAfterTask", userTask.getTaskDefinitionKey());
execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
assertNotNull(execution);
// ///////////////////////////////////
// Verify timer firing.
// After setting the clock to time '2 hours and 5 seconds', the timer should fire.
processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((2 * 60 * 60 * 1000) + 5000)));
waitForJobExecutorOnCondition(2000L, 100L, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return taskService.createTaskQuery().count() == 2;
}
});
// It is a repeating job, so it will come back.
assertEquals(1L, jobQuery.count());
// After setting the clock to time '3 hours and 5 seconds', the timer should fire again.
processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((3 * 60 * 60 * 1000) + 5000)));
waitForJobExecutorOnCondition(2000L, 100L, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return taskService.createTaskQuery().list().size() == 3;
}
});
// It is a repeating job, so it will come back.
assertEquals(1L, jobQuery.count());
// ///////////////////////////////////
// Complete the after timer tasks
final List<Task> tasks = taskService.createTaskQuery().taskDefinitionKey("taskAfterTaskTimer").list();
assertEquals(2, tasks.size());
taskService.complete(tasks.get(0).getId());
taskService.complete(tasks.get(1).getId());
// ///////////////////////////////////
// Complete the second task
taskService.complete(userTask.getId());
// ///////////////////////////////////
// Complete the third task
userTask = taskService.createTaskQuery().singleResult();
assertNotNull(userTask);
assertEquals("taskAfterTaskAfterTask", userTask.getTaskDefinitionKey());
taskService.complete(userTask.getId());
// ///////////////////////////////////
// We should be done at this point
assertEquals(0, runtimeService.createProcessInstanceQuery().count());
execution = runtimeService.createExecutionQuery().messageEventSubscriptionName("messageName").singleResult();
assertNull(execution);
}
use of org.activiti.engine.runtime.JobQuery in project Activiti by Activiti.
the class HistoricProcessInstanceQueryAndWithExceptionTest method testQueryWithException.
public void testQueryWithException() throws InterruptedException {
ProcessInstance processNoException = runtimeService.startProcessInstanceByKey(PROCESS_DEFINITION_KEY_NO_EXCEPTION);
HistoricProcessInstanceQuery queryNoException = historyService.createHistoricProcessInstanceQuery();
assertEquals(1, queryNoException.count());
assertEquals(1, queryNoException.list().size());
assertEquals(processNoException.getId(), queryNoException.list().get(0).getId());
HistoricProcessInstanceQuery queryWithException = historyService.createHistoricProcessInstanceQuery();
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());
}
Aggregations