use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class ProcessInstanceQueryAndWithExceptionTest method startProcessInstanceWithFailingJob.
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;
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class BoundaryTimerEventTest method testInterruptingTimerDuration.
@Deployment
public void testInterruptingTimerDuration() {
// Start process instance
ProcessInstance pi = runtimeService.startProcessInstanceByKey("escalationExample");
// There should be one task, with a timer : first line support
Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
assertEquals("First line support", task.getName());
// Manually execute the job
Job timer = managementService.createJobQuery().singleResult();
managementService.executeJob(timer.getId());
// The timer has fired, and the second task (secondlinesupport) now exists
task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
assertEquals("Handle escalated issue", task.getName());
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class JobCollectionResourceTest method testGetJobs.
@Deployment(resources = { "org/activiti/rest/service/api/management/JobCollectionResourceTest.testTimerProcess.bpmn20.xml" })
public void testGetJobs() throws Exception {
Calendar hourAgo = Calendar.getInstance();
hourAgo.add(Calendar.HOUR, -1);
Calendar inAnHour = Calendar.getInstance();
inAnHour.add(Calendar.HOUR, 1);
// Start process, forcing error on job-execution
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerProcess", Collections.singletonMap("error", (Object) Boolean.TRUE));
Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).timers().singleResult();
assertNotNull(timerJob);
for (int i = 0; i < timerJob.getRetries(); i++) {
// Force execution of job until retries are exhausted
try {
managementService.executeJob(timerJob.getId());
fail();
} catch (ActivitiException expected) {
// Ignore, we expect the exception
}
}
timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).timers().singleResult();
assertEquals(0, timerJob.getRetries());
// Fetch the async-job (which has retries left)
Job asyncJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).withRetriesLeft().singleResult();
// Test fetching all jobs
String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION);
assertResultsPresentInDataResponse(url, asyncJob.getId(), timerJob.getId());
// Fetch using job-id
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?id=" + asyncJob.getId();
assertResultsPresentInDataResponse(url, asyncJob.getId());
// Fetch using processInstanceId
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?processInstanceId=" + processInstance.getId();
assertResultsPresentInDataResponse(url, asyncJob.getId(), timerJob.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?processInstanceId=unexisting";
assertResultsPresentInDataResponse(url);
// Fetch using executionId
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?executionId=" + asyncJob.getExecutionId();
assertResultsPresentInDataResponse(url, asyncJob.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?executionId=" + timerJob.getExecutionId();
assertResultsPresentInDataResponse(url, timerJob.getId());
// Fetch using processDefinitionId
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?processDefinitionId=" + processInstance.getProcessDefinitionId();
assertResultsPresentInDataResponse(url, asyncJob.getId(), timerJob.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?processDefinitionId=unexisting";
assertResultsPresentInDataResponse(url);
// Fetch using withRetriesLeft
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?withRetriesLeft=true";
assertResultsPresentInDataResponse(url, asyncJob.getId());
// Fetch using executable
// url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?executable=true";
// assertResultsPresentInDataResponse(url, asyncJob.getId());
// Fetch using timers only
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?timersOnly=true";
assertResultsPresentInDataResponse(url, timerJob.getId());
// Combining messagesOnly with timersOnly should result in exception
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?timersOnly=true&messagesOnly=true"), HttpStatus.SC_BAD_REQUEST));
// Fetch using dueBefore
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?dueBefore=" + getISODateString(inAnHour.getTime());
assertResultsPresentInDataResponse(url, timerJob.getId(), asyncJob.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?dueBefore=" + getISODateString(hourAgo.getTime());
assertResultsPresentInDataResponse(url);
// Fetch using dueAfter
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?dueAfter=" + getISODateString(hourAgo.getTime());
assertResultsPresentInDataResponse(url, timerJob.getId(), asyncJob.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?dueAfter=" + getISODateString(inAnHour.getTime());
assertResultsPresentInDataResponse(url);
// Fetch using withException
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?withException=true";
assertResultsPresentInDataResponse(url, timerJob.getId());
// Fetch with exceptionMessage
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?exceptionMessage=" + encode(timerJob.getExceptionMessage());
assertResultsPresentInDataResponse(url, timerJob.getId());
// Fetch with empty exceptionMessage
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?exceptionMessage=";
assertResultsPresentInDataResponse(url);
// Without tenant id, before tenant update
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?withoutTenantId=true";
assertResultsPresentInDataResponse(url, timerJob.getId(), asyncJob.getId());
// Set tenant on deployment
managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));
// Without tenant id, after tenant update
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?withoutTenantId=true";
assertResultsPresentInDataResponse(url);
// Tenant id
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?tenantId=myTenant";
assertResultsPresentInDataResponse(url, timerJob.getId(), asyncJob.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?tenantId=anotherTenant";
assertResultsPresentInDataResponse(url);
// Tenant id like
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?tenantIdLike=" + encode("%enant");
assertResultsPresentInDataResponse(url, timerJob.getId(), asyncJob.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_COLLECTION) + "?tenantIdLike=anotherTenant";
assertResultsPresentInDataResponse(url);
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class JobExceptionStacktraceResourceTest method testGetJobStacktrace.
/**
* Test getting the stacktrace for a failed job
*/
@Deployment(resources = { "org/activiti/rest/service/api/management/JobExceptionStacktraceResourceTest.testTimerProcess.bpmn20.xml" })
public void testGetJobStacktrace() throws Exception {
// Start process, forcing error on job-execution
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerProcess", Collections.singletonMap("error", (Object) Boolean.TRUE));
Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(timerJob);
// Force execution of job
try {
managementService.executeJob(timerJob.getId());
fail();
} catch (ActivitiException expected) {
// Ignore, we expect the exception
}
Calendar now = Calendar.getInstance();
now.set(Calendar.MILLISECOND, 0);
processEngineConfiguration.getClock().setCurrentTime(now.getTime());
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_JOB_EXCEPTION_STRACKTRACE, timerJob.getId())), HttpStatus.SC_OK);
String stack = IOUtils.toString(response.getEntity().getContent());
assertNotNull(stack);
assertEquals(managementService.getJobExceptionStacktrace(timerJob.getId()), stack);
// Also check content-type
assertEquals("text/plain", response.getEntity().getContentType().getValue());
closeResponse(response);
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class ManagementServiceTest method testGetJobExceptionStacktrace.
@Deployment
public void testGetJobExceptionStacktrace() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exceptionInJobExecution");
// The execution is waiting in the first usertask. This contains a boundry
// timer event which we will execute manual for testing purposes.
Job timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull("No job found for process instance", timerJob);
try {
managementService.executeJob(timerJob.getId());
fail("RuntimeException from within the script task expected");
} catch (RuntimeException re) {
assertTextPresent("This is an exception thrown from scriptTask", re.getCause().getMessage());
}
// Fetch the task to see that the exception that occurred is persisted
timerJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(timerJob);
assertNotNull(timerJob.getExceptionMessage());
assertTextPresent("This is an exception thrown from scriptTask", timerJob.getExceptionMessage());
// Get the full stacktrace using the managementService
String exceptionStack = managementService.getJobExceptionStacktrace(timerJob.getId());
assertNotNull(exceptionStack);
assertTextPresent("This is an exception thrown from scriptTask", exceptionStack);
}
Aggregations