use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class TimerMigrationManagerTest method testMigrateBoundaryTimerProcessInstance.
@Test(timeout = 10000)
public void testMigrateBoundaryTimerProcessInstance() throws Exception {
NodeLeftCountDownProcessEventListener countdownListener = new NodeLeftCountDownProcessEventListener("GoodbyeV2", 1);
createRuntimeManagers("migration/v1/BPMN2-TimerBoundary-v1.bpmn2", "migration/v2/BPMN2-TimerBoundary-v2.bpmn2", countdownListener);
assertNotNull(managerV1);
assertNotNull(managerV2);
RuntimeEngine runtime = managerV1.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance pi1 = ksession.startProcess(BOUNDARY_TIMER_ID_V1);
assertNotNull(pi1);
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
JPAAuditLogService auditService = new JPAAuditLogService(emf);
ProcessInstanceLog log = auditService.findProcessInstance(pi1.getId());
assertNotNull(log);
assertEquals(BOUNDARY_TIMER_ID_V1, log.getProcessId());
assertEquals(DEPLOYMENT_ID_V1, log.getExternalId());
managerV1.disposeRuntimeEngine(runtime);
MigrationSpec migrationSpec = new MigrationSpec(DEPLOYMENT_ID_V1, pi1.getId(), DEPLOYMENT_ID_V2, BOUNDARY_TIMER_ID_V2);
MigrationManager migrationManager = new MigrationManager(migrationSpec);
MigrationReport report = migrationManager.migrate();
assertNotNull(report);
assertTrue(report.isSuccessful());
log = auditService.findProcessInstance(pi1.getId());
assertNotNull(log);
assertEquals(BOUNDARY_TIMER_ID_V2, log.getProcessId());
assertEquals(DEPLOYMENT_ID_V2, log.getExternalId());
assertEquals(ProcessInstance.STATE_ACTIVE, log.getStatus().intValue());
// wait till timer fires
countdownListener.waitTillCompleted();
log = auditService.findProcessInstance(pi1.getId());
auditService.dispose();
assertNotNull(log);
assertEquals(BOUNDARY_TIMER_ID_V2, log.getProcessId());
assertEquals(DEPLOYMENT_ID_V2, log.getExternalId());
assertEquals(ProcessInstance.STATE_COMPLETED, log.getStatus().intValue());
}
use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class ConcurrentOperationsTest method testExecuteProcessWithAsyncHandler.
@Test(timeout = 10000)
public void testExecuteProcessWithAsyncHandler() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Log", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addEnvironmentEntry("TRANSACTION_LOCK_ENABLED", true).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("Log", new AsyncWorkItemHandler(((RuntimeEngineImpl) runtime).getManager()));
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).addAsset(ResourceFactory.newClassPathResource("BPMN2-CustomTask.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long sessionId = ksession.getIdentifier();
assertTrue(sessionId == 1);
runtime = manager.getRuntimeEngine(EmptyContext.get());
ksession = runtime.getKieSession();
assertEquals(sessionId, ksession.getIdentifier());
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
ut.begin();
ProcessInstance processInstance = ksession.startProcess("customtask");
logger.debug("Started process, committing...");
ut.commit();
countDownListener.waitTillCompleted();
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
// dispose session that should not have affect on the session at all
manager.disposeRuntimeEngine(runtime);
// close manager which will close session maintained by the manager
manager.close();
}
use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class AsyncTaskCallbackTest method testTaskCallback.
@Test(timeout = 30000)
public void testTaskCallback() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Continue", 1);
addProcessEventListener(countDownListener);
KieSession ksession = createKSession(ASYNC_EXECUTOR_CALLBACK, ASYNC_DATA_EXECUTOR);
WorkItemManager wim = ksession.getWorkItemManager();
wim.registerWorkItemHandler("async", new AsyncWorkItemHandler(getExecutorService()));
Map<String, Object> pm = new HashMap<String, Object>();
pm.put("_command", CALLBACK_COMMAND);
ProcessInstance pi = ksession.startProcess(ASYNC_EXECUTOR_CALLBACK_ID, pm);
// Wait for the job to be picked up and processed. The job will send
// the 'Continue' signal on OK or Fail. We expect OK.
countDownListener.waitTillCompleted();
ProcessInstance processInstance = ksession.getProcessInstance(pi.getId());
assertNull(processInstance);
// Make sure the user registered callback was executed (a.k.a the "continue" signal was received by the process)
assertNodeTriggered(pi.getId(), "Process async", "Continue");
assertProcessInstanceCompleted(pi.getId());
// Make sure the job was processed by the job executor (a.k.a the _user property was set)
List<VariableInstanceLog> varLogList = auditLogService.findVariableInstances(pi.getId(), "_user");
assertEquals(1, varLogList.size());
VariableInstanceLog userVarLog = varLogList.get(0);
assertEquals("[Name=john after command execution, age=25]", userVarLog.getValue());
}
use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class AsyncThreadContinuationTest method testRepeatIntermediateTimerAfterException.
@Test(timeout = 10000)
public void testRepeatIntermediateTimerAfterException() {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("MySignal", 1, true);
KieSession ksession = createKSession(BPMN_IT);
ksession.addEventListener(countDownListener);
ProcessInstance pi = ksession.startProcess(PROCESS_IT);
long pid = pi.getId();
countDownListener.waitTillCompleted();
pi = ksession.getProcessInstance(pid);
Assertions.assertThat(pi).isNotNull();
ksession.abortProcessInstance(pid);
pi = ksession.getProcessInstance(pid);
Assertions.assertThat(pi).isNull();
ProcessInstanceLog log = getLogService().findProcessInstance(pid);
Assertions.assertThat(log.getStatus()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class CountDownListenerFactory method get.
public static NodeLeftCountDownProcessEventListener get(String id, String nodeName, int threads) {
if (listeners.containsKey(id)) {
return listeners.get(id);
}
NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener(nodeName, threads);
listeners.put(id, listener);
return listener;
}
Aggregations