use of org.jbpm.services.task.identity.JBossUserGroupCallbackImpl in project jbpm by kiegroup.
the class ConcurrentGlobalTimerServiceTest method setup.
@Before
public void setup() {
Properties properties = new Properties();
properties.setProperty("mary", "HR");
properties.setProperty("john", "HR");
userGroupCallback = new JBossUserGroupCallbackImpl(properties);
globalScheduler = new ThreadPoolSchedulerService(1);
emf = Persistence.createEntityManagerFactory("org.jbpm.test.persistence");
}
use of org.jbpm.services.task.identity.JBossUserGroupCallbackImpl in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testInterediateTimerWithGlobalTestServiceSimulateCMT.
@Test(timeout = 20000)
public void testInterediateTimerWithGlobalTestServiceSimulateCMT() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
// 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());
}
}
};
Properties properties = new Properties();
properties.setProperty("mary", "HR");
properties.setProperty("john", "HR");
UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(properties);
EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate("org.jbpm.test.persistence");
TransactionManager tm = new ContainerManagedTransactionManager();
Environment env = EnvironmentFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.TRANSACTION_MANAGER, tm);
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT2.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry(EnvironmentName.TRANSACTION_MANAGER, tm).addEnvironmentEntry(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, new JpaProcessPersistenceContextManager(env)).addEnvironmentEntry(EnvironmentName.TASK_PERSISTENCE_CONTEXT_MANAGER, new JPATaskPersistenceContextManager(env)).schedulerService(globalScheduler).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).userGroupCallback(userGroupCallback).get();
RuntimeEngine runtime;
KieSession ksession;
ProcessInstance processInstance;
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
manager = getManager(environment, true);
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
ksession = runtime.getKieSession();
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "R3/PT1S");
processInstance = ksession.startProcess("IntermediateCatchEvent", params);
ut.commit();
} catch (Exception ex) {
ut.rollback();
throw ex;
}
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtime.getKieSession();
// 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());
for (TaskSummary task : tasks) {
runtime.getTaskService().start(task.getId(), "john");
runtime.getTaskService().complete(task.getId(), "john", null);
}
ut.commit();
} catch (Exception ex) {
ut.rollback();
throw ex;
}
// now wait for 1 second for first timer to trigger
countDownListener.waitTillCompleted();
countDownListener.reset(1);
ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
try {
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtime.getKieSession();
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
} catch (SessionNotFoundException e) {
// expected for PerProcessInstanceManagers since process instance is completed
}
ut.commit();
} catch (Exception ex) {
ut.rollback();
throw ex;
}
// let's wait to ensure no more timers are expired and triggered
countDownListener.waitTillCompleted(3000);
assertEquals(3, timerExporations.size());
}
use of org.jbpm.services.task.identity.JBossUserGroupCallbackImpl in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testInterediateTimerWithHTBeforeWithGlobalTestService.
@Test(timeout = 20000)
public void testInterediateTimerWithHTBeforeWithGlobalTestService() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
// 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());
}
}
};
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).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).userGroupCallback(userGroupCallback).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
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());
for (TaskSummary task : tasks) {
runtime.getTaskService().start(task.getId(), "john");
runtime.getTaskService().complete(task.getId(), "john", null);
}
// dispose session to force session to be reloaded on timer expiration
manager.disposeRuntimeEngine(runtime);
// now wait for 1 second for first timer to trigger
countDownListener.waitTillCompleted();
countDownListener.reset(1);
try {
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtime.getKieSession();
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
} catch (SessionNotFoundException e) {
// expected for PerProcessInstanceManagers since process instance is completed
}
// let's wait to ensure no more timers are expired and triggered
countDownListener.waitTillCompleted(3000);
manager.disposeRuntimeEngine(runtime);
assertEquals(3, timerExporations.size());
}
use of org.jbpm.services.task.identity.JBossUserGroupCallbackImpl in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testInterediateBoundaryTimerWithGlobalTestServiceRollback.
@Test(timeout = 20000)
public void testInterediateBoundaryTimerWithGlobalTestServiceRollback() throws Exception {
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/HumanTaskWithBoundaryTimer.bpmn"), 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();
ProcessInstance processInstance;
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
Map<String, Object> params = new HashMap<String, Object>();
params.put("test", "john");
processInstance = ksession.startProcess("PROCESS_1", params);
} finally {
ut.rollback();
}
manager.disposeRuntimeEngine(runtime);
try {
// two types of checks as different managers will treat it differently
// per process instance will fail on getting runtime
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
// where singleton and per request will return runtime but there should not be process instance
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
} catch (SessionNotFoundException e) {
}
TimerService timerService = TimerServiceRegistry.getInstance().get(manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
Collection<TimerJobInstance> timerInstances = timerService.getTimerJobInstances(ksessionId);
assertNotNull(timerInstances);
assertEquals(0, timerInstances.size());
if (runtime != null) {
manager.disposeRuntimeEngine(runtime);
}
}
use of org.jbpm.services.task.identity.JBossUserGroupCallbackImpl in project jbpm by kiegroup.
the class GlobalTimerServiceVolumeTest method setup.
@Before
public void setup() {
Properties properties = new Properties();
properties.setProperty("mary", "HR");
properties.setProperty("john", "HR");
userGroupCallback = new JBossUserGroupCallbackImpl(properties);
System.setProperty("org.quartz.properties", "quartz-db.properties");
testCreateQuartzSchema();
globalScheduler = new QuartzSchedulerService();
emf = Persistence.createEntityManagerFactory("org.jbpm.test.persistence");
countDownListener = new NodeLeftCountDownProcessEventListener("timer", numberOfProcesses);
// 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());
}
}
};
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT3.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
if ("processinstance".equals(strategy)) {
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment, "first");
} else if ("request".equals(strategy)) {
manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment, "first");
} else if ("case".equals(strategy)) {
manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment, "first");
} else {
throw new RuntimeException("Unknow type of runtime strategy");
}
}
Aggregations