use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class AsyncThrowSignalTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
executorService = ExecutorServiceFactory.newExecutorService(getEmf());
executorService.setInterval(1);
executorService.init();
addEnvironmentEntry("ExecutorService", executorService);
addWorkItemHandler("SyncError", new FirstErrorWorkItemHandler());
addProcessEventListener(new DefaultProcessEventListener() {
@Override
public void afterProcessCompleted(ProcessCompletedEvent event) {
synchronized (LOCK) {
LOCK.notifyAll();
}
}
});
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class GlobalQuartzDBTimerServiceTest method testContinueTimerWithMisfire.
@Test(timeout = 25000)
public void testContinueTimerWithMisfire() throws Exception {
// RHBPMS-4729
System.setProperty("org.quartz.properties", "quartz-db-short-misfire.properties");
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 2);
// prepare listener to assert results
final List<Long> timerExporations = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
timerExporations.add(event.getProcessInstance().getId());
}
};
// No special configuration for TimerService in order to test RuntimeManager default
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/TimerStart2.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
countDownListener.waitTillCompleted();
manager.disposeRuntimeEngine(runtime);
manager.close();
System.out.println("==== manager.close() ====");
countDownListener.reset(3);
// Simulate interval between shutdown and start so the Trigger is older than (now - misfireThreshold)
Thread.sleep(5000);
// ---- restart ----
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/TimerStart2.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
manager = getManager(environment, true);
countDownListener.waitTillCompleted(4000);
assertEquals(5, timerExporations.size());
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class GlobalQuartzDBTimerServiceTest method testAbortGlobalTestService.
/**
* Test that illustrates that jobs are persisted and survives server restart
* and as soon as GlobalTimerService is active jobs are fired and it loads and aborts the
* process instance to illustrate jobs are properly removed when isntance is aborted
* 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 testAbortGlobalTestService() throws Exception {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle3.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());
}
}
};
long id = -1;
Thread.sleep(5000);
RuntimeEngine runtime = manger.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
ksession.addEventListener(listener);
ksession.abortProcessInstance(id);
ProcessInstance processInstance = ksession.getProcessInstance(id);
assertNull(processInstance);
// let's wait to ensure no more timers are expired and triggered
Thread.sleep(3000);
ksession.dispose();
}
use of org.kie.api.event.process.DefaultProcessEventListener 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.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testTimerFailureAndRetrigger.
@Test(timeout = 20000)
public void testTimerFailureAndRetrigger() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Timer_1m", 3);
final List<Long> timerExporations = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
if (event.getNodeInstance().getNodeName().equals("Timer_1m")) {
timerExporations.add(event.getNodeInstance().getId());
}
}
};
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/helloretrigger.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
manager = getManager(environment, false);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
Map<String, Object> params = new HashMap<>();
ProcessInstance pi = ksession.startProcess("rescheduletimer.helloretrigger", params);
assertEquals("Process instance should be active", ProcessInstance.STATE_ACTIVE, pi.getState());
manager.disposeRuntimeEngine(runtime);
final long processInstanceId = pi.getId();
// let the timer (every 2 sec) fire three times as third will fail on gateway
countDownListener.waitTillCompleted(8000);
assertEquals("There should be only 3 nodes as there third is failing", 3, timerExporations.size());
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
ksession = runtime.getKieSession();
ksession.execute(new ExecutableCommand<Void>() {
@Override
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
ProcessInstance pi = (ProcessInstance) ksession.getProcessInstance(processInstanceId);
((WorkflowProcessInstance) pi).setVariable("fixed", true);
return null;
}
});
manager.disposeRuntimeEngine(runtime);
countDownListener.reset(1);
countDownListener.waitTillCompleted(5000);
assertEquals("There should be 3 expirations as the failing one should finally proceed", 3, timerExporations.size());
try {
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
ksession = runtime.getKieSession();
pi = ksession.getProcessInstance(processInstanceId);
assertNull(pi);
} catch (SessionNotFoundException e) {
// expected for PerProcessInstanceManagers since process instance is completed
}
((AbstractRuntimeManager) manager).close(true);
}
Aggregations