use of org.drools.core.time.TimerService in project jbpm by kiegroup.
the class GlobalQuartzDBTimerServiceTest method testContinueGlobalTestService.
/**
* Test that illustrates that jobs are persisted and survives server restart
* and as soon as GlobalTimerService is active jobs are fired
* NOTE: this test is disabled by default as it requires real db (not in memory)
* and test to be executed separately each with new jvm process
*/
@Test
@Ignore
public void testContinueGlobalTestService() throws Exception {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle2.bpmn2"), ResourceType.BPMN2).addConfiguration("drools.timerService", "org.jbpm.process.core.timer.impl.RegisteredTimerServiceDelegate").get();
RuntimeManager manger = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
// build GlobalTimerService instance
TimerService globalTs = new GlobalTimerService(manger, globalScheduler);
// and register it in the registry under 'default' key
TimerServiceRegistry.getInstance().registerTimerService("default", globalTs);
// prepare listener to assert results
final List<Long> timerExporations = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("timer")) {
timerExporations.add(event.getProcessInstance().getId());
}
}
};
Thread.sleep(5000);
}
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