use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class CamelExceptionTest method testNonBpmnPathAsynchronous.
// check non bpmn exception in asynchronouse camel call
@Deployment(resources = { "org/activiti/camel/exception/bpmnExceptionInRouteAsynchronous.bpmn20.xml" })
public void testNonBpmnPathAsynchronous() {
// Signal ThrowBpmnExceptionBean to throw non bpmn exception
ThrowBpmnExceptionBean.setExceptionType(ThrowBpmnExceptionBean.ExceptionType.NON_BPMN_EXCEPTION);
runtimeService.startProcessInstanceByKey("exceptionInRouteSynchron");
assertTrue(JobTestHelper.areJobsAvailable(managementService));
Job job = managementService.createJobQuery().singleResult();
try {
managementService.executeJob(job.getId());
fail();
} catch (Exception e) {
// expected
}
job = managementService.createJobQuery().singleResult();
assertEquals("Unhandled exception on camel route", job.getExceptionMessage());
assertFalse(ExceptionServiceMock.isCalled());
assertFalse(NoExceptionServiceMock.isCalled());
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class ActivitiEventBuilder method populateEventWithCurrentContext.
protected static void populateEventWithCurrentContext(ActivitiEventImpl event) {
boolean extractedFromContext = false;
if (Context.isExecutionContextActive()) {
ExecutionContext executionContext = Context.getExecutionContext();
if (executionContext != null) {
extractedFromContext = true;
event.setExecutionId(executionContext.getExecution().getId());
event.setProcessInstanceId(executionContext.getExecution().getProcessInstanceId());
event.setProcessDefinitionId(executionContext.getExecution().getProcessDefinitionId());
}
}
// Fallback to fetching context from the object itself
if (!extractedFromContext) {
if (event instanceof ActivitiEntityEvent) {
Object persistendObject = ((ActivitiEntityEvent) event).getEntity();
if (persistendObject instanceof Job) {
event.setExecutionId(((Job) persistendObject).getExecutionId());
event.setProcessInstanceId(((Job) persistendObject).getProcessInstanceId());
event.setProcessDefinitionId(((Job) persistendObject).getProcessDefinitionId());
} else if (persistendObject instanceof DelegateExecution) {
event.setExecutionId(((DelegateExecution) persistendObject).getId());
event.setProcessInstanceId(((DelegateExecution) persistendObject).getProcessInstanceId());
event.setProcessDefinitionId(((DelegateExecution) persistendObject).getProcessDefinitionId());
} else if (persistendObject instanceof IdentityLinkEntity) {
IdentityLinkEntity idLink = (IdentityLinkEntity) persistendObject;
if (idLink.getProcessDefinitionId() != null) {
event.setProcessDefinitionId(idLink.getProcessDefId());
} else if (idLink.getProcessInstance() != null) {
event.setProcessDefinitionId(idLink.getProcessInstance().getProcessDefinitionId());
event.setProcessInstanceId(idLink.getProcessInstanceId());
event.setExecutionId(idLink.getProcessInstanceId());
} else if (idLink.getTask() != null) {
event.setProcessDefinitionId(idLink.getTask().getProcessDefinitionId());
event.setProcessInstanceId(idLink.getTask().getProcessInstanceId());
event.setExecutionId(idLink.getTask().getExecutionId());
}
} else if (persistendObject instanceof Task) {
event.setProcessInstanceId(((Task) persistendObject).getProcessInstanceId());
event.setExecutionId(((Task) persistendObject).getExecutionId());
event.setProcessDefinitionId(((Task) persistendObject).getProcessDefinitionId());
} else if (persistendObject instanceof ProcessDefinition) {
event.setProcessDefinitionId(((ProcessDefinition) persistendObject).getId());
}
}
}
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class ActivityEventsTest method testActivityTimeOutEventInSubProcess.
@Deployment(resources = "org/activiti/engine/test/bpmn/event/timer/BoundaryTimerEventTest.testTimerOnNestingOfSubprocesses.bpmn20.xml")
public void testActivityTimeOutEventInSubProcess() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnNestedSubprocesses");
Job theJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(theJob);
// Force timer to fire
Calendar timeToFire = Calendar.getInstance();
timeToFire.add(Calendar.HOUR, 2);
timeToFire.add(Calendar.SECOND, 5);
processEngineConfiguration.getClock().setCurrentTime(timeToFire.getTime());
waitForJobExecutorToProcessAllJobs(2000, 200);
// Check timeout-events have been dispatched
assertEquals(3, listener.getEventsReceived().size());
List<String> eventIdList = new ArrayList<String>();
for (ActivitiEvent event : listener.getEventsReceived()) {
assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, event.getType());
assertTrue("TIMER is the cause of the cancellation", ((ActivitiActivityCancelledEvent) event).getCause() instanceof TimerEntity);
eventIdList.add(((ActivitiActivityEventImpl) event).getActivityId());
}
assertTrue(eventIdList.indexOf("innerTask1") >= 0);
assertTrue(eventIdList.indexOf("innerTask2") >= 0);
assertTrue(eventIdList.indexOf("innerFork") >= 0);
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class ActivityEventsTest method testActivityTimeOutEvent.
@Deployment(resources = "org/activiti/engine/test/api/event/JobEventsTest.testJobEntityEvents.bpmn20.xml")
public void testActivityTimeOutEvent() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testJobEvents");
Job theJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(theJob);
// Force timer to fire
Calendar tomorrow = Calendar.getInstance();
tomorrow.add(Calendar.DAY_OF_YEAR, 1);
processEngineConfiguration.getClock().setCurrentTime(tomorrow.getTime());
waitForJobExecutorToProcessAllJobs(2000, 100);
// Check timeout has been dispatched
assertEquals(1, listener.getEventsReceived().size());
ActivitiEvent activitiEvent = listener.getEventsReceived().get(0);
assertEquals("ACTIVITY_CANCELLED event expected", ActivitiEventType.ACTIVITY_CANCELLED, activitiEvent.getType());
ActivitiActivityCancelledEvent cancelledEvent = (ActivitiActivityCancelledEvent) activitiEvent;
assertTrue("TIMER is the cause of the cancellation", cancelledEvent.getCause() instanceof TimerEntity);
}
use of org.activiti.engine.runtime.Job in project Activiti by Activiti.
the class ActivityEventsTest method testActivityTimeOutEventInCallActivity.
@Deployment
public void testActivityTimeOutEventInCallActivity() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnCallActivity");
Job theJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(theJob);
// Force timer to fire
Calendar timeToFire = Calendar.getInstance();
timeToFire.add(Calendar.HOUR, 2);
timeToFire.add(Calendar.SECOND, 5);
processEngineConfiguration.getClock().setCurrentTime(timeToFire.getTime());
waitForJobExecutorToProcessAllJobs(20000, 500);
// Check timeout-events have been dispatched
assertEquals(4, listener.getEventsReceived().size());
List<String> eventIdList = new ArrayList<String>();
for (ActivitiEvent event : listener.getEventsReceived()) {
assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, event.getType());
assertTrue("TIMER is the cause of the cancellation", ((ActivitiActivityCancelledEvent) event).getCause() instanceof TimerEntity);
eventIdList.add(((ActivitiActivityEventImpl) event).getActivityId());
}
assertTrue(eventIdList.indexOf("innerTask1") >= 0);
assertTrue(eventIdList.indexOf("innerTask2") >= 0);
assertTrue(eventIdList.indexOf("innerFork") >= 0);
assertTrue(eventIdList.indexOf("callActivity") >= 0);
}
Aggregations