use of org.drools.core.time.TimerService in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testInterediateTimerWithHTBeforeWithGlobalTestServiceRollback.
@Test(timeout = 20000)
public void testInterediateTimerWithHTBeforeWithGlobalTestServiceRollback() throws Exception {
// prepare listener to assert results
Properties properties = new Properties();
properties.setProperty("mary", "HR");
properties.setProperty("john", "HR");
UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(properties);
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT2.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).userGroupCallback(userGroupCallback).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
long ksessionId = ksession.getIdentifier();
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "R3/PT1S");
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params);
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
// get tasks
List<Status> statuses = new ArrayList<Status>();
statuses.add(Status.Reserved);
List<TaskSummary> tasks = runtime.getTaskService().getTasksAssignedAsPotentialOwnerByStatus("john", statuses, "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
runtime.getTaskService().start(task.getId(), "john");
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
runtime.getTaskService().complete(task.getId(), "john", null);
} finally {
ut.rollback();
}
processInstance = ksession.getProcessInstance(processInstance.getId());
Collection<NodeInstance> activeNodes = ((WorkflowProcessInstance) processInstance).getNodeInstances();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertTrue(activeNodes.iterator().next() instanceof HumanTaskNodeInstance);
TimerService timerService = TimerServiceRegistry.getInstance().get(manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
Collection<TimerJobInstance> timerInstances = timerService.getTimerJobInstances(ksessionId);
assertNotNull(timerInstances);
assertEquals(0, timerInstances.size());
// clean up
ksession.abortProcessInstance(processInstance.getId());
manager.disposeRuntimeEngine(runtime);
}
use of org.drools.core.time.TimerService in project jbpm by kiegroup.
the class AbstractRuntimeManager method close.
public void close(boolean removeJobs) {
cacheManager.dispose();
environment.close();
registry.remove(identifier);
TimerService timerService = TimerServiceRegistry.getInstance().get(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
if (timerService != null) {
try {
if (removeJobs && timerService instanceof GlobalTimerService) {
((GlobalTimerService) timerService).destroy();
}
timerService.shutdown();
GlobalSchedulerService schedulerService = ((SchedulerProvider) environment).getSchedulerService();
if (schedulerService != null) {
schedulerService.shutdown();
}
} finally {
TimerServiceRegistry.getInstance().remove(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
}
}
this.closed = true;
}
Aggregations