use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class JobListQuery method loadItems.
public List<Item> loadItems(int start, int count) {
List<Job> jobs = managementService.createJobQuery().orderByJobDuedate().asc().orderByJobId().asc().list();
List<Item> items = new ArrayList<Item>();
for (Job job : jobs) {
items.add(new JobListItem(job));
}
return items;
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class RestResponseFactory method createJobResponseList.
public List<JobResponse> createJobResponseList(List<Job> jobs) {
RestUrlBuilder urlBuilder = createUrlBuilder();
List<JobResponse> responseList = new ArrayList<JobResponse>();
for (Job instance : jobs) {
responseList.add(createJobResponse(instance, urlBuilder));
}
return responseList;
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class JobEventsTest method testJobEntityEventsException.
/**
* Test create, update and delete events of jobs entities.
*/
@Deployment
public void testJobEntityEventsException() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testJobEvents");
Job theJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(theJob);
// Set retries to 1, to prevent multiple chains of events being thrown
managementService.setJobRetries(theJob.getId(), 1);
listener.clearEventsReceived();
// Force timer to fire
Calendar tomorrow = Calendar.getInstance();
tomorrow.add(Calendar.DAY_OF_YEAR, 1);
processEngineConfiguration.getClock().setCurrentTime(tomorrow.getTime());
try {
managementService.executeJob(theJob.getId());
fail("Expected exception");
} catch (Exception e) {
// exception expected
}
// Check delete-event has been dispatched
assertEquals(5, listener.getEventsReceived().size());
// First, the timer was fired
ActivitiEvent event = listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.TIMER_FIRED, event.getType());
checkEventContext(event, theJob, true);
// Second, the job-entity was deleted, as the job was executed
event = listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
checkEventContext(event, theJob, true);
// Next, a job failed event is dispatched
event = listener.getEventsReceived().get(2);
assertEquals(ActivitiEventType.JOB_EXECUTION_FAILURE, event.getType());
checkEventContext(event, theJob, true);
// Finally, an update-event is received and the job count is decremented
event = listener.getEventsReceived().get(3);
assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
checkEventContext(event, theJob, true);
event = listener.getEventsReceived().get(4);
assertEquals(ActivitiEventType.JOB_RETRIES_DECREMENTED, event.getType());
assertEquals(0, ((Job) ((ActivitiEntityEvent) event).getEntity()).getRetries());
checkEventContext(event, theJob, true);
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class JobEventsTest method testRepetitionJobEntityEvents.
/**
* Timer repetition
*/
@Deployment
public void testRepetitionJobEntityEvents() throws Exception {
Clock previousClock = processEngineConfiguration.getClock();
Clock testClock = new DefaultClockImpl();
processEngineConfiguration.setClock(testClock);
Date now = new Date();
testClock.setCurrentTime(now);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testRepetitionJobEvents");
Job theJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(theJob);
// Check if create-event has been dispatched
assertEquals(2, listener.getEventsReceived().size());
ActivitiEvent event = listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
checkEventContext(event, theJob, false);
event = listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
checkEventContext(event, theJob, false);
listener.clearEventsReceived();
try {
waitForJobExecutorToProcessAllJobs(2000, 100);
fail("a new job must be prepared because there are 2 repeats");
} catch (Exception ex) {
//expected exception because a new job is prepared
}
testClock.setCurrentTime(new Date(now.getTime() + 10000L));
try {
waitForJobExecutorToProcessAllJobs(2000, 100);
fail("a new job must be prepared because there are 2 repeats");
} catch (Exception ex) {
//expected exception because a new job is prepared
}
testClock.setCurrentTime(new Date(now.getTime() + 20000L));
try {
waitForJobExecutorToProcessAllJobs(2000, 100);
} catch (Exception ex) {
fail("There must be no jobs remaining");
}
testClock.setCurrentTime(new Date(now.getTime() + 30000L));
try {
waitForJobExecutorToProcessAllJobs(2000, 100);
} catch (Exception ex) {
fail("There must be no jobs remaining");
}
// count timer fired events
int timerFiredCount = 0;
List<ActivitiEvent> eventsReceived = listener.getEventsReceived();
for (ActivitiEvent eventReceived : eventsReceived) {
if (ActivitiEventType.TIMER_FIRED.equals(eventReceived.getType())) {
timerFiredCount++;
}
}
listener.clearEventsReceived();
processEngineConfiguration.setClock(previousClock);
assertEquals(2, timerFiredCount);
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class JobEventsTest method testJobCanceledEventByManagementService.
@Deployment(resources = "org/activiti/engine/test/api/event/JobEventsTest.testJobCanceledEventOnBoundaryEvent.bpmn20.xml")
public void testJobCanceledEventByManagementService() throws Exception {
// GIVEN
processEngineConfiguration.getClock().setCurrentTime(new Date());
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testTimerCancelledEvent");
listener.clearEventsReceived();
Job job = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
// WHEN
managementService.deleteJob(job.getId());
// THEN
checkEventCount(1, ActivitiEventType.JOB_CANCELED);
}
Aggregations