use of org.drools.persistence.jpa.OptimisticLockRetryInterceptor in project jbpm by kiegroup.
the class SingletonRuntimeManagerTest method testInterceptorAfterRollback.
@Test
public void testInterceptorAfterRollback() throws Exception {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskWithRollback.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
ProcessInstance processInstance = ksession.startProcess("UserTaskWithRollback");
ExecutableRunner commandService = ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
assertEquals(PersistableRunner.class, commandService.getClass());
ChainableRunner internalCommandService = ((PersistableRunner) commandService).getChainableRunner();
assertEquals(ExecutionErrorHandlerInterceptor.class, internalCommandService.getClass());
internalCommandService = (ChainableRunner) ((ExecutionErrorHandlerInterceptor) internalCommandService).getNext();
assertEquals(TransactionLockInterceptor.class, internalCommandService.getClass());
TaskService taskService = runtime.getTaskService();
List<Long> taskIds = taskService.getTasksByProcessInstanceId(processInstance.getId());
taskService.start(taskIds.get(0), "john");
HashMap<String, Object> result = new HashMap<String, Object>();
result.put("output1", "rollback");
try {
// rollback transaction
taskService.complete(taskIds.get(0), "john", result);
} catch (WorkflowRuntimeException e) {
// ignore
}
result = new HashMap<String, Object>();
result.put("output1", "ok");
// this time, execute normally
taskService.complete(taskIds.get(0), "john", result);
internalCommandService = ((PersistableRunner) commandService).getChainableRunner();
assertEquals(ExecutionErrorHandlerInterceptor.class, internalCommandService.getClass());
internalCommandService = (ChainableRunner) ((ExecutionErrorHandlerInterceptor) internalCommandService).getNext();
assertEquals(TransactionLockInterceptor.class, internalCommandService.getClass());
internalCommandService = (ChainableRunner) ((TransactionLockInterceptor) internalCommandService).getNext();
assertEquals(OptimisticLockRetryInterceptor.class, internalCommandService.getClass());
internalCommandService = (ChainableRunner) ((OptimisticLockRetryInterceptor) internalCommandService).getNext();
assertEquals("org.drools.persistence.PersistableRunner$TransactionInterceptor", internalCommandService.getClass().getName());
// close manager which will close session maintained by the manager
manager.close();
}
use of org.drools.persistence.jpa.OptimisticLockRetryInterceptor in project jbpm by kiegroup.
the class JPASessionFactory method addInterceptors.
protected void addInterceptors(KieSession ksession) {
PersistableRunner runner = (PersistableRunner) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
runner.addInterceptor(new OptimisticLockRetryInterceptor());
// even though it's added always TransactionLockInterceptor is by default disabled so won't do anything
runner.addInterceptor(new TransactionLockInterceptor(ksession.getEnvironment()));
runner.addInterceptor(new ExecutionErrorHandlerInterceptor(ksession.getEnvironment()));
}
Aggregations